Skip to content

Commit

Permalink
Spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PencilAmazing committed Dec 4, 2024
1 parent 5884973 commit 2c6ed1d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
58 changes: 58 additions & 0 deletions spec/controllers/staff/makerstore_links_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "rails_helper"

RSpec.describe Staff::MakerstoreLinksController, type: :controller do
before(:each) { session[:user_id] = (create :user, :staff).id }

describe "GET /index" do
context "logged in as staff" do
it "should return http success" do
get :index
expect(response).to have_http_status(:success)
end
end

context "not logged in" do
it "should return http redirect" do
session[:user_id] = nil
get :index
expect(response).to_not have_http_status(:success)
end
end
end

describe "POST /create" do
context "create a new link" do
it "should create link" do
makerstore_link_params =
FactoryBot.attributes_for(:makerstore_link, :with_image)
expect {
post :create, params: { makerstore_link: makerstore_link_params }
}.to change(MakerstoreLink, :count).by 1
end

it "should reject link without image" do
makerstore_link_params = FactoryBot.attributes_for(:makerstore_link)
expect {
post :create, params: { makerstore_link: makerstore_link_params }
}.to change(MakerstoreLink, :count).by 0
expect(flash[:alert]&.empty?).to be_falsy
end
end
end

describe "PATCH #update" do
context "hiding and showing a link" do
it "should hide a link" do
link = create(:makerstore_link, :with_image)
put :update, params: { id: link.id, makerstore_link: { shown: false } }
expect(MakerstoreLink.find(link.id).shown).to be false
end

it "should show a link" do
link = create(:makerstore_link, :with_image, :hidden)
put :update, params: { id: link.id, makerstore_link: { shown: true } }
expect(MakerstoreLink.find(link.id).shown).to be true
end
end
end
end
15 changes: 15 additions & 0 deletions spec/factories/makerstore_links.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FactoryBot.define do
factory :makerstore_link do
title { Faker::Alphanumeric.alphanumeric(number: 10) }
url { Faker::Internet.url }
shown { true }
order { 0 }
trait :with_image do
image { FilesTestHelper.png }
end

trait :hidden do
shown { false }
end
end
end

0 comments on commit 2c6ed1d

Please sign in to comment.