-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5884973
commit 2c6ed1d
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
spec/controllers/staff/makerstore_links_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |