repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/manifestation_checkout_stats.rb | spec/factories/manifestation_checkout_stats.rb | FactoryBot.define do
factory :manifestation_checkout_stat do
start_date { 1.week.ago }
end_date { 1.day.ago }
association :user, factory: :librarian
end
end
# == Schema Information
#
# Table name: manifestation_checkout_stats
#
# id :bigint not null, primary key
# completed_at :datetime
# end_date :datetime
# note :text
# start_date :datetime
# started_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_manifestation_checkout_stats_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/bookstores.rb | spec/factories/bookstores.rb | FactoryBot.define do
factory :bookstore do |f|
f.sequence(:name) {|n| "bookstore_#{n}"}
end
end
# == Schema Information
#
# Table name: bookstores
#
# id :bigint not null, primary key
# name :text not null
# zip_code :string
# address :text
# note :text
# telephone_number :string
# fax_number :string
# url :string
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/use_restrictions.rb | spec/factories/use_restrictions.rb | FactoryBot.define do
factory :use_restriction do |f|
f.sequence(:name) {|n| "use_restriction_#{n}"}
end
end
# == Schema Information
#
# Table name: use_restrictions
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_use_restrictions_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/manifestation_reserve_stats.rb | spec/factories/manifestation_reserve_stats.rb | FactoryBot.define do
factory :manifestation_reserve_stat do
start_date { 1.week.ago }
end_date { 1.day.ago }
association :user, factory: :librarian
end
end
# == Schema Information
#
# Table name: manifestation_reserve_stats
#
# id :bigint not null, primary key
# completed_at :datetime
# end_date :datetime
# note :text
# start_date :datetime
# started_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_manifestation_reserve_stats_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/item_has_use_restrictions.rb | spec/factories/item_has_use_restrictions.rb | FactoryBot.define do
factory :item_has_use_restriction do |f|
f.item_id {FactoryBot.create(:item).id}
f.use_restriction_id {FactoryBot.create(:use_restriction).id}
end
end
# == Schema Information
#
# Table name: item_has_use_restrictions
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# item_id :bigint not null
# use_restriction_id :bigint not null
#
# Indexes
#
# index_item_has_use_restrictions_on_item_and_use_restriction (item_id,use_restriction_id) UNIQUE
# index_item_has_use_restrictions_on_use_restriction_id (use_restriction_id)
#
# Foreign Keys
#
# fk_rails_... (item_id => items.id)
# fk_rails_... (use_restriction_id => use_restrictions.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/subjects.rb | spec/factories/subjects.rb | FactoryBot.define do
factory :subject do |f|
f.sequence(:term) {|n| "subject_#{n}"}
f.subject_heading_type_id {FactoryBot.create(:subject_heading_type).id}
f.subject_type_id {FactoryBot.create(:subject_type).id}
end
end
# == Schema Information
#
# Table name: subjects
#
# id :bigint not null, primary key
# lock_version :integer default(0), not null
# note :text
# scope_note :text
# term :string
# term_transcription :text
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# manifestation_id :bigint
# parent_id :bigint
# required_role_id :bigint default(1), not null
# subject_heading_type_id :bigint
# subject_type_id :bigint not null
# use_term_id :bigint
#
# Indexes
#
# index_subjects_on_manifestation_id (manifestation_id)
# index_subjects_on_parent_id (parent_id)
# index_subjects_on_required_role_id (required_role_id)
# index_subjects_on_subject_type_id (subject_type_id)
# index_subjects_on_term (term)
# index_subjects_on_use_term_id (use_term_id)
#
# Foreign Keys
#
# fk_rails_... (required_role_id => roles.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/subscriptions.rb | spec/factories/subscriptions.rb | FactoryBot.define do
factory :subscription do |f|
f.sequence(:title) {|n| "subscription_#{n}"}
f.user_id {FactoryBot.create(:user).id}
end
end
# == Schema Information
#
# Table name: subscriptions
#
# id :bigint not null, primary key
# note :text
# subscribes_count :integer default(0), not null
# title :text not null
# created_at :datetime not null
# updated_at :datetime not null
# order_list_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_subscriptions_on_order_list_id (order_list_id)
# index_subscriptions_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/realizes.rb | spec/factories/realizes.rb | FactoryBot.define do
factory :realize do |f|
f.expression_id {FactoryBot.create(:manifestation).id}
f.agent_id {FactoryBot.create(:agent).id}
end
end
# == Schema Information
#
# Table name: realizes
#
# id :bigint not null, primary key
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :bigint not null
# expression_id :bigint not null
# realize_type_id :bigint
#
# Indexes
#
# index_realizes_on_agent_id (agent_id)
# index_realizes_on_expression_id_and_agent_id (expression_id,agent_id) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/owns.rb | spec/factories/owns.rb | FactoryBot.define do
factory :own do |f|
f.item_id {FactoryBot.create(:item).id}
f.agent_id {FactoryBot.create(:agent).id}
end
end
# == Schema Information
#
# Table name: owns
#
# id :bigint not null, primary key
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :bigint not null
# item_id :bigint not null
#
# Indexes
#
# index_owns_on_agent_id (agent_id)
# index_owns_on_item_id_and_agent_id (item_id,agent_id) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/shelves.rb | spec/factories/shelves.rb | FactoryBot.define do
factory :shelf do |f|
f.sequence(:name) {|n| "shelf_#{n}"}
f.library_id {FactoryBot.create(:library).id}
end
end
# == Schema Information
#
# Table name: shelves
#
# id :bigint not null, primary key
# closed :boolean default(FALSE), not null
# display_name :text
# items_count :integer default(0), not null
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# library_id :bigint not null
#
# Indexes
#
# index_shelves_on_library_id (library_id)
# index_shelves_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/user_reserve_stats.rb | spec/factories/user_reserve_stats.rb | FactoryBot.define do
factory :user_reserve_stat do
start_date { 1.week.ago }
end_date { 1.day.ago }
association :user, factory: :librarian
end
end
# == Schema Information
#
# Table name: user_reserve_stats
#
# id :bigint not null, primary key
# completed_at :datetime
# end_date :datetime
# note :text
# start_date :datetime
# started_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_user_reserve_stats_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/agent_relationships.rb | spec/factories/agent_relationships.rb | FactoryBot.define do
factory :agent_relationship do |f|
f.parent_id {FactoryBot.create(:agent).id}
f.child_id {FactoryBot.create(:agent).id}
f.association :agent_relationship_type
end
end
# == Schema Information
#
# Table name: agent_relationships
#
# id :bigint not null, primary key
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# agent_relationship_type_id :bigint
# child_id :bigint
# parent_id :bigint
#
# Indexes
#
# index_agent_relationships_on_child_id (child_id)
# index_agent_relationships_on_parent_id (parent_id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/form_of_works.rb | spec/factories/form_of_works.rb | FactoryBot.define do
factory :form_of_work do |f|
f.sequence(:name) {|n| "form_of_work_#{n}"}
end
end
# == Schema Information
#
# Table name: form_of_works
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_form_of_works_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/search_engines.rb | spec/factories/search_engines.rb | FactoryBot.define do
factory :search_engine do |f|
f.sequence(:name) {|n| "search_engine_#{n}"}
f.sequence(:url) {|n| "http://search-engine-#{n}.example.jp"}
f.sequence(:base_url) {|n| "http://search-engine-#{n}.example.jp"}
f.query_param { 'q' }
f.http_method { 'get' }
end
end
# == Schema Information
#
# Table name: search_engines
#
# id :bigint not null, primary key
# name :string not null
# display_name :text
# url :string not null
# base_url :text not null
# http_method :text not null
# query_param :text not null
# additional_param :text
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/creates.rb | spec/factories/creates.rb | FactoryBot.define do
factory :create do
work_id {FactoryBot.create(:manifestation).id}
agent_id {FactoryBot.create(:agent).id}
association :create_type
end
end
# == Schema Information
#
# Table name: creates
#
# id :bigint not null, primary key
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :bigint not null
# create_type_id :bigint
# work_id :bigint not null
#
# Indexes
#
# index_creates_on_agent_id (agent_id)
# index_creates_on_work_id_and_agent_id (work_id,agent_id) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/medium_of_performances.rb | spec/factories/medium_of_performances.rb | FactoryBot.define do
factory :medium_of_performance do |f|
f.sequence(:name) {|n| "medium_of_performance_#{n}"}
end
end
# == Schema Information
#
# Table name: medium_of_performances
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_medium_of_performances_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/subscribes.rb | spec/factories/subscribes.rb | FactoryBot.define do
factory :subscribe do |f|
f.subscription_id {FactoryBot.create(:subscription).id}
f.work_id {FactoryBot.create(:manifestation).id}
f.start_at { 1.year.ago }
f.end_at { 1.year.from_now }
end
end
# == Schema Information
#
# Table name: subscribes
#
# id :bigint not null, primary key
# end_at :datetime not null
# start_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# subscription_id :bigint not null
# work_id :bigint not null
#
# Indexes
#
# index_subscribes_on_subscription_id (subscription_id)
# index_subscribes_on_work_id (work_id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/request_status_types.rb | spec/factories/request_status_types.rb | FactoryBot.define do
factory :request_status_type do |f|
f.sequence(:name) {|n| "request_status_type_#{n}"}
end
end
# == Schema Information
#
# Table name: request_status_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_request_status_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/tags.rb | spec/factories/tags.rb | FactoryBot.define do
factory :tag do |f|
f.sequence(:name) {|n| "tag_#{n}"}
end
end
# == Schema Information
#
# Table name: tags
#
# id :bigint not null, primary key
# name :string not null
# taggings_count :integer default(0)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_tags_on_name (name) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/manifestation_relationship_types.rb | spec/factories/manifestation_relationship_types.rb | FactoryBot.define do
factory :manifestation_relationship_type do
sequence(:name) {|n| "manifestation_relationship_type_#{n}"}
end
end
# == Schema Information
#
# Table name: manifestation_relationship_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_manifestation_relationship_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/produce_types.rb | spec/factories/produce_types.rb | # Read about factories at http://github.com/thoughtbot/factory_bot
FactoryBot.define do
factory :produce_type do
name { "mystring" }
display_name { "MyText" }
note { "MyText" }
end
end
# == Schema Information
#
# Table name: produce_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_produce_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/factories/purchase_requests.rb | spec/factories/purchase_requests.rb | FactoryBot.define do
factory :purchase_request do |f|
f.sequence(:title) {|n| "purchase_request_#{n}"}
f.user_id {FactoryBot.create(:user).id}
end
end
# == Schema Information
#
# Table name: purchase_requests
#
# id :bigint not null, primary key
# accepted_at :datetime
# author :text
# date_of_publication :datetime
# denied_at :datetime
# isbn :string
# note :text
# price :integer
# pub_date :string
# publisher :text
# state :string
# title :text not null
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_purchase_requests_on_state (state)
# index_purchase_requests_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/request_status_types_controller_spec.rb | spec/controllers/request_status_types_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe RequestStatusTypesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:request_status_type)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:request_status_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all request_status_types as @request_status_types' do
get :index
assigns(:request_status_types).should eq(RequestStatusType.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all request_status_types as @request_status_types' do
get :index
assigns(:request_status_types).should eq(RequestStatusType.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign request_status_types as @request_status_types' do
get :index
assigns(:request_status_types).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign request_status_types as @request_status_types' do
get :index
assigns(:request_status_types).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
before(:each) do
@request_status_type = FactoryBot.create(:request_status_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested request_status_type as @request_status_type' do
get :show, params: { id: @request_status_type.id }
assigns(:request_status_type).should eq(@request_status_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested request_status_type as @request_status_type' do
get :show, params: { id: @request_status_type.id }
assigns(:request_status_type).should eq(@request_status_type)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested request_status_type as @request_status_type' do
get :show, params: { id: @request_status_type.id }
assigns(:request_status_type).should eq(@request_status_type)
end
end
describe 'When not logged in' do
it 'assigns the requested request_status_type as @request_status_type' do
get :show, params: { id: @request_status_type.id }
assigns(:request_status_type).should eq(@request_status_type)
end
end
end
describe 'GET edit' do
before(:each) do
@request_status_type = FactoryBot.create(:request_status_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested request_status_type as @request_status_type' do
get :edit, params: { id: @request_status_type.id }
assigns(:request_status_type).should eq(@request_status_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested request_status_type as @request_status_type' do
get :edit, params: { id: @request_status_type.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested request_status_type as @request_status_type' do
get :edit, params: { id: @request_status_type.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested request_status_type as @request_status_type' do
get :edit, params: { id: @request_status_type.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'PUT update' do
before(:each) do
@request_status_type = FactoryBot.create(:request_status_type)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
end
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
assigns(:request_status_type).should eq(@request_status_type)
end
it 'moves its position when specified' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs, move: 'lower' }
response.should redirect_to(request_status_types_url)
end
end
describe 'with invalid params' do
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
end
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
assigns(:request_status_type).should eq(@request_status_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
end
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
assigns(:request_status_type).should eq(@request_status_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @request_status_type.id, request_status_type: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested request_status_type as @request_status_type' do
put :update, params: { id: @request_status_type.id, request_status_type: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_relationship_types_controller_spec.rb | spec/controllers/agent_relationship_types_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe AgentRelationshipTypesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:agent_relationship_type)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:agent_relationship_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all agent_relationship_types as @agent_relationship_types' do
get :index
expect(assigns(:agent_relationship_types)).to eq(AgentRelationshipType.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all agent_relationship_types as @agent_relationship_types' do
get :index
expect(assigns(:agent_relationship_types)).to eq(AgentRelationshipType.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all agent_relationship_types as @agent_relationship_types' do
get :index
expect(assigns(:agent_relationship_types)).to eq(AgentRelationshipType.order(:position))
end
end
describe 'When not logged in' do
it 'assigns all agent_relationship_types as @agent_relationship_types' do
get :index
expect(assigns(:agent_relationship_types)).to eq(AgentRelationshipType.order(:position))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :show, params: { id: agent_relationship_type.id }
expect(assigns(:agent_relationship_type)).to eq(agent_relationship_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :show, params: { id: agent_relationship_type.id }
expect(assigns(:agent_relationship_type)).to eq(agent_relationship_type)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :show, params: { id: agent_relationship_type.id }
expect(assigns(:agent_relationship_type)).to eq(agent_relationship_type)
end
end
describe 'When not logged in' do
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :show, params: { id: agent_relationship_type.id }
expect(assigns(:agent_relationship_type)).to eq(agent_relationship_type)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
get :new
expect(assigns(:agent_relationship_type)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested agent_relationship_type as @agent_relationship_type' do
get :new
expect(assigns(:agent_relationship_type)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested agent_relationship_type as @agent_relationship_type' do
get :new
expect(assigns(:agent_relationship_type)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_relationship_type as @agent_relationship_type' do
get :new
expect(assigns(:agent_relationship_type)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :edit, params: { id: agent_relationship_type.id }
expect(assigns(:agent_relationship_type)).to eq(agent_relationship_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :edit, params: { id: agent_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :edit, params: { id: agent_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_relationship_type as @agent_relationship_type' do
agent_relationship_type = FactoryBot.create(:agent_relationship_type)
get :edit, params: { id: agent_relationship_type.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent_relationship_type: @attrs }
expect(response).to redirect_to(assigns(:agent_relationship_type))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(assigns(:agent_relationship_type)).not_to be_valid
end
it 'should be successful' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(response).to be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship_type: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(assigns(:agent_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship_type: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(assigns(:agent_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship_type: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship_type as @agent_relationship_type' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(assigns(:agent_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship_type: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@agent_relationship_type = FactoryBot.create(:agent_relationship_type)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
end
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to eq(@agent_relationship_type)
end
it 'moves its position when specified' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs, move: 'lower' }
expect(response).to redirect_to(agent_relationship_types_url)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
end
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to eq(@agent_relationship_type)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
end
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
expect(assigns(:agent_relationship_type)).to eq(@agent_relationship_type)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship_type as @agent_relationship_type' do
put :update, params: { id: @agent_relationship_type.id, agent_relationship_type: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@agent_relationship_type = FactoryBot.create(:agent_relationship_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested agent_relationship_type' do
delete :destroy, params: { id: @agent_relationship_type.id }
end
it 'redirects to the agent_relationship_types list' do
delete :destroy, params: { id: @agent_relationship_type.id }
expect(response).to redirect_to(agent_relationship_types_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested agent_relationship_type' do
delete :destroy, params: { id: @agent_relationship_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested agent_relationship_type' do
delete :destroy, params: { id: @agent_relationship_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested agent_relationship_type' do
delete :destroy, params: { id: @agent_relationship_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_relationship_type.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/libraries_controller_spec.rb | spec/controllers/libraries_controller_spec.rb | require 'rails_helper'
describe LibrariesController do
fixtures :all
describe 'GET index', solr: true do
before do
Library.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all libraries as @libraries' do
get :index
assigns(:libraries).should_not be_empty
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all libraries as @libraries' do
get :index
assigns(:libraries).should_not be_empty
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all libraries as @libraries' do
get :index
assigns(:libraries).should_not be_empty
end
end
describe 'When not logged in' do
it 'assigns all libraries as @libraries' do
get :index
assigns(:libraries).should_not be_empty
end
it 'should get index with query' do
get :index, params: { query: 'kamata' }
response.should be_successful
assigns(:libraries).include?(Library.friendly.find('kamata')).should be_truthy
end
end
end
describe 'GET show', solr: true do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested library as @library' do
get :show, params: { id: 1 }
assigns(:library).should eq(libraries(:library_00001))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested library as @library' do
get :show, params: { id: 1 }
assigns(:library).should eq(libraries(:library_00001))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested library as @library' do
get :show, params: { id: 1 }
assigns(:library).should eq(libraries(:library_00001))
end
end
describe 'When not logged in' do
it 'assigns the requested library as @library' do
get :show, params: { id: 1 }
assigns(:library).should eq(libraries(:library_00001))
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested library as @library' do
get :new
assigns(:library).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested library as @library' do
get :new
assigns(:library).should be_nil
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested library as @library' do
get :new
assigns(:library).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested library as @library' do
get :new
assigns(:library).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested library as @library' do
library = FactoryBot.create(:library)
get :edit, params: { id: library.id }
assigns(:library).should eq(library)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested library as @library' do
library = FactoryBot.create(:library)
get :edit, params: { id: library.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested library as @library' do
library = FactoryBot.create(:library)
get :edit, params: { id: library.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested library as @library' do
library = FactoryBot.create(:library)
get :edit, params: { id: library.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:library)
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created library as @library' do
post :create, params: { library: @attrs }
assigns(:library).should be_valid
end
it 'redirects to the created patron' do
post :create, params: { library: @attrs }
response.should redirect_to(assigns(:library))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved library as @library' do
post :create, params: { library: @invalid_attrs }
assigns(:library).should_not be_valid
end
it 'should be successful' do
post :create, params: { library: @invalid_attrs }
response.should be_successful
end
it 'should not create library without short_display_name' do
post :create, params: { library: { name: 'fujisawa', short_display_name: '' } }
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created library as @library' do
post :create, params: { library: @attrs }
assigns(:library).should be_nil
end
it 'should be forbidden' do
post :create, params: { library: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved library as @library' do
post :create, params: { library: @invalid_attrs }
assigns(:library).should be_nil
end
it 'should be forbidden' do
post :create, params: { library: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created library as @library' do
post :create, params: { library: @attrs }
assigns(:library).should be_nil
end
it 'should be forbidden' do
post :create, params: { library: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved library as @library' do
post :create, params: { library: @invalid_attrs }
assigns(:library).should be_nil
end
it 'should be forbidden' do
post :create, params: { library: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created library as @library' do
post :create, params: { library: @attrs }
assigns(:library).should be_nil
end
it 'should be redirected to new session url' do
post :create, params: { library: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved library as @library' do
post :create, params: { library: @invalid_attrs }
assigns(:library).should be_nil
end
it 'should be redirected to new session url' do
post :create, params: { library: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@library = libraries(:library_00001)
@attrs = { name: 'example' }
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested library' do
put :update, params: { id: @library.id, library: @attrs }
end
it 'assigns the requested library as @library' do
put :update, params: { id: @library.id, library: @attrs }
assigns(:library).should eq(@library)
end
it 'moves its position when specified' do
put :update, params: { id: @library.id, library: @attrs, move: 'lower' }
response.should redirect_to(libraries_url)
end
end
describe 'with invalid params' do
it 'assigns the requested library as @library' do
put :update, params: { id: @library.id, library: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested library' do
put :update, params: { id: @library.id, library: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @library.id, library: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'should be forbidden' do
put :update, params: { id: @library.id, library: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested library' do
put :update, params: { id: @library.id, library: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @library.id, library: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'should be forbidden' do
put :update, params: { id: @library.id, library: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested library' do
put :update, params: { id: @library.id, library: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @library.id, library: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested library as @library' do
put :update, params: { id: @library.id, library: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
describe 'Web' do
before(:each) do
@library = libraries(:library_00001)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should be_forbidden
end
it 'should not destroy library_id 1' do
delete :destroy, params: { id: 'web' }
response.should be_forbidden
end
it 'should not destroy library that contains shelves' do
delete :destroy, params: { id: 'kamata' }
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'Library' do
before(:each) do
@library = FactoryBot.create(:library)
@library.shelves.first.destroy
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'redirects to the libraries list' do
delete :destroy, params: { id: @library.id }
response.should redirect_to(libraries_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested library' do
delete :destroy, params: { id: @library.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @library.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/subjects_controller_spec.rb | spec/controllers/subjects_controller_spec.rb | require 'rails_helper'
describe SubjectsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:subject)
end
describe 'GET index', solr: true do
before do
Subject.reindex
end
describe 'When logged in as Administrator' do
login_admin
it 'assigns all subjects as @subjects' do
get :index
expect(assigns(:subjects)).not_to be_nil
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns all subjects as @subjects' do
get :index
expect(assigns(:subjects)).not_to be_nil
end
end
describe 'When logged in as User' do
login_user
it 'assigns all subjects as @subjects' do
get :index
expect(assigns(:subjects)).not_to be_nil
end
end
describe 'When not logged in' do
it 'assigns all subjects as @subjects' do
get :index
response.should be_successful
expect(assigns(:subjects)).not_to be_nil
end
end
end
describe 'GET show', solr: true do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :show, params: { id: subject.id }
expect(assigns(:subject)).to eq(subject)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :show, params: { id: subject.id }
expect(assigns(:subject)).to eq(subject)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :show, params: { id: subject.id }
expect(assigns(:subject)).to eq(subject)
end
end
describe 'When not logged in' do
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :show, params: { id: subject.id }
expect(assigns(:subject)).to eq(subject)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested subject as @subject' do
get :new
expect(assigns(:subject)).not_to be_valid
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested subject as @subject' do
get :new
expect(assigns(:subject)).to be_nil
end
end
describe 'When logged in as User' do
login_user
it 'should not assign the requested subject as @subject' do
get :new
expect(assigns(:subject)).to be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subject as @subject' do
get :new
expect(assigns(:subject)).to be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :edit, params: { id: subject.id }
expect(assigns(:subject)).to eq(subject)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :edit, params: { id: subject.id }
expect(assigns(:subject)).to eq(subject)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :edit, params: { id: subject.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subject as @subject' do
subject = FactoryBot.create(:subject)
get :edit, params: { id: subject.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { term: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'assigns a newly created subject as @subject' do
post :create, params: { subject: @attrs }
expect(assigns(:subject)).to be_valid
end
it 'redirects to the created subject' do
post :create, params: { subject: @attrs }
response.should redirect_to(subject_url(assigns(:subject)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject as @subject' do
post :create, params: { subject: @invalid_attrs }
expect(assigns(:subject)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { subject: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'assigns a newly created subject as @subject' do
post :create, params: { subject: @attrs }
expect(assigns(:subject)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject as @subject' do
post :create, params: { subject: @invalid_attrs }
expect(assigns(:subject)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'assigns a newly created subject as @subject' do
post :create, params: { subject: @attrs }
expect(assigns(:subject)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject as @subject' do
post :create, params: { subject: @invalid_attrs }
expect(assigns(:subject)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created subject as @subject' do
post :create, params: { subject: @attrs }
expect(assigns(:subject)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject as @subject' do
post :create, params: { subject: @invalid_attrs }
expect(assigns(:subject)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@subject = FactoryBot.create(:subject)
@attrs = valid_attributes
@invalid_attrs = { term: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'updates the requested subject' do
put :update, params: { id: @subject.id, subject: @attrs }
end
it 'assigns the requested subject as @subject' do
put :update, params: { id: @subject.id, subject: @attrs }
expect(assigns(:subject)).to eq(@subject)
end
end
describe 'with invalid params' do
it 'assigns the requested subject as @subject' do
put :update, params: { id: @subject.id, subject: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'updates the requested subject' do
put :update, params: { id: @subject.id, subject: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @subject.id, subject: @attrs }
expect(assigns(:subject)).to eq(@subject)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'should be forbidden' do
put :update, params: { id: @subject, subject: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'updates the requested subject' do
put :update, params: { id: @subject.id, subject: @attrs }
end
it 'assigns the requested subject as @subject' do
put :update, params: { id: @subject.id, subject: @attrs }
expect(assigns(:subject)).to eq(@subject)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested subject as @subject' do
put :update, params: { id: @subject.id, subject: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested subject' do
put :update, params: { id: @subject.id, subject: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @subject.id, subject: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested subject as @subject' do
put :update, params: { id: @subject.id, subject: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@subject = FactoryBot.create(:subject)
end
describe 'When logged in as Administrator' do
login_admin
it 'destroys the requested subject' do
delete :destroy, params: { id: @subject.id }
end
it 'redirects to the subjects list' do
delete :destroy, params: { id: @subject.id }
response.should redirect_to(subjects_url)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'destroys the requested subject' do
delete :destroy, params: { id: @subject.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subject.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'destroys the requested subject' do
delete :destroy, params: { id: @subject.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subject.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested subject' do
delete :destroy, params: { id: @subject.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subject.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/checkouts_controller_spec.rb | spec/controllers/checkouts_controller_spec.rb | require 'rails_helper'
describe CheckoutsController do
fixtures :all
describe 'GET index', solr: true do
before do
Checkout.reindex
end
before(:each) do
FactoryBot.create(:profile)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all checkouts as @checkouts' do
get :index
assigns(:checkouts).should eq Checkout.order('checkouts.created_at DESC').page(1)
assigns(:checkouts).total_entries.should eq Checkout.count
end
it "should get other user's index" do
get :index, params: { user_id: users(:admin).username }
response.should be_successful
assigns(:checkouts).should eq users(:admin).checkouts.not_returned.order('checkouts.id DESC').page(1)
end
describe "with render_views" do
render_views
it "should accept params: user_id, days_overdue, and reserved" do
username = users(:admin).username
get :index, params: { user_id: username }
expect(response.body).to have_link "No (3)", href: "/checkouts?reserved=false&user_id=#{username}"
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should get index' do
get :index
response.should be_successful
end
it 'should get index text' do
get :index, format: :text
assigns(:checkouts).count.should eq assigns(:checkouts).total_entries
response.should be_successful
end
it 'should get index rss' do
get :index, format: 'rss'
assigns(:checkouts).count.should eq assigns(:checkouts).total_entries
response.should be_successful
end
it 'should get overdue index' do
get :index, params: { days_overdue: 1 }
assigns(:checkouts).should eq Checkout.overdue(1.day.ago.beginning_of_day).order('checkouts.id DESC').page(1)
response.should be_successful
end
it 'should get overdue index with number of days_overdue' do
get :index, params: { days_overdue: 2 }
response.should be_successful
assigns(:checkouts).size.should > 0
end
it 'should get overdue index with invalid number of days_overdue' do
get :index, params: { days_overdue: 'invalid days' }
response.should be_successful
assigns(:checkouts).size.should > 0
end
it "should get other user's index" do
get :index, params: { user_id: users(:admin).username }
response.should be_successful
assigns(:checkouts).should eq users(:admin).checkouts.not_returned.order('checkouts.id DESC').page(1)
end
it 'should get index with item_id' do
get :index, params: { item_id: 1 }
response.should be_successful
assigns(:checkouts).should eq items(:item_00001).checkouts.order('checkouts.id DESC').page(1)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all checkouts as @checkouts' do
get :index
assigns(:checkouts).should eq(users(:user1).checkouts.order('checkouts.created_at DESC').page(1))
assigns(:checkouts).total_entries.should eq users(:user1).checkouts.count
response.should be_successful
end
it "should be forbidden if other's username is specified" do
user = users(:user3)
get :index, params: { user_id: user.username }
assigns(:checkouts).should be_nil
response.should be_forbidden
end
it 'should get my index feed' do
get :index, format: 'rss'
response.should be_successful
assigns(:checkouts).should eq(users(:user1).checkouts.order('checkouts.created_at DESC').page(1))
end
it 'should get my index with user_id' do
get :index, params: { user_id: users(:user1).username }
assigns(:checkouts).should be_nil
response.should redirect_to checkouts_url
end
it 'should get my index in text format' do
get :index, params: { user_id: users(:user1).username, format: :text }
response.should redirect_to checkouts_url(format: :text)
assigns(:checkouts).should be_nil
end
it 'should get my index in rss format' do
get :index, params: { user_id: users(:user1).username, format: 'rss' }
response.should redirect_to checkouts_url(format: :rss)
assigns(:checkouts).should be_nil
end
it "should not get other user's index" do
get :index, params: { user_id: users(:admin).username }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns nil as @checkouts' do
get :index
assigns(:checkouts).should be_nil
response.should redirect_to(new_user_session_url)
end
it 'assigns his own checkouts as @checkouts' do
token = '577830b08ecf9c4c4333d599a57a6f44a7fe76c0'
user = Profile.where(checkout_icalendar_token: token).first.user
get :index, params: { icalendar_token: token }
assigns(:checkouts).should eq user.checkouts.not_returned.order('checkouts.id DESC')
response.should be_successful
end
it 'should get ics template' do
token = '577830b08ecf9c4c4333d599a57a6f44a7fe76c0'
user = Profile.where(checkout_icalendar_token: token).first.user
get :index, params: { icalendar_token: token, format: :ics }
assigns(:checkouts).should eq user.checkouts.not_returned.order('checkouts.id DESC')
response.should be_successful
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it "should show other user's content" do
get :show, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it "should show other user's content" do
get :show, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should show my account' do
get :show, params: { id: 3 }
response.should be_successful
assigns(:checkout).should eq checkouts(:checkout_00003)
end
it "should not show other user's checkout" do
get :show, params: { id: 1 }
response.should be_forbidden
assigns(:checkout).should eq checkouts(:checkout_00001)
end
end
describe 'When not logged in' do
it 'should not assign the requested checkout as @checkout' do
get :show, params: { id: 1 }
response.should redirect_to new_user_session_url
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it "should edit other user's checkout" do
get :edit, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it "should edit other user's checkout" do
get :edit, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should edit my checkout' do
sign_in users(:user1)
get :edit, params: { id: 3 }
response.should be_successful
end
it "should not edit other user's checkout" do
get :edit, params: { id: 1 }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not edit checkout' do
get :edit, params: { id: 1 }
response.should redirect_to new_user_session_url
end
end
end
describe 'PUT update' do
before(:each) do
@checkout = checkouts(:checkout_00003)
@attrs = { due_date: 1.day.from_now }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested checkout' do
put :update, params: { id: @checkout.id, checkout: @attrs }
end
it 'assigns the requested checkout as @checkout' do
old_due_date = @checkout.due_date
put :update, params: { id: @checkout.id, checkout: @attrs }
assigns(:checkout).should eq(@checkout)
response.should redirect_to(assigns(:checkout))
assigns(:checkout).due_date.to_s.should eq 1.day.from_now.end_of_day.to_s
end
end
describe 'with invalid params' do
it 'assigns the requested checkout as @checkout' do
put :update, params: { id: @checkout.id, checkout: @invalid_attrs }
end
it 'should ignore item_id' do
put :update, params: { id: @checkout.id, checkout: @invalid_attrs }
response.should redirect_to(assigns(:checkout))
assigns(:checkout).changed?.should be_falsy
end
it 'should not accept invalid date' do
put :update, params: { id: @checkout.id, checkout: @invalid_attrs.merge(due_date: '2017-03-151') }
assigns(:checkout).changed?.should be_truthy
response.should be_successful
end
end
it 'should remove its own checkout history' do
put :remove_all, params: { user_id: users(:user1).username }
users(:user1).checkouts.returned.count.should eq 0
response.should redirect_to checkouts_url
end
it 'should not remove other checkout history' do
put :remove_all, params: { user_id: users(:user2).username }
users(:user1).checkouts.returned.count.should_not eq 0
response.should redirect_to checkouts_url
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested checkout' do
put :update, params: { id: @checkout.id, checkout: @attrs, user_id: @checkout.user.username }
end
it 'assigns the requested checkout as @checkout' do
put :update, params: { id: @checkout.id, checkout: @attrs, user_id: @checkout.user.username }
assigns(:checkout).should eq(@checkout)
response.should redirect_to(assigns(:checkout))
end
end
describe 'with invalid params' do
it 'assigns the checkout as @checkout' do
put :update, params: { id: @checkout.id, checkout: @invalid_attrs, user_id: @checkout.user.username }
assigns(:checkout).should be_valid
end
it 'should ignore item_id' do
put :update, params: { id: @checkout.id, checkout: @invalid_attrs, user_id: @checkout.user.username }
response.should redirect_to(assigns(:checkout))
end
end
it 'should update checkout item that is reserved' do
put :update, params: { id: 8, checkout: {} }
assigns(:checkout).errors[:base].include?(I18n.t('checkout.this_item_is_reserved')).should be_truthy
response.should be_successful
end
it "should update other user's checkout" do
put :update, params: { id: 1, checkout: {} }
response.should redirect_to checkout_url(assigns(:checkout))
end
it 'should remove its own checkout history' do
put :remove_all, params: { user_id: users(:user1).username }
users(:user1).checkouts.returned.count.should eq 0
response.should redirect_to checkouts_url
end
it 'should not remove other checkout history' do
put :remove_all, params: { user_id: users(:user2).username }
users(:user1).checkouts.returned.count.should_not eq 0
response.should redirect_to checkouts_url
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested checkout' do
put :update, params: { id: checkouts(:checkout_00001).id, checkout: @attrs }
end
it 'assigns the requested checkout as @checkout' do
put :update, params: { id: checkouts(:checkout_00001).id, checkout: @attrs }
assigns(:checkout).should eq(checkouts(:checkout_00001))
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested checkout as @checkout' do
put :update, params: { id: checkouts(:checkout_00001).id, checkout: @attrs }
response.should be_forbidden
end
end
it "should not update other user's checkout" do
put :update, params: { id: 1, checkout: {} }
response.should be_forbidden
end
it 'should not update checkout already renewed' do
put :update, params: { id: 9, checkout: {} }
assigns(:checkout).errors[:base].include?(I18n.t('checkout.excessed_renewal_limit')).should be_truthy
response.should be_successful
end
it 'should update my checkout' do
put :update, params: { id: 3, checkout: {} }
assigns(:checkout).should be_valid
response.should redirect_to checkout_url(assigns(:checkout))
end
it 'should not update checkout without item_id' do
put :update, params: { id: 3, checkout: { item_id: nil } }
assigns(:checkout).should be_valid
response.should redirect_to(assigns(:checkout))
assigns(:checkout).changed?.should be_falsy
end
it 'should remove its own checkout history' do
put :remove_all, params: { user_id: users(:user1).username }
assigns(:user).checkouts.returned.count.should eq 0
response.should redirect_to checkouts_url
end
it 'should not remove other checkout history' do
put :remove_all, params: { user_id: users(:admin).username }
assigns(:user).checkouts.returned.count.should eq 0
response.should be_forbidden
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested checkout' do
put :update, params: { id: @checkout.id, checkout: @attrs, user_id: @checkout.user.username }
end
it 'should be forbidden' do
put :update, params: { id: @checkout.id, checkout: @attrs, user_id: @checkout.user.username }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested checkout as @checkout' do
put :update, params: { id: @checkout.id, checkout: @invalid_attrs, user_id: @checkout.user.username }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@checkout = checkouts(:checkout_00003)
@returned_checkout = checkouts(:checkout_00012)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested checkout' do
delete :destroy, params: { id: @checkout.id }
end
it 'should not destroy the checkout that is not checked in' do
delete :destroy, params: { id: @checkout.id }
response.should be_forbidden
end
it 'redirects to the checkouts list' do
delete :destroy, params: { id: @returned_checkout.id }
response.should redirect_to(checkouts_url(user_id: @returned_checkout.user.username))
end
it 'should be forbidden to delete a checkout if its user is not set' do
delete :destroy, params: { id: @returned_checkout.id }
delete :destroy, params: { id: @returned_checkout.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested checkout' do
delete :destroy, params: { id: @checkout.id }
end
it 'should not destroy the checkout that is not checked in' do
delete :destroy, params: { id: @checkout.id }
response.should be_forbidden
end
it 'redirects to the checkouts list' do
delete :destroy, params: { id: @returned_checkout.id }
response.should redirect_to(checkouts_url(user_id: @returned_checkout.user.username))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested checkout' do
delete :destroy, params: { id: checkouts(:checkout_00001).id }
end
it 'should be forbidden' do
delete :destroy, params: { id: checkouts(:checkout_00001).id }
response.should be_forbidden
end
it 'should destroy my checkout' do
delete :destroy, params: { id: 13 }
response.should redirect_to checkouts_url(user_id: users(:user1).username)
end
end
describe 'When not logged in' do
it 'destroys the requested checkout' do
delete :destroy, params: { id: @checkout.id, user_id: @checkout.user.username }
end
it 'should be forbidden' do
delete :destroy, params: { id: @checkout.id, user_id: @checkout.user.username }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/create_types_controller_spec.rb | spec/controllers/create_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe CreateTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# CreateType. As you add validations to CreateType, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:create_type)
end
describe 'GET index' do
it 'assigns all create_types as @create_types' do
create_type = CreateType.create! valid_attributes
get :index
expect(assigns(:create_types)).to eq(CreateType.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested create_type as @create_type' do
create_type = CreateType.create! valid_attributes
get :show, params: { id: create_type.id }
expect(assigns(:create_type)).to eq(create_type)
end
end
describe 'GET new' do
it 'assigns a new create_type as @create_type' do
get :new
expect(assigns(:create_type)).to be_a_new(CreateType)
end
end
describe 'GET edit' do
it 'assigns the requested create_type as @create_type' do
create_type = CreateType.create! valid_attributes
get :edit, params: { id: create_type.id }
expect(assigns(:create_type)).to eq(create_type)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new CreateType' do
expect do
post :create, params: { create_type: valid_attributes }
end.to change(CreateType, :count).by(1)
end
it 'assigns a newly created create_type as @create_type' do
post :create, params: { create_type: valid_attributes }
expect(assigns(:create_type)).to be_a(CreateType)
expect(assigns(:create_type)).to be_persisted
end
it 'redirects to the created create_type' do
post :create, params: { create_type: valid_attributes }
expect(response).to redirect_to(CreateType.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved create_type as @create_type' do
# Trigger the behavior that occurs when invalid params are submitted
CreateType.any_instance.stub(:save).and_return(false)
post :create, params: { create_type: { name: 'test' } }
expect(assigns(:create_type)).to be_a_new(CreateType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
CreateType.any_instance.stub(:save).and_return(false)
post :create, params: { create_type: { name: 'test' } }
# expect(response).to render_template("new")
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested create_type' do
create_type = CreateType.create! valid_attributes
# Assuming there are no other create_types in the database, this
# specifies that the CreateType created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# CreateType.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: create_type.id, create_type: { 'name' => 'test' } }
end
it 'assigns the requested create_type as @create_type' do
create_type = CreateType.create! valid_attributes
put :update, params: { id: create_type.id, create_type: valid_attributes }
expect(assigns(:create_type)).to eq(create_type)
end
it 'redirects to the create_type' do
create_type = CreateType.create! valid_attributes
put :update, params: { id: create_type.id, create_type: valid_attributes }
expect(response).to redirect_to(create_type)
end
it 'moves its position when specified' do
create_type = CreateType.create! valid_attributes
position = create_type.position
put :update, params: { id: create_type.id, move: 'higher' }
expect(response).to redirect_to create_types_url
assigns(:create_type).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the create_type as @create_type' do
create_type = CreateType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
CreateType.any_instance.stub(:save).and_return(false)
put :update, params: { id: create_type.id, create_type: { name: 'test' } }
expect(assigns(:create_type)).to eq(create_type)
end
it "re-renders the 'edit' template" do
create_type = CreateType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
CreateType.any_instance.stub(:save).and_return(false)
put :update, params: { id: create_type.id, create_type: { name: 'test' } }
# expect(response).to render_template("edit")
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested create_type' do
create_type = CreateType.create! valid_attributes
expect do
delete :destroy, params: { id: create_type.id }
end.to change(CreateType, :count).by(-1)
end
it 'redirects to the create_types list' do
create_type = CreateType.create! valid_attributes
delete :destroy, params: { id: create_type.id }
expect(response).to redirect_to(create_types_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/item_has_use_restrictions_controller_spec.rb | spec/controllers/item_has_use_restrictions_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ItemHasUseRestrictionsController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:item_has_use_restriction)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:item_has_use_restriction)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all item_has_use_restrictions as @item_has_use_restrictions' do
get :index
assigns(:item_has_use_restrictions).should eq(ItemHasUseRestriction.order('id DESC').page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all item_has_use_restrictions as @item_has_use_restrictions' do
get :index
assigns(:item_has_use_restrictions).should eq(ItemHasUseRestriction.order('id DESC').page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all item_has_use_restrictions as @item_has_use_restrictions' do
get :index
assigns(:item_has_use_restrictions).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all item_has_use_restrictions as @item_has_use_restrictions' do
get :index
assigns(:item_has_use_restrictions).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :show, params: { id: item_has_use_restriction.id }
assigns(:item_has_use_restriction).should eq(item_has_use_restriction)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :show, params: { id: item_has_use_restriction.id }
assigns(:item_has_use_restriction).should eq(item_has_use_restriction)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :show, params: { id: item_has_use_restriction.id }
assigns(:item_has_use_restriction).should eq(item_has_use_restriction)
end
end
describe 'When not logged in' do
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :show, params: { id: item_has_use_restriction.id }
assigns(:item_has_use_restriction).should eq(item_has_use_restriction)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
get :new
assigns(:item_has_use_restriction).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested item_has_use_restriction as @item_has_use_restriction' do
get :new
assigns(:item_has_use_restriction).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested item_has_use_restriction as @item_has_use_restriction' do
get :new
assigns(:item_has_use_restriction).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested item_has_use_restriction as @item_has_use_restriction' do
get :new
assigns(:item_has_use_restriction).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :edit, params: { id: item_has_use_restriction.id }
assigns(:item_has_use_restriction).should eq(item_has_use_restriction)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :edit, params: { id: item_has_use_restriction.id }
assigns(:item_has_use_restriction).should eq(item_has_use_restriction)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :edit, params: { id: item_has_use_restriction.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested item_has_use_restriction as @item_has_use_restriction' do
item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
get :edit, params: { id: item_has_use_restriction.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { item_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @attrs }
assigns(:item_has_use_restriction).should be_valid
end
it 'redirects to the created patron' do
post :create, params: { item_has_use_restriction: @attrs }
response.should redirect_to(assigns(:item_has_use_restriction))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
assigns(:item_has_use_restriction).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { item_has_use_restriction: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @attrs }
assigns(:item_has_use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { item_has_use_restriction: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
assigns(:item_has_use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @attrs }
assigns(:item_has_use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { item_has_use_restriction: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
assigns(:item_has_use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @attrs }
assigns(:item_has_use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { item_has_use_restriction: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_has_use_restriction as @item_has_use_restriction' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
assigns(:item_has_use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { item_has_use_restriction: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
@attrs = valid_attributes
@invalid_attrs = { item_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
end
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
assigns(:item_has_use_restriction).should eq(@item_has_use_restriction)
response.should redirect_to(@item_has_use_restriction)
end
end
describe 'with invalid params' do
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @invalid_attrs }
assigns(:item_has_use_restriction).should eq(@item_has_use_restriction)
end
it 'should be forbidden' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
assigns(:item_has_use_restriction).should eq(@item_has_use_restriction)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested item_has_use_restriction as @item_has_use_restriction' do
put :update, params: { id: @item_has_use_restriction.id, item_has_use_restriction: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@item_has_use_restriction = FactoryBot.create(:item_has_use_restriction)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested item_has_use_restriction' do
delete :destroy, params: { id: @item_has_use_restriction.id }
end
it 'redirects to the item_has_use_restrictions list' do
delete :destroy, params: { id: @item_has_use_restriction.id }
response.should redirect_to(item_has_use_restrictions_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested item_has_use_restriction' do
delete :destroy, params: { id: @item_has_use_restriction.id }
end
it 'redirects to the item_has_use_restrictions list' do
delete :destroy, params: { id: @item_has_use_restriction.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested item_has_use_restriction' do
delete :destroy, params: { id: @item_has_use_restriction.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item_has_use_restriction.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested item_has_use_restriction' do
delete :destroy, params: { id: @item_has_use_restriction.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item_has_use_restriction.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/medium_of_performances_controller_spec.rb | spec/controllers/medium_of_performances_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe MediumOfPerformancesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# MediumOfPerformance. As you add validations to MediumOfPerformance, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:medium_of_performance)
end
describe 'GET index' do
it 'assigns all medium_of_performances as @medium_of_performances' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
get :index
expect(assigns(:medium_of_performances)).to eq(MediumOfPerformance.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested medium_of_performance as @medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
get :show, params: { id: medium_of_performance.id }
expect(assigns(:medium_of_performance)).to eq(medium_of_performance)
end
end
describe 'GET new' do
it 'assigns a new medium_of_performance as @medium_of_performance' do
get :new
expect(assigns(:medium_of_performance)).to be_a_new(MediumOfPerformance)
end
end
describe 'GET edit' do
it 'assigns the requested medium_of_performance as @medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
get :edit, params: { id: medium_of_performance.id }
expect(assigns(:medium_of_performance)).to eq(medium_of_performance)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new MediumOfPerformance' do
expect do
post :create, params: { medium_of_performance: valid_attributes }
end.to change(MediumOfPerformance, :count).by(1)
end
it 'assigns a newly created medium_of_performance as @medium_of_performance' do
post :create, params: { medium_of_performance: valid_attributes }
expect(assigns(:medium_of_performance)).to be_a(MediumOfPerformance)
expect(assigns(:medium_of_performance)).to be_persisted
end
it 'redirects to the created medium_of_performance' do
post :create, params: { medium_of_performance: valid_attributes }
expect(response).to redirect_to(MediumOfPerformance.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved medium_of_performance as @medium_of_performance' do
# Trigger the behavior that occurs when invalid params are submitted
MediumOfPerformance.any_instance.stub(:save).and_return(false)
post :create, params: { medium_of_performance: { name: 'test' } }
expect(assigns(:medium_of_performance)).to be_a_new(MediumOfPerformance)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
MediumOfPerformance.any_instance.stub(:save).and_return(false)
post :create, params: { medium_of_performance: { name: 'test' } }
# expect(response).to render_template("new")
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
# Assuming there are no other medium_of_performances in the database, this
# specifies that the MediumOfPerformance created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# MediumOfPerformance.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: medium_of_performance.id, medium_of_performance: { 'name' => 'test' } }
end
it 'assigns the requested medium_of_performance as @medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
put :update, params: { id: medium_of_performance.id, medium_of_performance: valid_attributes }
expect(assigns(:medium_of_performance)).to eq(medium_of_performance)
end
it 'redirects to the medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
put :update, params: { id: medium_of_performance.id, medium_of_performance: valid_attributes }
expect(response).to redirect_to(medium_of_performance)
end
it 'moves its position when specified' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
position = medium_of_performance.position
put :update, params: { id: medium_of_performance.id, move: 'higher' }
expect(response).to redirect_to medium_of_performances_url
assigns(:medium_of_performance).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the medium_of_performance as @medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
MediumOfPerformance.any_instance.stub(:save).and_return(false)
put :update, params: { id: medium_of_performance.id, medium_of_performance: { name: 'test' } }
expect(assigns(:medium_of_performance)).to eq(medium_of_performance)
end
it "re-renders the 'edit' template" do
medium_of_performance = MediumOfPerformance.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
MediumOfPerformance.any_instance.stub(:save).and_return(false)
put :update, params: { id: medium_of_performance.id, medium_of_performance: { name: 'test' } }
# expect(response).to render_template("edit")
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested medium_of_performance' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
expect do
delete :destroy, params: { id: medium_of_performance.id }
end.to change(MediumOfPerformance, :count).by(-1)
end
it 'redirects to the medium_of_performances list' do
medium_of_performance = MediumOfPerformance.create! valid_attributes
delete :destroy, params: { id: medium_of_performance.id }
expect(response).to redirect_to(medium_of_performances_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/picture_files_controller_spec.rb | spec/controllers/picture_files_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe PictureFilesController do
fixtures :all
disconnect_sunspot
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all picture_files as @picture_files' do
get :index
expect(assigns(:picture_files)).to eq(PictureFile.attached.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all picture_files as @picture_files' do
get :index
expect(assigns(:picture_files)).to eq(PictureFile.attached.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all picture_files as @picture_files' do
get :index
expect(assigns(:picture_files)).to eq(PictureFile.attached.page(1))
end
end
describe 'When not logged in' do
it 'assigns all picture_files as @picture_files' do
get :index
expect(assigns(:picture_files)).to eq(PictureFile.attached.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :show, params: { id: picture_file.id }
expect(assigns(:picture_file)).to eq(picture_file)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :show, params: { id: picture_file.id }
expect(assigns(:picture_file)).to eq(picture_file)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :show, params: { id: picture_file.id }
expect(assigns(:picture_file)).to eq(picture_file)
end
end
describe 'When not logged in' do
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :show, params: { id: picture_file.id }
expect(assigns(:picture_file)).to eq(picture_file)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested picture_file as @picture_file' do
get :new
expect(assigns(:picture_file)).to be_nil
expect(response).to redirect_to picture_files_url
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested picture_file as @picture_file' do
get :new
expect(assigns(:picture_file)).to be_nil
expect(response).to redirect_to picture_files_url
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested picture_file as @picture_file' do
get :new
expect(assigns(:picture_file)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested picture_file as @picture_file' do
get :new
expect(assigns(:picture_file)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :edit, params: { id: picture_file.id }
expect(assigns(:picture_file)).to eq(picture_file)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :edit, params: { id: picture_file.id }
expect(assigns(:picture_file)).to eq(picture_file)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :edit, params: { id: picture_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested picture_file as @picture_file' do
picture_file = PictureFile.find(1)
get :edit, params: { id: picture_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = { picture_attachable_type: 'Shelf', picture_attachable_id: 1, picture: fixture_file_upload('spinner.gif', 'image/gif') }
@invalid_attrs = { picture_attachable_id: 'invalid', picture_attachable_type: 'Library' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created picture_file as @picture_file' do
post :create, params: { picture_file: @attrs }
expect(assigns(:picture_file)).to be_valid
end
it 'redirects to the created picture_file' do
post :create, params: { picture_file: @attrs }
expect(response).to redirect_to(picture_file_url(assigns(:picture_file)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved picture_file as @picture_file' do
post :create, params: { picture_file: @invalid_attrs }
expect(assigns(:picture_file)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { picture_file: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created picture_file as @picture_file' do
post :create, params: { picture_file: @attrs }
expect(assigns(:picture_file)).to be_valid
end
it 'redirects to the created picture_file' do
post :create, params: { picture_file: @attrs }
expect(response).to redirect_to(picture_file_url(assigns(:picture_file)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved picture_file as @picture_file' do
post :create, params: { picture_file: @invalid_attrs }
expect(assigns(:picture_file)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { picture_file: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created picture_file as @picture_file' do
post :create, params: { picture_file: @attrs }
expect(assigns(:picture_file)).to be_nil
end
it 'should be forbidden' do
post :create, params: { picture_file: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved picture_file as @picture_file' do
post :create, params: { picture_file: @invalid_attrs }
expect(assigns(:picture_file)).to be_nil
end
it 'should be forbidden' do
post :create, params: { picture_file: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created picture_file as @picture_file' do
post :create, params: { picture_file: @attrs }
expect(assigns(:picture_file)).to be_nil
end
it 'should be forbidden' do
post :create, params: { picture_file: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved picture_file as @picture_file' do
post :create, params: { picture_file: @invalid_attrs }
expect(assigns(:picture_file)).to be_nil
end
it 'should be forbidden' do
post :create, params: { picture_file: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@picture_file = picture_files(:picture_file_00001)
@attrs = { picture_attachable_id: '1', picture_attachable_type: 'Manifestation' }
@invalid_attrs = { picture_attachable_id: 'invalid', picture_attachable_type: 'Library' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
end
it 'assigns the requested picture_file as @picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
expect(assigns(:picture_file)).to eq(@picture_file)
end
it 'moves its position when specified' do
put :update, params: { id: @picture_file.id, move: 'lower' }
expect(response).to redirect_to(picture_files_url(shelf_id: @picture_file.picture_attachable_id))
end
end
describe 'with invalid params' do
it 'assigns the requested picture_file as @picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
end
it 'assigns the requested picture_file as @picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
expect(assigns(:picture_file)).to eq(@picture_file)
expect(response).to redirect_to(@picture_file)
end
end
describe 'with invalid params' do
it 'assigns the picture_file as @picture_file' do
put :update, params: { id: @picture_file, picture_file: @invalid_attrs }
expect(assigns(:picture_file)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @picture_file, picture_file: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
end
it 'assigns the requested picture_file as @picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
expect(assigns(:picture_file)).to eq(@picture_file)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested picture_file as @picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @picture_file.id, picture_file: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested picture_file as @picture_file' do
put :update, params: { id: @picture_file.id, picture_file: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@picture_file = PictureFile.find(1)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested picture_file' do
delete :destroy, params: { id: @picture_file.id }
end
it 'redirects to the picture_files list' do
delete :destroy, params: { id: @picture_file.id }
expect(response).to redirect_to(picture_files_url(shelf_id: @picture_file.picture_attachable_id))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested picture_file' do
delete :destroy, params: { id: @picture_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @picture_file.id }
expect(response).to redirect_to(picture_files_url(shelf_id: @picture_file.picture_attachable_id))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested picture_file' do
delete :destroy, params: { id: @picture_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @picture_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested picture_file' do
delete :destroy, params: { id: @picture_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @picture_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/messages_controller_spec.rb | spec/controllers/messages_controller_spec.rb | require 'rails_helper'
describe MessagesController do
fixtures :all
describe 'GET index', solr: true do
before do
Message.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'should get its own messages' do
get :index
assigns(:messages).should_not be_nil
response.should be_successful
end
describe 'When user_id is specified' do
it 'assigns all messages as @messages' do
get :index, params: { user_id: @user.username }
assigns(:messages).should_not be_nil
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should get its own messages' do
get :index
assigns(:messages).should_not be_nil
response.should be_successful
end
describe 'When user_id is specified' do
it 'assigns all messages as @messages' do
get :index, params: { user_id: @user.username }
assigns(:messages).should_not be_nil
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'When user_id is specified' do
it 'assigns all messages as @messages' do
get :index
assigns(:messages).should_not be_nil
end
end
it 'should get its own messages' do
get :index
assigns(:messages).should_not be_nil
response.should be_successful
end
it 'should get index with query' do
get :index, params: { query: 'you' }
assigns(:messages).first.receiver.should eq users(:user1)
response.should be_successful
end
end
describe 'When not logged in' do
it 'assigns all messages as @messages' do
get :index
assigns(:messages).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested message as @message' do
message = messages(:user1_to_user2_1)
lambda do
get :show, params: { id: message.id }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
# response.should be_missing
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested message as @message' do
message = messages(:user1_to_user2_1)
lambda do
get :show, params: { id: message.id }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
# response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_user
it 'should show my message' do
get :show, params: { id: messages(:user2_to_user1_1).id }
response.should be_successful
end
it "should should not show other user's message" do
lambda do
get :show, params: { id: messages(:user1_to_user2_1).id }
end.should raise_error(ActiveRecord::RecordNotFound)
# response.should be_missing
end
end
describe 'When not logged in' do
it 'assigns the requested message as @message' do
get :show, params: { id: messages(:user1_to_user2_1).id }
response.should redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested message as @message' do
get :new
assigns(:message).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested message as @message' do
get :new
assigns(:message).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested message as @message' do
get :new
assigns(:message).should be_nil
response.should be_forbidden
end
it 'should not get new template without parent_id' do
get :new
response.should be_forbidden
end
it 'should not get new template with invalid parent_id' do
get :new, params: { parent_id: 1 }
response.should be_forbidden
end
it 'should not get new template with valid parent_id' do
get :new, params: { parent_id: 2 }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested message as @message' do
get :new
assigns(:message).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested message as @message' do
message = messages(:user1_to_user2_1)
lambda do
get :edit, params: { id: message.id }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested message as @message' do
message = messages(:user1_to_user2_1)
lambda do
get :edit, params: { id: message.id }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested message as @message' do
message = messages(:user1_to_user2_1)
lambda do
get :edit, params: { id: message.id }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
response.should be_successful
end
end
describe 'When not logged in' do
it 'assigns the requested message as @message' do
message = FactoryBot.create(:message)
get :edit, params: { id: message.id }
assigns(:message).should be_nil
response.should redirect_to new_user_session_url
end
end
end
describe 'POST create' do
before(:each) do
@attrs = { recipient: users(:user1).username, subject: 'test', body: 'test' }
@invalid_attrs = { recipient: users(:user1).username, subject: 'test', body: '' }
@invalid_user_attrs = { recipient: 'invalid_user', subject: 'test', body: 'test' }
@blank_user_attrs = { recipient: '', subject: 'test', body: 'test' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created message as @message' do
post :create, params: { message: @attrs, user_id: users(:user1).username }
assigns(:message).should be_valid
end
it 'redirects to the created message' do
post :create, params: { message: @attrs, user_id: users(:user1).username }
response.should redirect_to(messages_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved message as @message' do
post :create, params: { message: @invalid_attrs, user_id: users(:user1).username }
assigns(:message).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { message: @invalid_attrs, user_id: users(:user1).username }
response.should render_template('new')
response.should be_successful
end
end
describe 'with invalid recipient' do
it "re-renders the 'new' template" do
post :create, params: { message: @invalid_user_attrs }
message = assigns(:message)
message.should_not be_valid
message.errors.should have_key :receiver
message.errors.added?(:receiver, :blank).should be_truthy
response.should render_template('new')
end
it "re-renders the 'new' template" do
post :create, params: { message: @blank_user_attrs }
message = assigns(:message)
message.should_not be_valid
message.errors.should have_key :recipient
message.errors.added?(:recipient, :blank).should be_truthy
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should create message without parent_id' do
post :create, params: { message: { recipient: 'user2', subject: 'test', body: 'test' } }
response.should redirect_to messages_url
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not create message without parent_id' do
post :create, params: { message: { recipient: 'user2', subject: 'test', body: 'test' } }
response.should be_forbidden
end
it 'should not create message with parent_id' do
post :create, params: { message: { recipient: 'user2', subject: 'test', body: 'test', parent_id: 2 } }
response.should be_forbidden
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created message as @message' do
post :create, params: { message: @attrs }
assigns(:message).should be_nil
end
it 'should redirect to new_user_session_url' do
post :create, params: { message: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved message as @message' do
post :create, params: { message: @invalid_attrs }
assigns(:message).should be_nil
end
it 'should redirect to new_user_session_url' do
post :create, params: { message: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@message = messages(:user1_to_user2_1)
@attrs = FactoryBot.attributes_for(:message)
@invalid_attrs = { sender_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested message' do
lambda do
put :update, params: { id: @message.id, message: @attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
end
it 'assigns the requested message as @message' do
lambda do
put :update, params: { id: @message.id, message: @attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
# response.should be_missing
end
end
describe 'with invalid params' do
it 'assigns the requested message as @message' do
lambda do
put :update, params: { id: @message.id, message: @invalid_attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
end
it "re-renders the 'edit' template" do
lambda do
put :update, params: { id: @message.id, message: @invalid_attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested message' do
lambda do
put :update, params: { id: @message.id, message: @attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
end
it 'assigns the requested message as @message' do
lambda do
put :update, params: { id: @message.id, message: @attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
response.should be_successful
end
end
describe 'with invalid params' do
it 'assigns the requested message as @message' do
lambda do
put :update, params: { id: @message.id, message: @invalid_attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
end
it "re-renders the 'edit' template" do
lambda do
put :update, params: { id: @message.id, message: @invalid_attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
response.should be_successful
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested message' do
lambda do
put :update, params: { id: @message.id, message: @attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
end
it 'assigns the requested message as @message' do
lambda do
put :update, params: { id: @message.id, message: @attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
assigns(:message).should be_nil
response.should be_successful
end
end
describe 'with invalid params' do
it 'assigns the requested message as @message' do
lambda do
put :update, params: { id: @message.id, message: @invalid_attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
end
it "re-renders the 'edit' template" do
lambda do
put :update, params: { id: @message.id, message: @invalid_attrs }
end.should raise_error(ActiveRecord::RecordNotFound)
response.should be_successful
end
end
it 'should not update my message' do
put :update, params: { id: messages(:user2_to_user1_1), message: {} }
response.should be_forbidden
end
it "should not update other user's message" do
lambda do
put :update, params: { id: messages(:user1_to_user2_1), message: {} }
end.should raise_error(ActiveRecord::RecordNotFound)
response.should be_successful
end
end
describe 'When not logged in' do
it 'assigns the requested message as @message' do
put :update, params: { id: messages(:user2_to_user1_1), message: {} }
response.should redirect_to new_user_session_url
end
end
end
describe 'DELETE destroy' do
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should destroy own message' do
@message = FactoryBot.create(:message, recipient: @user.username)
delete :destroy, params: { id: @message.id }
response.should redirect_to messages_url
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should destroy own message' do
delete :destroy, params: { id: messages(:user2_to_user1_1) }
response.should redirect_to messages_url
response.should_not be_forbidden
end
it "should not destroy other user's message" do
lambda do
delete :destroy, params: { id: messages(:user1_to_user2_1) }
end.should raise_error(ActiveRecord::RecordNotFound)
response.should be_successful
end
end
describe 'When not logged in' do
it 'destroys the requested message' do
delete :destroy, params: { id: messages(:user1_to_user2_1) }
response.should redirect_to(new_user_session_url)
end
it 'should be redirected to new_user_session_url' do
delete :destroy, params: { id: messages(:user1_to_user2_1) }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST destroy_selected' do
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should destroy own message' do
message = FactoryBot.create(:message, recipient: @user.username)
post :destroy_selected, params: { delete: [ message.id ] }
response.should_not be_forbidden
response.should redirect_to(messages_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should destroy own message' do
message = FactoryBot.create(:message, recipient: @user.username)
post :destroy_selected, params: { delete: [ message.id ] }
response.should_not be_forbidden
response.should redirect_to(messages_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/content_types_controller_spec.rb | spec/controllers/content_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe ContentTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# ContentType. As you add validations to ContentType, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:content_type)
end
describe 'GET index' do
it 'assigns all content_types as @content_types' do
content_type = ContentType.create! valid_attributes
get :index
expect(assigns(:content_types)).to eq(ContentType.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested content_type as @content_type' do
content_type = ContentType.create! valid_attributes
get :show, params: { id: content_type.id }
expect(assigns(:content_type)).to eq(content_type)
end
end
describe 'GET new' do
it 'assigns a new content_type as @content_type' do
get :new
expect(assigns(:content_type)).to be_a_new(ContentType)
end
end
describe 'GET edit' do
it 'assigns the requested content_type as @content_type' do
content_type = ContentType.create! valid_attributes
get :edit, params: { id: content_type.id }
expect(assigns(:content_type)).to eq(content_type)
end
it 'assigns the content_type even if it associates manifestation(s)' do
content_type = FactoryBot.create(:content_type)
manifestation = FactoryBot.create(:manifestation, content_type_id: content_type.id)
get :edit, params: { id: content_type.id }
expect(assigns(:content_type)).to eq content_type
expect(response).to be_successful
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new ContentType' do
expect do
post :create, params: { content_type: valid_attributes }
end.to change(ContentType, :count).by(1)
end
it 'assigns a newly created content_type as @content_type' do
post :create, params: { content_type: valid_attributes }
expect(assigns(:content_type)).to be_a(ContentType)
expect(assigns(:content_type)).to be_persisted
end
it 'redirects to the created content_type' do
post :create, params: { content_type: valid_attributes }
expect(response).to redirect_to(ContentType.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved content_type as @content_type' do
# Trigger the behavior that occurs when invalid params are submitted
ContentType.any_instance.stub(:save).and_return(false)
post :create, params: { content_type: { name: 'test' } }
expect(assigns(:content_type)).to be_a_new(ContentType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
ContentType.any_instance.stub(:save).and_return(false)
post :create, params: { content_type: { name: 'test' } }
expect(response).to render_template('new')
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested content_type' do
content_type = ContentType.create! valid_attributes
# Assuming there are no other content_types in the database, this
# specifies that the ContentType created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# ContentType.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: content_type.id, content_type: { 'name' => 'test' } }
end
it 'assigns the requested content_type as @content_type' do
content_type = ContentType.create! valid_attributes
put :update, params: { id: content_type.id, content_type: valid_attributes }
expect(assigns(:content_type)).to eq(content_type)
end
it 'redirects to the content_type' do
content_type = ContentType.create! valid_attributes
put :update, params: { id: content_type.id, content_type: valid_attributes }
expect(response).to redirect_to(content_type)
end
it 'moves its position when specified' do
content_type = ContentType.create! valid_attributes
position = content_type.position
put :update, params: { id: content_type.id, move: 'higher' }
expect(response).to redirect_to content_types_url
assigns(:content_type).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the content_type as @content_type' do
content_type = ContentType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
ContentType.any_instance.stub(:save).and_return(false)
put :update, params: { id: content_type.id, content_type: { name: 'test' } }
expect(assigns(:content_type)).to eq(content_type)
end
it "re-renders the 'edit' template" do
content_type = ContentType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
ContentType.any_instance.stub(:save).and_return(false)
put :update, params: { id: content_type.id, content_type: { name: 'test' } }
expect(response).to render_template('edit')
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested content_type' do
content_type = ContentType.create! valid_attributes
expect do
delete :destroy, params: { id: content_type.id }
end.to change(ContentType, :count).by(-1)
end
it 'redirects to the content_types list' do
content_type = ContentType.create! valid_attributes
delete :destroy, params: { id: content_type.id }
expect(response).to redirect_to(content_types_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/manifestation_reserve_stats_controller_spec.rb | spec/controllers/manifestation_reserve_stats_controller_spec.rb | require 'rails_helper'
describe ManifestationReserveStatsController do
fixtures :all
describe 'GET index' do
before(:each) do
FactoryBot.create(:manifestation_reserve_stat)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all manifestation_reserve_stats as @manifestation_reserve_stats' do
get :index
assigns(:manifestation_reserve_stats).should eq(ManifestationReserveStat.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all manifestation_reserve_stats as @manifestation_reserve_stats' do
get :index
assigns(:manifestation_reserve_stats).should eq(ManifestationReserveStat.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all manifestation_reserve_stats as @manifestation_reserve_stats' do
get :index
assigns(:manifestation_reserve_stats).should eq(ManifestationReserveStat.page(1))
end
end
describe 'When not logged in' do
it 'should not assign manifestation_reserve_stats as @manifestation_reserve_stats' do
get :index
assigns(:manifestation_reserve_stats).should eq(ManifestationReserveStat.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :show, params: { id: manifestation_reserve_stat.id }
assigns(:manifestation_reserve_stat).should eq(manifestation_reserve_stat)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :show, params: { id: manifestation_reserve_stat.id }
assigns(:manifestation_reserve_stat).should eq(manifestation_reserve_stat)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :show, params: { id: manifestation_reserve_stat.id }
assigns(:manifestation_reserve_stat).should eq(manifestation_reserve_stat)
end
end
describe 'When not logged in' do
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :show, params: { id: manifestation_reserve_stat.id }
assigns(:manifestation_reserve_stat).should eq(manifestation_reserve_stat)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
get :new
assigns(:manifestation_reserve_stat).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
get :new
assigns(:manifestation_reserve_stat).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
get :new
assigns(:manifestation_reserve_stat).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
get :new
assigns(:manifestation_reserve_stat).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :edit, params: { id: manifestation_reserve_stat.id }
assigns(:manifestation_reserve_stat).should eq(manifestation_reserve_stat)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :edit, params: { id: manifestation_reserve_stat.id }
assigns(:manifestation_reserve_stat).should eq(manifestation_reserve_stat)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :edit, params: { id: manifestation_reserve_stat.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
get :edit, params: { id: manifestation_reserve_stat.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:manifestation_reserve_stat)
@invalid_attrs = { start_date: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should be_valid
end
it 'redirects to the created manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @attrs }
response.should redirect_to(manifestation_reserve_stat_url(assigns(:manifestation_reserve_stat)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
assigns(:manifestation_reserve_stat).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should be_valid
end
it 'redirects to the created manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @attrs }
response.should redirect_to(manifestation_reserve_stat_url(assigns(:manifestation_reserve_stat)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
assigns(:manifestation_reserve_stat).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_reserve_stat: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
assigns(:manifestation_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_reserve_stat: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_reserve_stat as @manifestation_reserve_stat' do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
assigns(:manifestation_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_reserve_stat: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
@attrs = FactoryBot.attributes_for(:manifestation_reserve_stat)
@invalid_attrs = { start_date: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
end
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should eq(@manifestation_reserve_stat)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
end
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should eq(@manifestation_reserve_stat)
response.should redirect_to(@manifestation_reserve_stat)
end
end
describe 'with invalid params' do
it 'assigns the manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat, manifestation_reserve_stat: @invalid_attrs }
assigns(:manifestation_reserve_stat).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @manifestation_reserve_stat, manifestation_reserve_stat: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
end
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
assigns(:manifestation_reserve_stat).should eq(@manifestation_reserve_stat)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_reserve_stat as @manifestation_reserve_stat' do
put :update, params: { id: @manifestation_reserve_stat.id, manifestation_reserve_stat: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@manifestation_reserve_stat = FactoryBot.create(:manifestation_reserve_stat)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested manifestation_reserve_stat' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
end
it 'redirects to the manifestation_reserve_stats list' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
response.should redirect_to(manifestation_reserve_stats_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested manifestation_reserve_stat' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
end
it 'redirects to the manifestation_reserve_stats list' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
response.should redirect_to(manifestation_reserve_stats_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested manifestation_reserve_stat' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested manifestation_reserve_stat' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_reserve_stat.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/item_custom_properties_controller_spec.rb | spec/controllers/item_custom_properties_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ItemCustomPropertiesController do
fixtures :all
disconnect_sunspot
def valid_attributes
@attrs = FactoryBot.attributes_for(:item_custom_property)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:item_custom_property)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all item_custom_properties as @item_custom_properties' do
get :index
expect(assigns(:item_custom_properties)).to eq(ItemCustomProperty.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all item_custom_properties as @item_custom_properties' do
get :index
expect(assigns(:item_custom_properties)).to eq(ItemCustomProperty.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all item_custom_properties as @item_custom_properties' do
get :index
expect(assigns(:item_custom_properties)).to eq nil
end
end
describe 'When not logged in' do
it 'assigns all item_custom_properties as @item_custom_properties' do
get :index
expect(assigns(:item_custom_properties)).to eq nil
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :show, params: { id: item_custom_property.id }
expect(assigns(:item_custom_property)).to eq(item_custom_property)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :show, params: { id: item_custom_property.id }
expect(assigns(:item_custom_property)).to eq(item_custom_property)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :show, params: { id: item_custom_property.id }
expect(assigns(:item_custom_property)).to eq(item_custom_property)
end
end
describe 'When not logged in' do
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :show, params: { id: item_custom_property.id }
expect(assigns(:item_custom_property)).to eq(item_custom_property)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item_custom_property as @item_custom_property' do
get :new
expect(assigns(:item_custom_property)).to be_a_new(ItemCustomProperty)
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested item_custom_property as @item_custom_property' do
get :new
expect(assigns(:item_custom_property)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested item_custom_property as @item_custom_property' do
get :new
expect(assigns(:item_custom_property)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested item_custom_property as @item_custom_property' do
get :new
expect(assigns(:item_custom_property)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :edit, params: { id: item_custom_property.id }
expect(assigns(:item_custom_property)).to eq(item_custom_property)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :edit, params: { id: item_custom_property.id }
expect(assigns(:item_custom_property)).to eq(item_custom_property)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :edit, params: { id: item_custom_property.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested item_custom_property as @item_custom_property' do
item_custom_property = FactoryBot.create(:item_custom_property)
get :edit, params: { id: item_custom_property.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to be_valid
end
it 'redirects to the created item' do
post :create, params: { item_custom_property: @attrs }
expect(response).to redirect_to(assigns(:item_custom_property))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @invalid_attrs }
expect(assigns(:item_custom_property)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { item_custom_property: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to be_nil
end
it 'redirects to the created item' do
post :create, params: { item_custom_property: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @invalid_attrs }
expect(assigns(:item_custom_property)).to be_nil
end
it "re-renders the 'new' template" do
post :create, params: { item_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item_custom_property: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @invalid_attrs }
expect(assigns(:item_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item_custom_property: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item_custom_property as @item_custom_property' do
post :create, params: { item_custom_property: @invalid_attrs }
expect(assigns(:item_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item_custom_property: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@item_custom_property = FactoryBot.create(:item_custom_property)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
end
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to eq(@item_custom_property)
expect(response).to redirect_to(@item_custom_property)
end
end
describe 'with invalid params' do
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @invalid_attrs }
expect(response).to render_template('edit')
end
end
it 'moves its position when specified' do
item_custom_property = ItemCustomProperty.create! valid_attributes
position = item_custom_property.position
put :update, params: { id: item_custom_property.id, move: 'higher' }
expect(response).to redirect_to item_custom_properties_url
assigns(:item_custom_property).reload.position.should eq position - 1
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
end
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to eq @item_custom_property
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
end
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
expect(assigns(:item_custom_property)).to eq(@item_custom_property)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested item_custom_property as @item_custom_property' do
put :update, params: { id: @item_custom_property.id, item_custom_property: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@item_custom_property = FactoryBot.create(:item_custom_property)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested item_custom_property' do
delete :destroy, params: { id: @item_custom_property.id }
end
it 'redirects to the item_custom_properties list' do
delete :destroy, params: { id: @item_custom_property.id }
expect(response).to redirect_to(item_custom_properties_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested item_custom_property' do
delete :destroy, params: { id: @item_custom_property.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item_custom_property.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested item_custom_property' do
delete :destroy, params: { id: @item_custom_property.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item_custom_property.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested item_custom_property' do
delete :destroy, params: { id: @item_custom_property.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item_custom_property.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/checkins_controller_spec.rb | spec/controllers/checkins_controller_spec.rb | require 'rails_helper'
describe CheckinsController do
fixtures :all
def mock_user(stubs = {})
(@mock_user ||= mock_model(Checkin).as_null_object).tap do |user|
user.stub(stubs) unless stubs.empty?
end
end
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all checkins as @checkins' do
get :index
assigns(:checkins).should eq Checkin.page(1)
response.should be_successful
end
describe 'When basket_id is specified' do
it 'assigns all checkins as @checkins' do
get :index, params: { basket_id: 10 }
assigns(:checkins).should eq Basket.find(10).checkins.page(1)
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all checkins as @checkins' do
get :index
assigns(:checkins).should eq Checkin.page(1)
response.should be_successful
end
describe 'When basket_id is specified' do
it 'assigns all checkins as @checkins' do
get :index, params: { basket_id: 9 }
assigns(:checkins).should eq Basket.find(9).checkins.page(1)
response.should be_successful
end
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign all checkins as @checkins' do
get :index
assigns(:checkins).should be_nil
response.should be_forbidden
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :show, params: { id: checkin.id }
assigns(:checkin).should eq(checkin)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :show, params: { id: checkin.id }
assigns(:checkin).should eq(checkin)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :show, params: { id: checkin.id }
assigns(:checkin).should eq(checkin)
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :show, params: { id: checkin.id }
assigns(:checkin).should eq(checkin)
response.should redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested checkin as @checkin' do
get :new
assigns(:checkin).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested checkin as @checkin' do
get :new
assigns(:checkin).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested checkin as @checkin' do
get :new
assigns(:checkin).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested checkin as @checkin' do
get :new
assigns(:checkin).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :edit, params: { id: checkin.id }
assigns(:checkin).should eq(checkin)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :edit, params: { id: checkin.id }
assigns(:checkin).should eq(checkin)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :edit, params: { id: checkin.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested checkin as @checkin' do
checkin = checkins(:checkin_00001)
get :edit, params: { id: checkin.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = { item_identifier: '00003' }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
assigns(:checkin).should be_nil
end
it 'should not create checkin without basket_id' do
post :create, params: { checkin: @attrs }
response.should be_forbidden
end
describe 'When basket_id is specified' do
it 'redirects to the created checkin' do
post :create, params: { checkin: @attrs, basket_id: 9 }
response.should redirect_to(checkins_url(basket_id: assigns(:checkin).basket_id))
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
end
it 'should checkin the overdue item' do
post :create, params: { checkin: { item_identifier: '00014' }, basket_id: 9 }
response.should redirect_to(checkins_url(basket_id: assigns(:checkin).basket_id))
assigns(:checkin).checkout.should be_valid
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
end
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved checkin as @checkin' do
post :create, params: { checkin: @invalid_attrs }
assigns(:checkin).should be_nil
end
it 'should be forbidden' do
post :create, params: { checkin: @invalid_attrs }
response.should be_forbidden
end
end
it 'should not create checkin without item_id' do
post :create, params: { checkin: { item_identifier: nil }, basket_id: 9 }
assigns(:checkin).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
assigns(:checkin).should be_nil
end
it 'should not create checkin without basket_id' do
post :create, params: { checkin: @attrs }
response.should be_forbidden
end
it 'should show notification when it is reserved' do
post :create, params: { checkin: { item_identifier: '00008' }, basket_id: 9 }
flash[:message].to_s.index(I18n.t('item.this_item_is_reserved')).should be_truthy
assigns(:checkin).checkout.item.should be_retained
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
response.should redirect_to(checkins_url(basket_id: assigns(:basket).id))
end
it 'should show notification when an item includes supplements' do
post :create, params: { checkin: { item_identifier: '00004' }, basket_id: 9 }
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
flash[:message].to_s.index(I18n.t('item.this_item_include_supplement')).should be_truthy
response.should redirect_to(checkins_url(basket_id: assigns(:basket).id))
end
end
it "should show notice when other library's item is checked in" do
sign_in users(:librarian2)
post :create, params: { checkin: { item_identifier: '00009' }, basket_id: 9 }
assigns(:checkin).should be_valid
flash[:message].to_s.index(I18n.t('checkin.other_library_item')).should be_truthy
response.should redirect_to(checkins_url(basket_id: assigns(:basket).id))
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
assigns(:checkin).should be_nil
end
it 'should be forbidden' do
post :create, params: { checkin: @attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
before(:each) do
@attrs = { item_identifier: '00003' }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
end
it 'should redirect to new session url' do
post :create, params: { checkin: @attrs }
response.should redirect_to new_user_session_url
end
end
end
end
describe 'POST create (json format)' do
before(:each) do
@attrs = { item_identifier: '00003' }
@invalid_attrs = { item_identifier: 'invalid' }
request.env["HTTP_ACCEPT"] = 'application/json'
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
assigns(:checkin).should be_nil
end
it 'should not create checkin without basket_id' do
post :create, params: { checkin: @attrs }
json = JSON.parse(response.body)
expect(json['error']).to eq('forbidden')
end
describe 'When basket_id is specified' do
it 'redirects to the created checkin' do
post :create, params: { checkin: @attrs, basket_id: 9 }
expect(response).to have_http_status(:created)
json = JSON.parse(response.body)
expect(json['result']['basket_id']).to eq(9)
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
end
it 'should checkin the overdue item' do
post :create, params: { checkin: { item_identifier: '00014' }, basket_id: 9 }
expect(response).to have_http_status(:created)
assigns(:checkin).checkout.should be_valid
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
end
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved checkin as @checkin' do
post :create, params: { checkin: @invalid_attrs }
assigns(:checkin).should be_nil
end
it 'should be forbidden' do
post :create, params: { checkin: @invalid_attrs }
json = JSON.parse(response.body)
expect(json['error']).to eq('forbidden')
end
end
it 'should not create checkin without item_id' do
post :create, params: { checkin: { item_identifier: nil }, basket_id: 9 }
assigns(:checkin).should_not be_valid
expect(response).to have_http_status(:unprocessable_entity)
json = JSON.parse(response.body)
expect(json['messages']['base']).to match_array([ I18n.t('checkin.item_not_found') ])
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
assigns(:checkin).should be_nil
end
it 'should not create checkin without basket_id' do
post :create, params: { checkin: @attrs }
json = JSON.parse(response.body)
expect(json['error']).to eq('forbidden')
end
it 'should show notification when it is reserved' do
post :create, params: { checkin: { item_identifier: '00008' }, basket_id: 9 }
flash[:message].to_s.index(I18n.t('item.this_item_is_reserved')).should be_truthy
assigns(:checkin).checkout.item.should be_retained
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
expect(response).to have_http_status(:created)
end
it 'should show notification when an item includes supplements' do
post :create, params: { checkin: { item_identifier: '00004' }, basket_id: 9 }
assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
flash[:message].to_s.index(I18n.t('item.this_item_include_supplement')).should be_truthy
expect(response).to have_http_status(:created)
end
end
it "should show notice when other library's item is checked in" do
sign_in users(:librarian2)
post :create, params: { checkin: { item_identifier: '00009' }, basket_id: 9 }
assigns(:checkin).should be_valid
flash[:message].to_s.index(I18n.t('checkin.other_library_item')).should be_truthy
expect(response).to have_http_status(:created)
end
end
describe 'When not logged in' do
before(:each) do
@attrs = { item_identifier: '00003' }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'with valid params' do
it 'assigns a newly created checkin as @checkin' do
post :create, params: { checkin: @attrs }
end
it 'should redirect to new session url' do
post :create, params: { checkin: @attrs }
expect(response).to have_http_status(:ok)
end
end
end
end
describe 'PUT update' do
before(:each) do
@checkin = checkins(:checkin_00001)
@attrs = { item_identifier: @checkin.item.item_identifier }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
end
it 'assigns the requested checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
assigns(:checkin).should eq(@checkin)
response.should redirect_to(@checkin)
end
end
describe 'with invalid params' do
it 'assigns the requested checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
expect(response).to be_successful
end
it 'should not update checkin without item_identifier' do
put :update, params: { id: @checkin.id, checkin: @attrs.merge(item_identifier: nil) }
assigns(:checkin).should be_valid
response.should redirect_to(@checkin)
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
end
it 'assigns the requested checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
assigns(:checkin).should eq(@checkin)
response.should redirect_to(@checkin)
end
end
describe 'with invalid params' do
it 'assigns the checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
expect(assigns(:checkin)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
expect(response).to be_successful
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
end
it 'assigns the requested checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
assigns(:checkin).should eq(@checkin)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested checkin' do
put :update, params: { id: @checkin.id, checkin: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @checkin.id, checkin: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested checkin as @checkin' do
put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@checkin = checkins(:checkin_00001)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested checkin' do
delete :destroy, params: { id: @checkin.id }
end
it 'redirects to the checkins list' do
delete :destroy, params: { id: @checkin.id }
response.should redirect_to(checkins_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested checkin' do
delete :destroy, params: { id: @checkin.id }
end
it 'redirects to the checkins list' do
delete :destroy, params: { id: @checkin.id }
response.should redirect_to(checkins_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested checkin' do
delete :destroy, params: { id: @checkin.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @checkin.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested checkin' do
delete :destroy, params: { id: @checkin.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @checkin.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/series_statements_controller_spec.rb | spec/controllers/series_statements_controller_spec.rb | require 'rails_helper'
describe SeriesStatementsController do
fixtures :users
def valid_attributes
FactoryBot.attributes_for(:series_statement)
end
describe 'GET index', solr: true do
before do
SeriesStatement.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all series_statements as @series_statements' do
get :index
expect(assigns(:series_statements)).not_to be_nil
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all series_statements as @series_statements' do
get :index
expect(assigns(:series_statements)).not_to be_nil
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all series_statements as @series_statements' do
get :index
expect(assigns(:series_statements)).not_to be_nil
end
end
describe 'When not logged in' do
it 'assigns all series_statements as @series_statements' do
get :index
expect(assigns(:series_statements)).not_to be_nil
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :show, params: { id: series_statement.id }
expect(assigns(:series_statement)).to eq(series_statement)
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :show, params: { id: series_statement.id }
expect(assigns(:series_statement)).to eq(series_statement)
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :show, params: { id: series_statement.id }
expect(assigns(:series_statement)).to eq(series_statement)
expect(response).to be_successful
end
end
describe 'When not logged in' do
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :show, params: { id: series_statement.id }
expect(assigns(:series_statement)).to eq(series_statement)
expect(response).to be_successful
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested series_statement as @series_statement' do
get :new
expect(assigns(:series_statement)).not_to be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested series_statement as @series_statement' do
get :new
expect(assigns(:series_statement)).not_to be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested series_statement as @series_statement' do
get :new
expect(assigns(:series_statement)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested series_statement as @series_statement' do
get :new
expect(assigns(:series_statement)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :edit, params: { id: series_statement.id }
expect(assigns(:series_statement)).to eq(series_statement)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :edit, params: { id: series_statement.id }
expect(assigns(:series_statement)).to eq(series_statement)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :edit, params: { id: series_statement.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested series_statement as @series_statement' do
series_statement = FactoryBot.create(:series_statement)
get :edit, params: { id: series_statement.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { original_title: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created series_statement as @series_statement' do
post :create, params: { series_statement: @attrs }
expect(assigns(:series_statement)).to be_valid
end
it 'redirects to the created series_statement' do
post :create, params: { series_statement: @attrs }
expect(response).to redirect_to(series_statement_url(assigns(:series_statement)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement as @series_statement' do
post :create, params: { series_statement: @invalid_attrs }
expect(assigns(:series_statement)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { series_statement: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created series_statement as @series_statement' do
post :create, params: { series_statement: @attrs }
expect(assigns(:series_statement)).to be_valid
end
it 'redirects to the created series_statement' do
post :create, params: { series_statement: @attrs }
expect(response).to redirect_to(series_statement_url(assigns(:series_statement)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement as @series_statement' do
post :create, params: { series_statement: @invalid_attrs }
expect(assigns(:series_statement)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { series_statement: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created series_statement as @series_statement' do
post :create, params: { series_statement: @attrs }
expect(assigns(:series_statement)).to be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement as @series_statement' do
post :create, params: { series_statement: @invalid_attrs }
expect(assigns(:series_statement)).to be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created series_statement as @series_statement' do
post :create, params: { series_statement: @attrs }
expect(assigns(:series_statement)).to be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement as @series_statement' do
post :create, params: { series_statement: @invalid_attrs }
expect(assigns(:series_statement)).to be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@series_statement = FactoryBot.create(:series_statement)
@attrs = valid_attributes
@invalid_attrs = { original_title: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
end
it 'assigns the requested series_statement as @series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
expect(assigns(:series_statement)).to eq(@series_statement)
end
it 'moves its position when specified' do
put :update, params: { id: @series_statement.id, move: 'lower' }
expect(response).to redirect_to(series_statements_url)
end
end
describe 'with invalid params' do
it 'assigns the requested series_statement as @series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
end
it 'assigns the requested series_statement as @series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
expect(assigns(:series_statement)).to eq(@series_statement)
expect(response).to redirect_to(@series_statement)
end
end
describe 'with invalid params' do
it 'assigns the series_statement as @series_statement' do
put :update, params: { id: @series_statement, series_statement: @invalid_attrs }
expect(assigns(:series_statement)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @series_statement, series_statement: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
end
it 'assigns the requested series_statement as @series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
expect(assigns(:series_statement)).to eq(@series_statement)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested series_statement as @series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @series_statement.id, series_statement: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested series_statement as @series_statement' do
put :update, params: { id: @series_statement.id, series_statement: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@series_statement = FactoryBot.create(:series_statement)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested series_statement' do
delete :destroy, params: { id: @series_statement.id }
end
it 'redirects to the series_statements list' do
delete :destroy, params: { id: @series_statement.id }
expect(response).to redirect_to(series_statements_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested series_statement' do
delete :destroy, params: { id: @series_statement.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @series_statement.id }
expect(response).to redirect_to(series_statements_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested series_statement' do
delete :destroy, params: { id: @series_statement.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @series_statement.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested series_statement' do
delete :destroy, params: { id: @series_statement.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @series_statement.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/baskets_controller_spec.rb | spec/controllers/baskets_controller_spec.rb | require 'rails_helper'
describe BasketsController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all baskets as @baskets' do
get :index, params: { user_id: users(:user1).username }
assigns(:baskets).should_not be_empty
response.should be_successful
end
it 'should get index without user_id' do
get :index
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all baskets as @baskets' do
get :index, params: { user_id: users(:user1).username }
assigns(:baskets).should_not be_empty
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all baskets as @baskets' do
get :index, params: { user_id: users(:user1).username }
assigns(:baskets).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all baskets as @baskets' do
get :index, params: { user_id: users(:user1).username }
assigns(:baskets).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested basket as @basket' do
get :show, params: { id: 1, user_id: users(:admin).username }
assigns(:basket).should eq(Basket.find(1))
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested basket as @basket' do
get :new
assigns(:basket).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested basket as @basket' do
get :new
assigns(:basket).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested basket as @basket' do
get :new
assigns(:basket).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested basket as @basket' do
get :new
assigns(:basket).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
before(:each) do
@basket = baskets(:basket_00001)
end
it 'assigns the requested basket as @basket' do
get :edit, params: { id: @basket.id }
assigns(:basket).should eq(@basket)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
before(:each) do
@basket = baskets(:basket_00001)
end
it 'assigns the requested basket as @basket' do
get :edit, params: { id: @basket.id }
assigns(:basket).should eq(@basket)
end
end
describe 'When logged in as User' do
login_fixture_user
before(:each) do
@basket = baskets(:basket_00001)
end
it 'should not assign the requested basket as @basket' do
get :edit, params: { id: @basket.id }
assigns(:basket).should eq(@basket)
response.should be_forbidden
end
end
describe 'When not logged in' do
before(:each) do
@basket = baskets(:basket_00001)
end
it 'should not assign the requested basket as @basket' do
get :edit, params: { id: @basket.id }
assigns(:basket).should eq(@basket)
response.should redirect_to new_user_session_url
end
end
end
describe 'POST create' do
before(:each) do
@attrs = { user_number: users(:user1).profile.user_number }
@invalid_attrs = { user_number: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
assigns(:basket).should be_valid
end
end
describe 'with blank params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: { note: 'test' } }
assigns(:basket).should_not be_valid
end
end
describe 'with invalid params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: @invalid_attrs }
assigns(:basket).should_not be_valid
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
assigns(:basket).should be_valid
end
end
describe 'with blank params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: { note: 'test' } }
assigns(:basket).should_not be_valid
end
end
describe 'with invalid params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: @invalid_attrs }
assigns(:basket).should_not be_valid
end
end
it 'should not create basket when user is suspended' do
post :create, params: { basket: { user_number: users(:user4).profile.user_number } }
assigns(:basket).should_not be_valid
assigns(:basket).errors['base'].include?(I18n.t('basket.this_account_is_suspended')).should be_truthy
response.should be_successful
end
it 'should not create basket when user is not found' do
post :create, params: { basket: { user_number: 'not found' } }
assigns(:basket).should_not be_valid
assigns(:basket).errors['base'].include?(I18n.t('user.not_found')).should be_truthy
response.should be_successful
end
it 'should not create basket without user_number' do
post :create, params: { basket: { note: 'test' } }
assigns(:basket).should_not be_valid
response.should be_successful
end
it 'should create basket' do
post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
assigns(:basket).should be_valid
response.should redirect_to new_checked_item_url(basket_id: assigns(:basket).id)
end
it 'should not create basket without user_number' do
post :create, params: { basket: { note: 'test' } }
assigns(:basket).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
assigns(:basket).should be_nil
end
it 'should be forbidden' do
post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
response.should be_forbidden
end
end
it 'should not create basket' do
post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
response.should be_forbidden
end
end
describe 'When not logged in' do
describe 'with blank params' do
it 'assigns a newly created basket as @basket' do
post :create, params: { basket: { note: 'test' } }
assigns(:basket).should be_nil
end
it 'should be redirected to new_user_session_url' do
post :create, params: { basket: { note: 'test' } }
assigns(:basket).should be_nil
assert_response :redirect
response.should redirect_to new_user_session_url
end
end
end
end
describe 'PUT update' do
before(:each) do
@attrs = { user_id: users(:user1).username }
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested basket' do
put :update, params: { id: 8, basket: @attrs }
end
it 'assigns the requested basket as @basket' do
put :update, params: { id: 8, basket: @attrs }
assigns(:basket).checkouts.order('created_at DESC').first.item.circulation_status.name.should eq 'On Loan'
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@basket = FactoryBot.create(:basket)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'should destroy basket without user_id' do
delete :destroy, params: { id: @basket.id, basket: { user_id: nil }, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
it 'should destroy basket' do
delete :destroy, params: { id: @basket.id, basket: {}, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should destroy basket without user_id' do
delete :destroy, params: { id: @basket.id, basket: { user_id: nil }, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
it 'should destroy basket' do
delete :destroy, params: { id: @basket.id, basket: {}, user_id: users(:user1).username }
response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not destroy basket' do
delete :destroy, params: { id: 3, user_id: users(:user1).username }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested basket' do
delete :destroy, params: { id: @basket.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @basket.id }
response.should redirect_to new_user_session_url
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/nii_types_controller_spec.rb | spec/controllers/nii_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe NiiTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# NiiType. As you add validations to NiiType, be sure to
# update the return value of this method accordingly.
def valid_attributes
{ name: 'test' }
end
describe "GET index" do
it "assigns all nii_types as @nii_types" do
nii_type = NiiType.create! valid_attributes
get :index
expect(assigns(:nii_types)).to eq(NiiType.order(:position))
end
end
describe "GET show" do
it "assigns the requested nii_type as @nii_type" do
nii_type = NiiType.create! valid_attributes
get :show, params: { id: nii_type.id }
expect(assigns(:nii_type)).to eq(nii_type)
end
end
describe "GET new" do
it "assigns a new nii_type as @nii_type" do
get :new
expect(assigns(:nii_type)).to be_a_new(NiiType)
end
end
describe "GET edit" do
it "assigns the requested nii_type as @nii_type" do
nii_type = NiiType.create! valid_attributes
get :edit, params: { id: nii_type.id }
expect(assigns(:nii_type)).to eq(nii_type)
end
end
describe "POST create" do
describe "with valid params" do
it "creates a new NiiType" do
expect do
post :create, params: { nii_type: valid_attributes }
end.to change(NiiType, :count).by(1)
end
it "assigns a newly created nii_type as @nii_type" do
post :create, params: { nii_type: valid_attributes }
expect(assigns(:nii_type)).to be_a(NiiType)
expect(assigns(:nii_type)).to be_persisted
end
it "redirects to the created nii_type" do
post :create, params: { nii_type: valid_attributes }
expect(response).to redirect_to(NiiType.last)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved nii_type as @nii_type" do
# Trigger the behavior that occurs when invalid params are submitted
NiiType.any_instance.stub(:save).and_return(false)
post :create, params: { nii_type: { name: "test" } }
expect(assigns(:nii_type)).to be_a_new(NiiType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
NiiType.any_instance.stub(:save).and_return(false)
post :create, params: { nii_type: { name: "test" } }
expect(response).to render_template("new")
end
end
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested nii_type" do
nii_type = NiiType.create! valid_attributes
# Assuming there are no other nii_types in the database, this
# specifies that the NiiType created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
# NiiType.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: nii_type.id, nii_type: { 'name' => 'test' } }
end
it "assigns the requested nii_type as @nii_type" do
nii_type = NiiType.create! valid_attributes
put :update, params: { id: nii_type.id, nii_type: valid_attributes }
expect(assigns(:nii_type)).to eq(nii_type)
end
it "redirects to the nii_type" do
nii_type = NiiType.create! valid_attributes
put :update, params: { id: nii_type.id, nii_type: valid_attributes }
expect(response).to redirect_to(nii_type)
end
it "moves its position when specified" do
nii_type = NiiType.create! valid_attributes
position = nii_type.position
put :update, params: { id: nii_type.id, move: 'higher' }
expect(response).to redirect_to nii_types_url
assigns(:nii_type).reload.position.should eq position - 1
end
end
describe "with invalid params" do
it "assigns the nii_type as @nii_type" do
nii_type = NiiType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
NiiType.any_instance.stub(:save).and_return(false)
put :update, params: { id: nii_type.id, nii_type: { name: "test" } }
expect(assigns(:nii_type)).to eq(nii_type)
end
it "re-renders the 'edit' template" do
nii_type = NiiType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
NiiType.any_instance.stub(:save).and_return(false)
put :update, params: { id: nii_type.id, nii_type: { name: "test" } }
expect(response).to render_template("edit")
end
end
end
describe "DELETE destroy" do
it "destroys the requested nii_type" do
nii_type = NiiType.create! valid_attributes
expect do
delete :destroy, params: { id: nii_type.id }
end.to change(NiiType, :count).by(-1)
end
it "redirects to the nii_types list" do
nii_type = NiiType.create! valid_attributes
delete :destroy, params: { id: nii_type.id }
expect(response).to redirect_to(nii_types_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/withdraws_controller_spec.rb | spec/controllers/withdraws_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe WithdrawsController, type: :controller do
fixtures :all
# This should return the minimal set of attributes required to create a valid
# Withdraw. As you add validations to Withdraw, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
FactoryBot.build(:withdraw).attributes.with_indifferent_access
end
let(:invalid_attributes) do
{ item_id: nil }
end
let(:valid_create_attributes) do
{ basket_id: Basket.find(valid_attributes[:basket_id]).id,
withdraw: { item_identifier: Item.find(valid_attributes[:item_id]).item_identifier } }
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# WithdrawsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe 'GET #index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all withdraws as @withdraws' do
Withdraw.create! valid_attributes
get :index, params: { basket_id: 1 }
expect(assigns(:withdraws)).to eq baskets(:basket_00001).withdraws.order('withdraws.created_at DESC').page(1)
end
end
end
describe 'GET #show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested withdraw as @withdraw' do
withdraw = Withdraw.create! valid_attributes
get :show, params: { id: withdraw.to_param }
expect(assigns(:withdraw)).to eq(withdraw)
response.should be_successful
end
end
end
describe 'GET #new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns a new withdraw as @withdraw' do
get :new
expect(assigns(:withdraw)).to be_a_new(Withdraw)
end
end
end
describe 'POST #create' do
describe 'When logged in as Administrator' do
login_fixture_admin
context 'with valid params' do
it 'creates a new Withdraw' do
expect do
post :create, params: valid_create_attributes
end.to change(Withdraw, :count).by(1)
expect(assigns(:withdraw)).to be_persisted
end
it 'assigns a newly created withdraw as @withdraw' do
post :create, params: valid_create_attributes
expect(assigns(:withdraw)).to be_a(Withdraw)
expect(assigns(:withdraw)).to be_persisted
end
it 'redirects to the created withdraw' do
post :create, params: valid_create_attributes
expect(response).to redirect_to(withdraws_path(basket_id: valid_create_attributes[:basket_id]))
end
it 'should not withdraw a checked-out item' do
post :create, params: { basket_id: valid_create_attributes[:basket_id], withdraw: { item_identifier: '00001' } }
expect(assigns(:withdraw)).to be_a(Withdraw)
expect(response).to be_successful
end
end
context 'with invalid params' do
it 'assigns a newly created but unsaved withdraw as @withdraw' do
post :create, params: { basket_id: valid_create_attributes[:basket_id], withdraw: { item_id: nil } }
expect(assigns(:withdraw)).to be_a_new(Withdraw)
end
it "re-renders the 'new' template" do
post :create, params: { basket_id: valid_create_attributes[:basket_id], withdraw: { item_id: nil } }
expect(response).to render_template('index')
end
end
end
end
describe 'DELETE #destroy' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested withdraw' do
withdraw = Withdraw.create! valid_attributes
expect do
delete :destroy, params: { id: withdraw.to_param }
end.to change(Withdraw, :count).by(-1)
end
it 'redirects to the withdraws list' do
withdraw = Withdraw.create! valid_attributes
delete :destroy, params: { id: withdraw.to_param }
expect(response).to redirect_to(withdraws_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/shelves_controller_spec.rb | spec/controllers/shelves_controller_spec.rb | require 'rails_helper'
describe ShelvesController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:shelf)
end
describe 'GET index', solr: true do
before do
Shelf.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all shelves as @shelves' do
get :index
assigns(:shelves).should_not be_empty
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all shelves as @shelves' do
get :index
assigns(:shelves).should_not be_empty
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all shelves as @shelves' do
get :index
assigns(:shelves).should_not be_empty
end
end
describe 'When not logged in' do
it 'assigns all shelves as @shelves' do
get :index
assigns(:shelves).should_not be_empty
response.should be_successful
end
it 'assigns all shelves as @shelves with library_id' do
get :index, params: { library_id: 'kamata' }
assigns(:shelves).map(&:id).should eq(Library.friendly.find('kamata').shelves.order(:position).page(1).pluck(:id))
response.should be_successful
end
it 'assigns all shelves as @shelves with select mode' do
get :index, params: { mode: 'select' }
assigns(:shelves).should eq(Shelf.real.order(:position))
response.should be_successful
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested shelf as @shelf' do
get :show, params: { id: 1 }
assigns(:shelf).should eq(Shelf.find(1))
end
end
describe 'When not logged in' do
it 'assigns the requested shelf as @shelf' do
get :show, params: { id: 1 }
assigns(:shelf).should eq(Shelf.find(1))
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested shelf as @shelf' do
get :new
assigns(:shelf).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested shelf as @shelf' do
get :new
assigns(:shelf).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested shelf as @shelf' do
get :new
assigns(:shelf).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested shelf as @shelf' do
get :new
assigns(:shelf).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested shelf as @shelf' do
shelf = FactoryBot.create(:shelf)
get :edit, params: { id: shelf.id }
assigns(:shelf).should eq(shelf)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested shelf as @shelf' do
shelf = FactoryBot.create(:shelf)
get :edit, params: { id: shelf.id }
assigns(:shelf).should eq(shelf)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested shelf as @shelf' do
shelf = FactoryBot.create(:shelf)
get :edit, params: { id: shelf.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested shelf as @shelf' do
shelf = FactoryBot.create(:shelf)
get :edit, params: { id: shelf.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created shelf as @shelf' do
post :create, params: { shelf: @attrs }
assigns(:shelf).should be_valid
end
it 'redirects to the created patron' do
post :create, params: { shelf: @attrs }
response.should redirect_to(assigns(:shelf))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved shelf as @shelf' do
post :create, params: { shelf: @invalid_attrs }
assigns(:shelf).should_not be_valid
end
it 'should be successful' do
post :create, params: { shelf: @invalid_attrs }
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created shelf as @shelf' do
post :create, params: { shelf: @attrs }
assigns(:shelf).should be_nil
end
it 'should be forbidden' do
post :create, params: { shelf: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved shelf as @shelf' do
post :create, params: { shelf: @invalid_attrs }
assigns(:shelf).should be_nil
end
it 'should be forbidden' do
post :create, params: { shelf: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created shelf as @shelf' do
post :create, params: { shelf: @attrs }
assigns(:shelf).should be_nil
end
it 'should be forbidden' do
post :create, params: { shelf: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved shelf as @shelf' do
post :create, params: { shelf: @invalid_attrs }
assigns(:shelf).should be_nil
end
it 'should be forbidden' do
post :create, params: { shelf: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created shelf as @shelf' do
post :create, params: { shelf: @attrs }
assigns(:shelf).should be_nil
end
it 'should be forbidden' do
post :create, params: { shelf: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved shelf as @shelf' do
post :create, params: { shelf: @invalid_attrs }
assigns(:shelf).should be_nil
end
it 'should be forbidden' do
post :create, params: { shelf: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@shelf = FactoryBot.create(:shelf)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
end
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
assigns(:shelf).should eq(@shelf)
end
it 'moves its position when specified' do
put :update, params: { id: @shelf.id, shelf: @attrs, move: 'lower' }
response.should redirect_to(shelves_url(library_id: @shelf.library_id))
end
end
describe 'with invalid params' do
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
end
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
assigns(:shelf).should eq(@shelf)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
end
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
assigns(:shelf).should eq(@shelf)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested shelf' do
put :update, params: { id: @shelf.id, shelf: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @shelf.id, shelf: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested shelf as @shelf' do
put :update, params: { id: @shelf.id, shelf: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@shelf = FactoryBot.create(:shelf)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested shelf' do
delete :destroy, params: { id: @shelf.id }
end
it 'redirects to the shelves list' do
delete :destroy, params: { id: @shelf.id }
response.should redirect_to(shelves_url)
end
it 'should not destroy a shelf that has id 1' do
delete :destroy, params: { id: 1 }
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested shelf' do
delete :destroy, params: { id: @shelf.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @shelf.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested shelf' do
delete :destroy, params: { id: @shelf.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @shelf.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested shelf' do
delete :destroy, params: { id: @shelf.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @shelf.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/orders_controller_spec.rb | spec/controllers/orders_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe OrdersController do
fixtures :all
disconnect_sunspot
describe 'GET index' do
before(:each) do
FactoryBot.create(:order)
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns all orders as @orders' do
get :index
assigns(:orders).should eq(Order.page(1))
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns all orders as @orders' do
get :index
assigns(:orders).should eq(Order.page(1))
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'should be forbidden' do
get :index
assigns(:orders).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all orders as @orders' do
get :index
assigns(:orders).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :show, params: { id: order.id }
assigns(:order).should eq(order)
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :show, params: { id: order.id }
assigns(:order).should eq(order)
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :show, params: { id: order.id }
assigns(:order).should eq(order)
end
end
describe 'When not logged in' do
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :show, params: { id: order.id }
assigns(:order).should eq(order)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns the requested order as @order' do
get :new, params: { order_list_id: 1, purchase_request_id: 1 }
assigns(:order).should_not be_valid
response.should be_successful
end
it 'should redirect to assigns the requested order as @order' do
get :new, params: { order_list_id: 1, purchase_request_id: 1 }
assigns(:order).should_not be_valid
response.should be_successful
end
it 'assigns the requested order as @order' do
get :new, params: { order_list_id: 1, purchase_request_id: 1 }
assigns(:order).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns the requested order as @order' do
get :new, params: { order_list_id: 1, purchase_request_id: 1 }
assigns(:order).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'should not assign the requested order as @order' do
get :new, params: { order_list_id: 1, purchase_request_id: 1 }
assigns(:order).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested order as @order' do
get :new, params: { order_list_id: 1, purchase_request_id: 1 }
assigns(:order).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :edit, params: { id: order.id }
assigns(:order).should eq(order)
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :edit, params: { id: order.id }
assigns(:order).should eq(order)
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'assigns the requested order as @order' do
order = FactoryBot.create(:order)
get :edit, params: { id: order.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested order as @order' do
order = FactoryBot.create(:order)
get :edit, params: { id: order.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:order)
@invalid_attrs = { order_list_id: '' }
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
describe 'with valid params' do
it 'assigns a newly created order as @order' do
post :create, params: { order: @attrs }
assigns(:order).should be_valid
end
it 'redirects to the created agent' do
post :create, params: { order: @attrs }
response.should redirect_to(assigns(:order))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order as @order' do
post :create, params: { order: @invalid_attrs }
assigns(:order).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { order: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
describe 'with valid params' do
it 'assigns a newly created order as @order' do
post :create, params: { order: @attrs }
assigns(:order).should be_valid
end
it 'redirects to the created agent' do
post :create, params: { order: @attrs }
response.should redirect_to(assigns(:order))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order as @order' do
post :create, params: { order: @invalid_attrs }
assigns(:order).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { order: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
describe 'with valid params' do
it 'assigns a newly created order as @order' do
post :create, params: { order: @attrs }
assigns(:order).should be_nil
end
it 'should be forbidden' do
post :create, params: { order: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order as @order' do
post :create, params: { order: @invalid_attrs }
assigns(:order).should be_nil
end
it 'should be forbidden' do
post :create, params: { order: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created order as @order' do
post :create, params: { order: @attrs }
assigns(:order).should be_nil
end
it 'should be forbidden' do
post :create, params: { order: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order as @order' do
post :create, params: { order: @invalid_attrs }
assigns(:order).should be_nil
end
it 'should be forbidden' do
post :create, params: { order: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@order = FactoryBot.create(:order)
@attrs = FactoryBot.attributes_for(:order)
@invalid_attrs = { order_list_id: '' }
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
describe 'with valid params' do
it 'updates the requested order' do
put :update, params: { id: @order.id, order: @attrs }
end
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @attrs }
assigns(:order).should eq(@order)
response.should redirect_to(@order)
end
end
describe 'with invalid params' do
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
describe 'with valid params' do
it 'updates the requested order' do
put :update, params: { id: @order.id, order: @attrs }
end
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @attrs }
assigns(:order).should eq(@order)
response.should redirect_to(@order)
end
end
describe 'with invalid params' do
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
describe 'with valid params' do
it 'updates the requested order' do
put :update, params: { id: @order.id, order: @attrs }
end
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @attrs }
assigns(:order).should eq(@order)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested order' do
put :update, params: { id: @order.id, order: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @order.id, order: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested order as @order' do
put :update, params: { id: @order.id, order: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@order = FactoryBot.create(:order)
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'destroys the requested order' do
delete :destroy, params: { id: @order.id }
end
it 'redirects to the orders list' do
delete :destroy, params: { id: @order.id }
response.should redirect_to(orders_url)
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'destroys the requested order' do
delete :destroy, params: { id: @order.id }
end
it 'redirects to the orders list' do
delete :destroy, params: { id: @order.id }
response.should redirect_to(orders_url)
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'destroys the requested order' do
delete :destroy, params: { id: @order.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @order.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested order' do
delete :destroy, params: { id: @order.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @order.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/circulation_statuses_controller_spec.rb | spec/controllers/circulation_statuses_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe CirculationStatusesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:circulation_status)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:circulation_status)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all circulation_statuses as @circulation_statuses' do
get :index
assigns(:circulation_statuses).should eq(CirculationStatus.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all circulation_statuses as @circulation_statuses' do
get :index
assigns(:circulation_statuses).should eq(CirculationStatus.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all circulation_statuses as @circulation_statuses' do
get :index
assigns(:circulation_statuses).should eq(CirculationStatus.order(:position))
end
end
describe 'When not logged in' do
it 'assigns all circulation_statuses as @circulation_statuses' do
get :index
assigns(:circulation_statuses).should eq(CirculationStatus.order(:position))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :show, params: { id: circulation_status.id }
assigns(:circulation_status).should eq(circulation_status)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :show, params: { id: circulation_status.id }
assigns(:circulation_status).should eq(circulation_status)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :show, params: { id: circulation_status.id }
assigns(:circulation_status).should eq(circulation_status)
end
end
describe 'When not logged in' do
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :show, params: { id: circulation_status.id }
assigns(:circulation_status).should eq(circulation_status)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'should be forbidden' do
get :new
assigns(:circulation_status).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should be forbidden' do
get :new
assigns(:circulation_status).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should be forbidden' do
get :new
assigns(:circulation_status).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should be redirected' do
get :new
assigns(:circulation_status).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :edit, params: { id: circulation_status.id }
assigns(:circulation_status).should eq(circulation_status)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :edit, params: { id: circulation_status.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :edit, params: { id: circulation_status.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested circulation_status as @circulation_status' do
circulation_status = FactoryBot.create(:circulation_status)
get :edit, params: { id: circulation_status.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created circulation_status as @circulation_status' do
post :create, params: { circulation_status: @attrs }
assigns(:circulation_status).should be_nil
end
it 'redirects to the created patron' do
post :create, params: { circulation_status: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved circulation_status as @circulation_status' do
post :create, params: { circulation_status: @invalid_attrs }
assigns(:circulation_status).should be_nil
end
it 'should be successful' do
post :create, params: { circulation_status: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created circulation_status as @circulation_status' do
post :create, params: { circulation_status: @attrs }
assigns(:circulation_status).should be_nil
end
it 'should be forbidden' do
post :create, params: { circulation_status: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved circulation_status as @circulation_status' do
post :create, params: { circulation_status: @invalid_attrs }
assigns(:circulation_status).should be_nil
end
it 'should be forbidden' do
post :create, params: { circulation_status: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created circulation_status as @circulation_status' do
post :create, params: { circulation_status: @attrs }
assigns(:circulation_status).should be_nil
end
it 'should be forbidden' do
post :create, params: { circulation_status: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved circulation_status as @circulation_status' do
post :create, params: { circulation_status: @invalid_attrs }
assigns(:circulation_status).should be_nil
end
it 'should be forbidden' do
post :create, params: { circulation_status: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created circulation_status as @circulation_status' do
post :create, params: { circulation_status: @attrs }
assigns(:circulation_status).should be_nil
end
it 'should be forbidden' do
post :create, params: { circulation_status: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved circulation_status as @circulation_status' do
post :create, params: { circulation_status: @invalid_attrs }
assigns(:circulation_status).should be_nil
end
it 'should be forbidden' do
post :create, params: { circulation_status: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@circulation_status = FactoryBot.create(:circulation_status)
@attrs = valid_attributes
@invalid_attrs = { display_name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
end
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
assigns(:circulation_status).should eq(@circulation_status)
end
it 'moves its position when specified' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs, move: 'lower' }
response.should redirect_to(circulation_statuses_url)
end
end
describe 'with invalid params' do
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
end
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
assigns(:circulation_status).should eq(@circulation_status)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
end
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
assigns(:circulation_status).should eq(@circulation_status)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @circulation_status.id, circulation_status: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested circulation_status as @circulation_status' do
put :update, params: { id: @circulation_status.id, circulation_status: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@circulation_status = FactoryBot.create(:circulation_status)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested circulation_status' do
delete :destroy, params: { id: @circulation_status.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @circulation_status.id }
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested circulation_status' do
delete :destroy, params: { id: @circulation_status.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @circulation_status.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested circulation_status' do
delete :destroy, params: { id: @circulation_status.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @circulation_status.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested circulation_status' do
delete :destroy, params: { id: @circulation_status.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @circulation_status.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/bookmarks_controller_spec.rb | spec/controllers/bookmarks_controller_spec.rb | require 'rails_helper'
describe BookmarksController do
fixtures :all
describe "GET index", solr: true do
before do
Bookmark.reindex
end
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all bookmarks as @bookmarks" do
get :index
expect(assigns(:bookmarks)).not_to be_empty
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all bookmarks as @bookmarks" do
get :index
expect(assigns(:bookmarks)).not_to be_empty
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns all bookmarks as @bookmarks" do
get :index
expect(assigns(:bookmarks)).not_to be_empty
end
it "should get my bookmark index" do
get :index
expect(response).to be_successful
expect(assigns(:bookmarks)).to eq users(:user1).bookmarks.page(1)
end
it "should redirect to my bookmark index if user_id is specified" do
get :index, params: { user_id: users(:user1).username }
expect(response).to redirect_to bookmarks_url
expect(assigns(:bookmarks)).to be_nil
end
it "should get other user's public bookmark index" do
get :index, params: { user_id: users(:admin).username }
expect(response).to be_successful
expect(assigns(:bookmarks)).to eq users(:admin).bookmarks.page(1)
end
it "should not get other user's private bookmark index" do
sign_in users(:user3)
get :index, params: { user_id: users(:user1).username }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "assigns nil as @bookmarks" do
get :index
expect(assigns(:bookmarks)).to be_nil
end
it "should be redirected to new_user_session_url " do
get :index
expect(response).to redirect_to new_user_session_url
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested bookmark as @bookmark" do
bookmark = FactoryBot.create(:bookmark)
get :show, params: { id: bookmark.id }
expect(assigns(:bookmark)).to eq(bookmark)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested bookmark as @bookmark" do
bookmark = FactoryBot.create(:bookmark)
get :show, params: { id: bookmark.id }
expect(assigns(:bookmark)).to eq(bookmark)
end
it "should shot other user's bookmark" do
get :show, params: { id: 3 }
expect(response).to be_successful
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested bookmark as @bookmark" do
bookmark = FactoryBot.create(:bookmark)
get :show, params: { id: bookmark.id }
expect(assigns(:bookmark)).to eq(bookmark)
end
it "should not show other user's bookmark" do
get :show, params: { id: 1 }
expect(response).to be_forbidden
end
it "should show my bookmark" do
get :show, params: { id: 3 }
expect(response).to be_successful
end
end
describe "When not logged in" do
it "assigns the requested bookmark as @bookmark" do
bookmark = FactoryBot.create(:bookmark)
get :show, params: { id: bookmark.id }
expect(assigns(:bookmark)).to eq(bookmark)
expect(response).to redirect_to new_user_session_url
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested bookmark as @bookmark" do
get :new, params: { bookmark: { title: 'test' } }
expect(assigns(:bookmark)).not_to be_valid
expect(response).to be_successful
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested bookmark as @bookmark" do
get :new, params: { bookmark: { title: 'test' } }
expect(assigns(:bookmark)).not_to be_valid
expect(response).to be_successful
end
end
describe "When logged in as User" do
login_fixture_user
it "should get my new template without url" do
get :new, params: { bookmark: { title: 'test' } }
expect(assigns(:bookmark)).not_to be_valid
expect(response).to be_successful
end
it "should not get new template with url already bookmarked" do
get :new, params: { bookmark: { url: 'http://www.slis.keio.ac.jp/' } }
expect(response).to be_successful
end
it "should get my new template with external url" do
get :new, params: { bookmark: { title: 'example', url: 'http://example.com' } }
expect(response).to be_successful
end
it "should get my new template with internal url" do
get :new, params: { bookmark: { url: "#{LibraryGroup.site_config.url}/manifestations/1" } }
expect(response).to be_successful
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested bookmark as @bookmark" do
get :edit, params: { id: 3 }
expect(assigns(:bookmark)).to eq(Bookmark.find(3))
expect(response).to be_successful
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested bookmark as @bookmark" do
get :edit, params: { id: 3 }
expect(assigns(:bookmark)).to eq(Bookmark.find(3))
expect(response).to be_successful
end
end
describe "When logged in as User" do
login_fixture_user
it "should not edit other user's bookmark" do
get :edit, params: { id: 1 }
expect(response).to be_forbidden
end
it "should edit my bookmark" do
get :edit, params: { id: 3 }
expect(assigns(:bookmark)).to eq(Bookmark.find(3))
expect(response).to be_successful
end
end
describe "When not logged in" do
it "should not assign the requested bookmark as @bookmark" do
get :edit, params: { id: 1 }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
before(:each) do
@bookmark = bookmarks(:bookmark_00001)
@attrs = FactoryBot.attributes_for(:bookmark)
@invalid_attrs = { url: '' }
end
describe "When logged in as User" do
login_fixture_user
# before(:each) do
# @user = FactoryBot.create(:user)
# sign_in @user
# end
it "should create bookmark" do
post :create, params: { bookmark: { title: 'example', url: 'http://www1.example.com/' } }
assigns(:bookmark).save!
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
end
it "should create bookmark with local url" do
post :create, params: { bookmark: { title: 'example', url: "#{LibraryGroup.site_config.url}manifestations/10" } }
expect(assigns(:bookmark)).to be_valid
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
end
it "should create bookmark with tag_list" do
old_tag_count = Tag.count
post :create, params: { bookmark: { tag_list: 'search', title: 'example', url: 'http://example.com/' } }
assigns(:bookmark).tag_list.should eq [ 'search' ]
assigns(:bookmark).taggings.size.should eq 1
Tag.count.should eq old_tag_count + 1
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
end
it "should create bookmark with tag_list include wide space" do
old_tag_count = Tag.count
post :create, params: { bookmark: { tag_list: 'タグの テスト', title: 'example', url: 'http://example.com/' } }
Tag.count.should eq old_tag_count + 2
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
end
it "should not create bookmark without url" do
post :create, params: { bookmark: { title: 'test' } }
expect(assigns(:bookmark)).not_to be_valid
expect(response).to be_successful
end
it "should not create bookmark already bookmarked" do
post :create, params: { bookmark: { user_id: users(:user1).id, url: 'http://www.slis.keio.ac.jp/' } }
expect(assigns(:bookmark)).not_to be_valid
expect(response).to be_successful
end
it "should not create other user's bookmark" do
old_bookmark_counts = users(:user2).bookmarks.count
post :create, params: { bookmark: { user_id: users(:user2).id, title: 'example', url: 'http://example.com/' } }
users(:user2).bookmarks.count.should eq old_bookmark_counts
assigns(:bookmark).user.should eq users(:user1)
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
end
end
describe "When not logged in" do
describe "with valid params" do
it "assigns a newly created bookmark as @bookmark" do
post :create, params: { bookmark: @attrs }
expect(assigns(:bookmark)).to be_nil
end
it "should be forbidden" do
post :create, params: { bookmark: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved bookmark as @bookmark" do
post :create, params: { bookmark: @invalid_attrs }
expect(assigns(:bookmark)).to be_nil
end
it "should be forbidden" do
post :create, params: { bookmark: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe "PUT update" do
before(:each) do
@bookmark = bookmarks(:bookmark_00001)
@attrs = FactoryBot.attributes_for(:bookmark)
@invalid_attrs = { url: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "updates the requested bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
end
it "assigns the requested bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
expect(assigns(:bookmark)).to eq(@bookmark)
expect(response).to redirect_to bookmark_url(@bookmark)
end
end
describe "with invalid params" do
it "assigns the requested bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @bookmark.id, bookmark: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "updates the requested bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
end
it "assigns the requested bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
expect(assigns(:bookmark)).to eq(@bookmark)
expect(response).to redirect_to bookmark_url(@bookmark)
end
end
describe "with invalid params" do
it "assigns the bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @invalid_attrs }
expect(assigns(:bookmark)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @bookmark.id, bookmark: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "updates the requested bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
end
it "assigns the requested bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
expect(assigns(:bookmark)).to eq(@bookmark)
expect(response).to be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @invalid_attrs }
expect(response).to be_forbidden
end
end
it "should update bookmark" do
put :update, params: { id: 3, bookmark: { title: 'test' } }
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
end
it "should add tags to bookmark" do
put :update, params: { id: 3, bookmark: { user_id: users(:user1).id, tag_list: 'search', title: 'test' } }
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
assigns(:bookmark).tag_list.should eq [ 'search' ]
end
it "should remove tags from bookmark" do
put :update, params: { id: 3, bookmark: { user_id: users(:user1).id, tag_list: nil, title: 'test' } }
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
assigns(:bookmark).tag_list.should be_empty
end
it "should not update other user's bookmark" do
put :update, params: { id: 1, bookmark: {} }
expect(response).to be_forbidden
end
it "should not update missing bookmark" do
lambda {
put :update, params: { id: 'missing', bookmark: {} }
}.should raise_error(ActiveRecord::RecordNotFound)
# expect(response).to be_missing
end
it "should update bookmark without manifestation_id" do
put :update, params: { id: 3, bookmark: { manifestation_id: nil } }
expect(assigns(:bookmark)).to be_valid
expect(response).to redirect_to bookmark_url(assigns(:bookmark))
assigns(:bookmark).manifestation.should_not be_nil
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @bookmark.id, bookmark: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested bookmark as @bookmark" do
put :update, params: { id: @bookmark.id, bookmark: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@bookmark = bookmarks(:bookmark_00001)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested bookmark" do
delete :destroy, params: { id: @bookmark.id }
end
it "redirects to the bookmarks list" do
delete :destroy, params: { id: @bookmark.id }
expect(response).to redirect_to bookmarks_url(user_id: @bookmark.user.username)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested bookmark" do
delete :destroy, params: { id: @bookmark.id }
end
it "redirects to the bookmarks list" do
delete :destroy, params: { id: @bookmark.id }
expect(response).to redirect_to bookmarks_url(user_id: @bookmark.user.username)
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested bookmark" do
delete :destroy, params: { id: @bookmark.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @bookmark.id }
expect(response).to be_forbidden
end
it "should destroy my bookmark" do
delete :destroy, params: { id: 3 }
expect(response).to redirect_to bookmarks_url(user_id: users(:user1).username)
end
it "should not destroy other user's bookmark" do
delete :destroy, params: { id: 1 }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested bookmark" do
delete :destroy, params: { id: @bookmark.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @bookmark.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/event_import_results_controller_spec.rb | spec/controllers/event_import_results_controller_spec.rb | require 'rails_helper'
describe EventImportResultsController do
fixtures :all
describe "GET index" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all event_import_results as @event_import_results" do
get :index
assigns(:event_import_results).should eq(EventImportResult.order(created_at: :desc).page(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all event_import_results as @event_import_results" do
get :index
assigns(:event_import_results).should eq(EventImportResult.order(created_at: :desc).page(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns empty as @event_import_results" do
get :index
assigns(:event_import_results).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "assigns empty as @event_import_results" do
get :index
assigns(:event_import_results).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_import_result as @event_import_result" do
get :show, params: { id: 1 }
assigns(:event_import_result).should eq(EventImportResult.find(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event_import_result as @event_import_result" do
get :show, params: { id: 1 }
assigns(:event_import_result).should eq(EventImportResult.find(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event_import_result as @event_import_result" do
get :show, params: { id: 1 }
assigns(:event_import_result).should eq(EventImportResult.find(1))
end
end
describe "When not logged in" do
it "assigns the requested event_import_result as @event_import_result" do
get :show, params: { id: 1 }
assigns(:event_import_result).should eq(EventImportResult.find(1))
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/tags_controller_spec.rb | spec/controllers/tags_controller_spec.rb | require 'rails_helper'
describe TagsController do
fixtures :all
describe "GET index", solr: true do
before do
Tag.reindex
end
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all tags as @tags" do
get :index
expect(assigns(:tags)).not_to be_nil
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all tags as @tags" do
get :index
expect(assigns(:tags)).not_to be_nil
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns all tags as @tags" do
get :index
expect(assigns(:tags)).not_to be_nil
end
end
describe "When not logged in" do
it "assigns all tags as @tags" do
get :index
expect(assigns(:tags)).not_to be_nil
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :show, params: { id: tag.name }
expect(assigns(:tag)).to eq(tag)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :show, params: { id: tag.name }
expect(assigns(:tag)).to eq(tag)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :show, params: { id: tag.name }
expect(assigns(:tag)).to eq(tag)
end
end
describe "When not logged in" do
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :show, params: { id: tag.name }
expect(assigns(:tag)).to eq(tag)
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :edit, params: { id: tag.name }
expect(assigns(:tag)).to eq(tag)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :edit, params: { id: tag.name }
expect(assigns(:tag)).to eq(tag)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :edit, params: { id: tag.name }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested tag as @tag" do
tag = FactoryBot.create(:tag)
get :edit, params: { id: tag.name }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "PUT update" do
before(:each) do
@tag = FactoryBot.create(:tag)
@attrs = FactoryBot.attributes_for(:tag)
@invalid_attrs = { name: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "updates the requested tag" do
put :update, params: { id: @tag.name, tag: @attrs }
end
it "assigns the requested tag as @tag" do
put :update, params: { id: @tag.name, tag: @attrs }
expect(assigns(:tag)).to eq(@tag)
expect(response).to redirect_to(assigns(:tag))
end
end
describe "with invalid params" do
it "assigns the requested tag as @tag" do
put :update, params: { id: @tag.name, tag: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @tag.name, tag: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "updates the requested tag" do
put :update, params: { id: @tag.name, tag: @attrs }
end
it "assigns the requested tag as @tag" do
put :update, params: { id: @tag.name, tag: @attrs }
expect(assigns(:tag)).to eq(@tag)
expect(response).to redirect_to(assigns(:tag))
end
end
describe "with invalid params" do
it "assigns the tag as @tag" do
put :update, params: { id: @tag.name, tag: @invalid_attrs }
expect(assigns(:tag)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @tag.name, tag: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "updates the requested tag" do
put :update, params: { id: @tag.name, tag: @attrs }
end
it "assigns the requested tag as @tag" do
put :update, params: { id: @tag.name, tag: @attrs }
expect(assigns(:tag)).to eq(@tag)
expect(response).to be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested tag as @tag" do
put :update, params: { id: @tag.name, tag: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested tag" do
put :update, params: { id: @tag.name, tag: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @tag.name, tag: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested tag as @tag" do
put :update, params: { id: @tag.name, tag: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@tag = FactoryBot.create(:tag)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested tag" do
delete :destroy, params: { id: @tag.name }
end
it "redirects to the tags list" do
delete :destroy, params: { id: @tag.name }
expect(response).to redirect_to(tags_url)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested tag" do
delete :destroy, params: { id: @tag.name }
end
it "redirects to the tags list" do
delete :destroy, params: { id: @tag.name }
expect(response).to redirect_to(tags_url)
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested tag" do
delete :destroy, params: { id: @tag.name }
end
it "should be forbidden" do
delete :destroy, params: { id: @tag.name }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested tag" do
delete :destroy, params: { id: @tag.name }
end
it "should be forbidden" do
delete :destroy, params: { id: @tag.name }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/user_groups_controller_spec.rb | spec/controllers/user_groups_controller_spec.rb | require 'rails_helper'
describe UserGroupsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:user_group)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:user_group)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all user_groups as @user_groups' do
get :index
assigns(:user_groups).should eq(UserGroup.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all user_groups as @user_groups' do
get :index
assigns(:user_groups).should eq(UserGroup.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all user_groups as @user_groups' do
get :index
assigns(:user_groups).should eq(UserGroup.order(:position))
end
end
describe 'When not logged in' do
it 'assigns all user_groups as @user_groups' do
get :index
assigns(:user_groups).should eq(UserGroup.order(:position))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :show, params: { id: user_group.id }
assigns(:user_group).should eq(user_group)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :show, params: { id: user_group.id }
assigns(:user_group).should eq(user_group)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :show, params: { id: user_group.id }
assigns(:user_group).should eq(user_group)
end
end
describe 'When not logged in' do
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :show, params: { id: user_group.id }
assigns(:user_group).should eq(user_group)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_group as @user_group' do
get :new
assigns(:user_group).should_not be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested user_group as @user_group' do
get :new
assigns(:user_group).should be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested user_group as @user_group' do
get :new
assigns(:user_group).should be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested user_group as @user_group' do
get :new
assigns(:user_group).should be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :edit, params: { id: user_group.id }
assigns(:user_group).should eq(user_group)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :edit, params: { id: user_group.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :edit, params: { id: user_group.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested user_group as @user_group' do
user_group = FactoryBot.create(:user_group)
get :edit, params: { id: user_group.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created user_group as @user_group' do
post :create, params: { user_group: @attrs }
assigns(:user_group).should be_valid
end
it 'redirects to the created patron' do
post :create, params: { user_group: @attrs }
expect(response).to redirect_to(assigns(:user_group))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group as @user_group' do
post :create, params: { user_group: @invalid_attrs }
assigns(:user_group).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { user_group: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created user_group as @user_group' do
post :create, params: { user_group: @attrs }
assigns(:user_group).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group as @user_group' do
post :create, params: { user_group: @invalid_attrs }
assigns(:user_group).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created user_group as @user_group' do
post :create, params: { user_group: @attrs }
assigns(:user_group).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group as @user_group' do
post :create, params: { user_group: @invalid_attrs }
assigns(:user_group).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created user_group as @user_group' do
post :create, params: { user_group: @attrs }
assigns(:user_group).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group as @user_group' do
post :create, params: { user_group: @invalid_attrs }
assigns(:user_group).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@user_group = FactoryBot.create(:user_group)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
end
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
assigns(:user_group).should eq(@user_group)
end
it 'moves its position when specified' do
put :update, params: { id: @user_group.id, user_group: @attrs, move: 'lower' }
expect(response).to redirect_to(user_groups_url)
end
end
describe 'with invalid params' do
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
end
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
assigns(:user_group).should eq(@user_group)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
end
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
assigns(:user_group).should eq(@user_group)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested user_group' do
put :update, params: { id: @user_group.id, user_group: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @user_group.id, user_group: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested user_group as @user_group' do
put :update, params: { id: @user_group.id, user_group: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@user_group = FactoryBot.create(:user_group)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested user_group' do
delete :destroy, params: { id: @user_group.id }
end
it 'redirects to the user_groups list' do
delete :destroy, params: { id: @user_group.id }
expect(response).to redirect_to(user_groups_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested user_group' do
delete :destroy, params: { id: @user_group.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_group.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested user_group' do
delete :destroy, params: { id: @user_group.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_group.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested user_group' do
delete :destroy, params: { id: @user_group.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_group.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/event_categories_controller_spec.rb | spec/controllers/event_categories_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe EventCategoriesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:event_category)
end
describe "GET index" do
before(:each) do
FactoryBot.create(:event_category)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all event_categories as @event_categories" do
get :index
assigns(:event_categories).should eq(EventCategory.order(:position))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all event_categories as @event_categories" do
get :index
assigns(:event_categories).should eq(EventCategory.order(:position))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns all event_categories as @event_categories" do
get :index
assigns(:event_categories).should eq(EventCategory.order(:position))
end
end
describe "When not logged in" do
it "assigns all event_categories as @event_categories" do
get :index
assigns(:event_categories).should eq(EventCategory.order(:position))
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :show, params: { id: event_category.id }
assigns(:event_category).should eq(event_category)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :show, params: { id: event_category.id }
assigns(:event_category).should eq(event_category)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :show, params: { id: event_category.id }
assigns(:event_category).should eq(event_category)
end
end
describe "When not logged in" do
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :show, params: { id: event_category.id }
assigns(:event_category).should eq(event_category)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_category as @event_category" do
get :new
assigns(:event_category).should_not be_valid
response.should be_successful
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "should not assign the requested event_category as @event_category" do
get :new
assigns(:event_category).should be_nil
response.should be_forbidden
end
end
describe "When logged in as User" do
login_fixture_user
it "should not assign the requested event_category as @event_category" do
get :new
assigns(:event_category).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested event_category as @event_category" do
get :new
assigns(:event_category).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :edit, params: { id: event_category.id }
assigns(:event_category).should eq(event_category)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :edit, params: { id: event_category.id }
response.should be_forbidden
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :edit, params: { id: event_category.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested event_category as @event_category" do
event_category = FactoryBot.create(:event_category)
get :edit, params: { id: event_category.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "assigns a newly created event_category as @event_category" do
post :create, params: { event_category: @attrs }
assigns(:event_category).should be_valid
end
it "redirects to the created patron" do
post :create, params: { event_category: @attrs }
response.should redirect_to(assigns(:event_category))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event_category as @event_category" do
post :create, params: { event_category: @invalid_attrs }
assigns(:event_category).should_not be_valid
end
it "should be successful" do
post :create, params: { event_category: @invalid_attrs }
response.should be_successful
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "assigns a newly created event_category as @event_category" do
post :create, params: { event_category: @attrs }
assigns(:event_category).should be_nil
end
it "should be forbidden" do
post :create, params: { event_category: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event_category as @event_category" do
post :create, params: { event_category: @invalid_attrs }
assigns(:event_category).should be_nil
end
it "should be forbidden" do
post :create, params: { event_category: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "assigns a newly created event_category as @event_category" do
post :create, params: { event_category: @attrs }
assigns(:event_category).should be_nil
end
it "should be forbidden" do
post :create, params: { event_category: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event_category as @event_category" do
post :create, params: { event_category: @invalid_attrs }
assigns(:event_category).should be_nil
end
it "should be forbidden" do
post :create, params: { event_category: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "assigns a newly created event_category as @event_category" do
post :create, params: { event_category: @attrs }
assigns(:event_category).should be_nil
end
it "should be forbidden" do
post :create, params: { event_category: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event_category as @event_category" do
post :create, params: { event_category: @invalid_attrs }
assigns(:event_category).should be_nil
end
it "should be forbidden" do
post :create, params: { event_category: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "PUT update" do
before(:each) do
@event_category = FactoryBot.create(:event_category)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "updates the requested event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
end
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
assigns(:event_category).should eq(@event_category)
end
it "moves its position when specified" do
put :update, params: { id: @event_category.id, event_category: @attrs, move: 'lower' }
response.should redirect_to(event_categories_url)
end
end
describe "with invalid params" do
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @invalid_attrs }
response.should render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "updates the requested event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
end
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
assigns(:event_category).should eq(@event_category)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "updates the requested event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
end
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
assigns(:event_category).should eq(@event_category)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested event_category" do
put :update, params: { id: @event_category.id, event_category: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @event_category.id, event_category: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested event_category as @event_category" do
put :update, params: { id: @event_category.id, event_category: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@event_category = FactoryBot.create(:event_category)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested event_category" do
delete :destroy, params: { id: @event_category.id }
end
it "redirects to the event_categories list" do
delete :destroy, params: { id: @event_category.id }
response.should redirect_to(event_categories_url)
end
it "should not destroy event_category that has events" do
event_category = EventCategory.first
delete :destroy, params: { id: event_category.id }
response.should be_forbidden
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested event_category" do
delete :destroy, params: { id: @event_category.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event_category.id }
response.should be_forbidden
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested event_category" do
delete :destroy, params: { id: @event_category.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event_category.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested event_category" do
delete :destroy, params: { id: @event_category.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event_category.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agents_controller_spec.rb | spec/controllers/agents_controller_spec.rb | require 'rails_helper'
describe AgentsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:agent)
end
describe 'GET index', solr: true do
before do
Agent.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all agents as @agents' do
get :index
expect(assigns(:agents)).not_to be_empty
end
it 'should get index with agent_id' do
get :index, params: { agent_id: 1 }
expect(response).to be_successful
expect(assigns(:agent)).to eq Agent.find(1)
expect(assigns(:agents)).to eq assigns(:agent).derived_agents.where('required_role_id >= 1').page(1)
end
it 'should get index with query' do
get :index, params: { query: 'Librarian1' }
expect(assigns(:agents)).not_to be_empty
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all agents as @agents' do
get :index
expect(assigns(:agents)).not_to be_empty
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all agents as @agents' do
get :index
expect(assigns(:agents)).not_to be_empty
end
end
describe 'When not logged in' do
it 'assigns all agents as @agents' do
get :index
expect(assigns(:agents)).not_to be_empty
end
it 'assigns all agents as @agents in rss format' do
get :index, format: :rss
expect(assigns(:agents)).not_to be_empty
end
it 'assigns all agents as @agents in atom format' do
get :index, format: :atom
expect(assigns(:agents)).not_to be_empty
end
it 'should get index with agent_id' do
get :index, params: { agent_id: 1 }
expect(response).to be_successful
expect(assigns(:agent)).to eq Agent.find(1)
expect(assigns(:agents)).to eq assigns(:agent).derived_agents.where(required_role_id: 1).page(1)
end
it 'should get index with manifestation_id' do
get :index, params: { manifestation_id: 1 }
assigns(:manifestation).should eq Manifestation.find(1)
expect(assigns(:agents)).to eq assigns(:manifestation).publishers.where(required_role_id: 1).page(1)
end
it 'should get index with query' do
get :index, params: { query: 'Librarian1' }
expect(assigns(:agents)).to be_empty
expect(response).to be_successful
end
end
end
describe 'GET show' do
before(:each) do
@agent = FactoryBot.create(:agent)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent as @agent' do
get :show, params: { id: @agent.id }
expect(assigns(:agent)).to eq(@agent)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent as @agent' do
get :show, params: { id: @agent.id }
expect(assigns(:agent)).to eq(@agent)
end
# it "should show agent when required_role is user" do
# get :show, :id => users(:user2).agent.id
# expect(assigns(:agent)).to eq(users(:user2).agent)
# expect(response).to be_successful
# end
# it "should show patron when required_role is librarian" do
# get :show, :id => users(:user1).agent.id
# expect(assigns(:agent)).to eq(users(:user1).agent)
# expect(response).to be_successful
# end
it 'should not show agent who does not create a work' do
lambda do
get :show, params: { id: 3, work_id: 3 }
end.should raise_error(ActiveRecord::RecordNotFound)
# expect(response).to be_missing
end
it 'should not show agent who does not produce a manifestation' do
lambda do
get :show, params: { id: 4, manifestation_id: 4 }
end.should raise_error(ActiveRecord::RecordNotFound)
# expect(response).to be_missing
end
# it "should not show agent when required_role is 'Administrator'" do
# sign_in users(:librarian2)
# get :show, :id => users(:librarian1).agent.id
# expect(response).to be_forbidden
# end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent as @agent' do
get :show, params: { id: @agent.id }
expect(assigns(:agent)).to eq(@agent)
end
# it "should show user" do
# get :show, :id => users(:user2).agent.id
# assigns(:agent).required_role.name.should eq 'User'
# expect(response).to be_successful
# end
# it "should not show agent when required_role is 'Librarian'" do
# sign_in users(:user2)
# get :show, :id => users(:user1).agent.id
# expect(response).to be_forbidden
# end
end
describe 'When not logged in' do
it 'assigns the requested agent as @agent' do
get :show, params: { id: @agent.id }
expect(assigns(:agent)).to eq(@agent)
end
it 'should show agent with work' do
get :show, params: { id: 1, work_id: 1 }
expect(assigns(:agent)).to eq assigns(:work).creators.first
end
it 'should show agent with manifestation' do
get :show, params: { id: 1, manifestation_id: 1 }
expect(assigns(:agent)).to eq assigns(:manifestation).publishers.first
end
it "should not show agent when required_role is 'User'" do
get :show, params: { id: 5 }
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent as @agent' do
get :new
expect(assigns(:agent)).not_to be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent as @agent' do
get :new
expect(assigns(:agent)).not_to be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested agent as @agent' do
get :new
expect(assigns(:agent)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent as @agent' do
get :new
expect(assigns(:agent)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent as @agent' do
agent = Agent.find(1)
get :edit, params: { id: agent.id }
expect(assigns(:agent)).to eq(agent)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent as @agent' do
agent = Agent.find(1)
get :edit, params: { id: agent.id }
expect(assigns(:agent)).to eq(agent)
end
# it "should edit agent when its required_role is 'User'" do
# get :edit, :id => users(:user2).agent.id
# expect(response).to be_successful
# end
# it "should edit agent when its required_role is 'Librarian'" do
# get :edit, :id => users(:user1).agent.id
# expect(response).to be_successful
# end
# it "should edit admin" do
# get :edit, :id => users(:admin).agent.id
# expect(response).to be_forbidden
# end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent as @agent' do
agent = Agent.find(1)
get :edit, params: { id: agent.id }
expect(response).to be_forbidden
end
# it "should edit myself" do
# get :edit, :id => users(:user1).agent.id
# expect(response).to be_successful
# end
# it "should not edit other user's agent profile" do
# get :edit, :id => users(:user2).agent.id
# expect(response).to be_forbidden
# end
end
describe 'When not logged in' do
it 'should not assign the requested agent as @agent' do
agent = Agent.find(1)
get :edit, params: { id: agent.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = FactoryBot.attributes_for(:agent, full_name: '')
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created agent as @agent' do
post :create, params: { agent: @attrs }
expect(assigns(:agent)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent: @attrs }
expect(response).to redirect_to(agent_url(assigns(:agent)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent as @agent' do
post :create, params: { agent: @invalid_attrs }
expect(assigns(:agent)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created agent as @agent' do
post :create, params: { agent: @attrs }
expect(assigns(:agent)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent: @attrs }
expect(response).to redirect_to(agent_url(assigns(:agent)))
end
it 'should create a relationship if work_id is set' do
post :create, params: { agent: @attrs, work_id: 1 }
expect(response).to redirect_to(agent_url(assigns(:agent)))
assigns(:agent).works.should eq [ Manifestation.find(1) ]
end
it 'should create a relationship if manifestation_id is set' do
post :create, params: { agent: @attrs, manifestation_id: 1 }
expect(response).to redirect_to(agent_url(assigns(:agent)))
assigns(:agent).manifestations.should eq [ Manifestation.find(1) ]
end
it 'should create a relationship if item_id is set' do
post :create, params: { agent: @attrs, item_id: 1 }
expect(response).to redirect_to(agent_url(assigns(:agent)))
assigns(:agent).items.should eq [ Item.find(1) ]
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent as @agent' do
post :create, params: { agent: @invalid_attrs }
expect(assigns(:agent)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent: @invalid_attrs }
expect(response).to render_template('new')
end
end
# TODO: full_name以外での判断
it 'should create agent without full_name' do
post :create, params: { agent: { first_name: 'test' } }
expect(response).to redirect_to agent_url(assigns(:agent))
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created agent as @agent' do
post :create, params: { agent: @attrs }
expect(assigns(:agent)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent as @agent' do
post :create, params: { agent: @invalid_attrs }
expect(assigns(:agent)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent: @invalid_attrs }
expect(response).to be_forbidden
end
end
# it "should not create agent myself" do
# post :create, :agent => { :full_name => 'test', :user_username => users(:user1).username }
# expect(assigns(:agent)).not_to be_valid
# expect(response).to be_successful
# end
# it "should not create other agent" do
# post :create, :agent => { :full_name => 'test', :user_id => users(:user2).username }
# expect(response).to be_forbidden
# end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created agent as @agent' do
post :create, params: { agent: @attrs }
expect(assigns(:agent)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent as @agent' do
post :create, params: { agent: @invalid_attrs }
expect(assigns(:agent)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@agent = FactoryBot.create(:agent)
@attrs = valid_attributes
@invalid_attrs = FactoryBot.attributes_for(:agent, full_name: '')
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested agent' do
put :update, params: { id: @agent.id, agent: @attrs }
end
it 'assigns the requested agent as @agent' do
put :update, params: { id: @agent.id, agent: @attrs }
expect(assigns(:agent)).to eq(@agent)
end
end
describe 'with invalid params' do
it 'assigns the requested agent as @agent' do
put :update, params: { id: @agent.id, agent: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested agent' do
put :update, params: { id: @agent.id, agent: @attrs }
end
it 'assigns the requested agent as @agent' do
put :update, params: { id: @agent.id, agent: @attrs }
expect(assigns(:agent)).to eq(@agent)
expect(response).to redirect_to(@agent)
end
end
describe 'with invalid params' do
it 'assigns the agent as @agent' do
put :update, params: { id: @agent, agent: @invalid_attrs }
expect(assigns(:agent)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @agent, agent: @invalid_attrs }
expect(response).to render_template('edit')
end
end
# it "should update other agent" do
# put :update, :id => users(:user2).agent.id, :agent => { :full_name => 'test' }
# expect(response).to redirect_to agent_url(assigns(:agent))
# end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested agent' do
put :update, params: { id: @agent.id, agent: @attrs }
end
it 'assigns the requested agent as @agent' do
put :update, params: { id: @agent.id, agent: @attrs }
expect(assigns(:agent)).to eq(@agent)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested agent as @agent' do
put :update, params: { id: @agent.id, agent: @invalid_attrs }
expect(response).to be_forbidden
end
end
# it "should update myself" do
# put :update, :id => users(:user1).agent.id, :agent => { :full_name => 'test' }
# expect(assigns(:agent)).to be_valid
# expect(response).to redirect_to agent_url(assigns(:agent))
# end
# it "should not update myself without name" do
# put :update, :id => users(:user1).agent.id, :agent => { :first_name => '', :last_name => '', :full_name => '' }
# expect(assigns(:agent)).not_to be_valid
# expect(response).to be_successful
# end
# it "should not update other agent" do
# put :update, :id => users(:user2).agent.id, :agent => { :full_name => 'test' }
# expect(response).to be_forbidden
# end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested agent' do
put :update, params: { id: @agent.id, agent: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @agent.id, agent: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested agent as @agent' do
put :update, params: { id: @agent.id, agent: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@agent = FactoryBot.create(:agent)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested agent' do
delete :destroy, params: { id: @agent.id }
end
it 'redirects to the agents list' do
delete :destroy, params: { id: @agent.id }
expect(response).to redirect_to(agents_url)
end
# it "should not destroy librarian who has items checked out" do
# delete :destroy, :id => users(:librarian1).agent.id
# expect(response).to be_forbidden
# end
# it "should destroy librarian who does not have items checked out" do
# delete :destroy, :id => users(:librarian2).agent.id
# expect(response).to redirect_to agents_url
# end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested agent' do
delete :destroy, params: { id: @agent.id }
end
it 'redirects to the agents list' do
delete :destroy, params: { id: @agent.id }
expect(response).to redirect_to(agents_url)
end
# it "should not destroy librarian" do
# delete :destroy, :id => users(:librarian2).agent.id
# expect(response).to be_forbidden
# end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested agent' do
delete :destroy, params: { id: @agent.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent.id }
expect(response).to be_forbidden
end
# it "should not destroy agent" do
# delete :destroy, :id => users(:user1).agent.id
# expect(response).to be_forbidden
# end
end
describe 'When not logged in' do
it 'destroys the requested agent' do
delete :destroy, params: { id: @agent.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/owns_controller_spec.rb | spec/controllers/owns_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe OwnsController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:own)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:own)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all owns as @owns' do
get :index
expect(assigns(:owns)).to eq(Own.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all owns as @owns' do
get :index
expect(assigns(:owns)).to eq(Own.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all owns as @owns' do
get :index
expect(assigns(:owns)).to eq(Own.page(1))
end
end
describe 'When not logged in' do
it 'assigns all owns as @owns' do
get :index
expect(assigns(:owns)).to eq(Own.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :show, params: { id: own.id }
expect(assigns(:own)).to eq(own)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :show, params: { id: own.id }
expect(assigns(:own)).to eq(own)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :show, params: { id: own.id }
expect(assigns(:own)).to eq(own)
end
end
describe 'When not logged in' do
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :show, params: { id: own.id }
expect(assigns(:own)).to eq(own)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested own as @own' do
get :new
expect(assigns(:own)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested own as @own' do
get :new
expect(assigns(:own)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested own as @own' do
get :new
expect(assigns(:own)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested own as @own' do
get :new
expect(assigns(:own)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :edit, params: { id: own.id }
expect(assigns(:own)).to eq(own)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :edit, params: { id: own.id }
expect(assigns(:own)).to eq(own)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested own as @own' do
own = FactoryBot.create(:own)
get :edit, params: { id: own.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested own as @own' do
own = FactoryBot.create(:own)
get :edit, params: { id: own.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { item_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created own as @own' do
post :create, params: { own: @attrs }
expect(assigns(:own)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { own: @attrs }
expect(response).to redirect_to(assigns(:own))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved own as @own' do
post :create, params: { own: @invalid_attrs }
expect(assigns(:own)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { own: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created own as @own' do
post :create, params: { own: @attrs }
expect(assigns(:own)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { own: @attrs }
expect(response).to redirect_to(assigns(:own))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved own as @own' do
post :create, params: { own: @invalid_attrs }
expect(assigns(:own)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { own: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created own as @own' do
post :create, params: { own: @attrs }
expect(assigns(:own)).to be_nil
end
it 'should be forbidden' do
post :create, params: { own: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved own as @own' do
post :create, params: { own: @invalid_attrs }
expect(assigns(:own)).to be_nil
end
it 'should be forbidden' do
post :create, params: { own: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created own as @own' do
post :create, params: { own: @attrs }
expect(assigns(:own)).to be_nil
end
it 'should be forbidden' do
post :create, params: { own: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved own as @own' do
post :create, params: { own: @invalid_attrs }
expect(assigns(:own)).to be_nil
end
it 'should be forbidden' do
post :create, params: { own: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@own = FactoryBot.create(:own)
@attrs = valid_attributes
@invalid_attrs = { item_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested own' do
put :update, params: { id: @own.id, own: @attrs }
end
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @attrs }
expect(assigns(:own)).to eq(@own)
expect(response).to redirect_to(@own)
end
it 'moves its position when specified' do
put :update, params: { id: @own.id, own: @attrs, item_id: @own.item.id, move: 'lower' }
expect(response).to redirect_to(owns_url(item_id: @own.item_id))
end
end
describe 'with invalid params' do
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested own' do
put :update, params: { id: @own.id, own: @attrs }
end
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @attrs }
expect(assigns(:own)).to eq(@own)
expect(response).to redirect_to(@own)
end
end
describe 'with invalid params' do
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested own' do
put :update, params: { id: @own.id, own: @attrs }
end
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @attrs }
expect(assigns(:own)).to eq(@own)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested own' do
put :update, params: { id: @own.id, own: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @own.id, own: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested own as @own' do
put :update, params: { id: @own.id, own: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@own = FactoryBot.create(:own)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested own' do
delete :destroy, params: { id: @own.id }
end
it 'redirects to the owns list' do
delete :destroy, params: { id: @own.id }
expect(response).to redirect_to(owns_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested own' do
delete :destroy, params: { id: @own.id }
end
it 'redirects to the owns list' do
delete :destroy, params: { id: @own.id }
expect(response).to redirect_to(owns_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested own' do
delete :destroy, params: { id: @own.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @own.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested own' do
delete :destroy, params: { id: @own.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @own.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/order_lists_controller_spec.rb | spec/controllers/order_lists_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe OrderListsController do
disconnect_sunspot
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns all order_lists as @order_lists' do
get :index
assigns(:order_lists).should eq(OrderList.page(1))
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns all order_lists as @order_lists' do
get :index
assigns(:order_lists).should eq(OrderList.page(1))
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'assigns empty as @order_lists' do
get :index
assigns(:order_lists).should be_nil
end
end
describe 'When not logged in' do
it 'assigns empty as @order_lists' do
get :index
assigns(:order_lists).should be_nil
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :show, params: { id: order_list.id }
assigns(:order_list).should eq(order_list)
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :show, params: { id: order_list.id }
assigns(:order_list).should eq(order_list)
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :show, params: { id: order_list.id }
assigns(:order_list).should eq(order_list)
end
end
describe 'When not logged in' do
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :show, params: { id: order_list.id }
assigns(:order_list).should eq(order_list)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns the requested order_list as @order_list' do
get :new
response.should be_successful
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns the requested order_list as @order_list' do
get :new
response.should be_successful
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'should not assign the requested order_list as @order_list' do
get :new
assigns(:order_list).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested order_list as @order_list' do
get :new
assigns(:order_list).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :edit, params: { id: order_list.id }
assigns(:order_list).should eq(order_list)
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :edit, params: { id: order_list.id }
assigns(:order_list).should eq(order_list)
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'assigns the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :edit, params: { id: order_list.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested order_list as @order_list' do
order_list = FactoryBot.create(:order_list)
get :edit, params: { id: order_list.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:order_list)
@invalid_attrs = { bookstore_id: '' }
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
describe 'with valid params' do
it 'assigns a newly created order_list as @order_list' do
post :create, params: { order_list: @attrs }
assigns(:order_list).should be_valid
end
it 'redirects to the created order_list' do
post :create, params: { order_list: @attrs }
response.should redirect_to(order_list_url(assigns(:order_list)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order_list as @order_list' do
post :create, params: { order_list: @invalid_attrs }
assigns(:order_list).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { order_list: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
describe 'with valid params' do
it 'assigns a newly created order_list as @order_list' do
post :create, params: { order_list: @attrs }
assigns(:order_list).should be_valid
end
it 'redirects to the created order_list' do
post :create, params: { order_list: @attrs }
response.should redirect_to(order_list_url(assigns(:order_list)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order_list as @order_list' do
post :create, params: { order_list: @invalid_attrs }
assigns(:order_list).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { order_list: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
describe 'with valid params' do
it 'assigns a newly created order_list as @order_list' do
post :create, params: { order_list: @attrs }
assigns(:order_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { order_list: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order_list as @order_list' do
post :create, params: { order_list: @invalid_attrs }
assigns(:order_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { order_list: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created order_list as @order_list' do
post :create, params: { order_list: @attrs }
assigns(:order_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { order_list: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved order_list as @order_list' do
post :create, params: { order_list: @invalid_attrs }
assigns(:order_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { order_list: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@order_list = FactoryBot.create(:order_list)
@attrs = FactoryBot.attributes_for(:order_list)
@invalid_attrs = { bookstore_id: '' }
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
describe 'with valid params' do
it 'updates the requested order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
end
it 'assigns the requested order_list as @order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
assigns(:order_list).should eq(@order_list)
end
end
describe 'with invalid params' do
it 'assigns the requested order_list as @order_list' do
put :update, params: { id: @order_list.id, order_list: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
describe 'with valid params' do
it 'updates the requested order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
end
it 'assigns the requested order_list as @order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
assigns(:order_list).should eq(@order_list)
response.should redirect_to(@order_list)
end
end
describe 'with invalid params' do
it 'assigns the order_list as @order_list' do
put :update, params: { id: @order_list, order_list: @invalid_attrs }
assigns(:order_list).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @order_list, order_list: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
describe 'with valid params' do
it 'updates the requested order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
end
it 'assigns the requested order_list as @order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
assigns(:order_list).should eq(@order_list)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested order_list as @order_list' do
put :update, params: { id: @order_list.id, order_list: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested order_list' do
put :update, params: { id: @order_list.id, order_list: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @order_list.id, order_list: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested order_list as @order_list' do
put :update, params: { id: @order_list.id, order_list: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@order_list = FactoryBot.create(:order_list)
end
describe 'When logged in as Administrator' do
before(:each) do
sign_in FactoryBot.create(:admin)
end
it 'destroys the requested order_list' do
delete :destroy, params: { id: @order_list.id }
end
it 'redirects to the order_lists list' do
delete :destroy, params: { id: @order_list.id }
response.should redirect_to(order_lists_url)
end
end
describe 'When logged in as Librarian' do
before(:each) do
sign_in FactoryBot.create(:librarian)
end
it 'destroys the requested order_list' do
delete :destroy, params: { id: @order_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @order_list.id }
response.should redirect_to(order_lists_url)
end
end
describe 'When logged in as User' do
before(:each) do
sign_in FactoryBot.create(:user)
end
it 'destroys the requested order_list' do
delete :destroy, params: { id: @order_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @order_list.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested order_list' do
delete :destroy, params: { id: @order_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @order_list.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/subscribes_controller_spec.rb | spec/controllers/subscribes_controller_spec.rb | require 'rails_helper'
describe SubscribesController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:subscribe)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:subscribe)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all subscribes as @subscribes' do
get :index
assigns(:subscribes).should eq(Subscribe.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all subscribes as @subscribes' do
get :index
assigns(:subscribes).should eq(Subscribe.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should be forbidden' do
get :index
assigns(:subscribes).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all subscribes as @subscribes' do
get :index
assigns(:subscribes).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :show, params: { id: subscribe.id }
assigns(:subscribe).should eq(subscribe)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :show, params: { id: subscribe.id }
assigns(:subscribe).should eq(subscribe)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :show, params: { id: subscribe.id }
assigns(:subscribe).should eq(subscribe)
end
end
describe 'When not logged in' do
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :show, params: { id: subscribe.id }
assigns(:subscribe).should eq(subscribe)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested subscribe as @subscribe' do
get :new
assigns(:subscribe).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested subscribe as @subscribe' do
get :new
assigns(:subscribe).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested subscribe as @subscribe' do
get :new
assigns(:subscribe).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subscribe as @subscribe' do
get :new
assigns(:subscribe).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :edit, params: { id: subscribe.id }
assigns(:subscribe).should eq(subscribe)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :edit, params: { id: subscribe.id }
assigns(:subscribe).should eq(subscribe)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :edit, params: { id: subscribe.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subscribe as @subscribe' do
subscribe = FactoryBot.create(:subscribe)
get :edit, params: { id: subscribe.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { work_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created subscribe as @subscribe' do
post :create, params: { subscribe: @attrs }
assigns(:subscribe).should be_valid
end
it 'redirects to the created agent' do
post :create, params: { subscribe: @attrs }
response.should redirect_to(assigns(:subscribe))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscribe as @subscribe' do
post :create, params: { subscribe: @invalid_attrs }
assigns(:subscribe).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { subscribe: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created subscribe as @subscribe' do
post :create, params: { subscribe: @attrs }
assigns(:subscribe).should be_valid
end
it 'redirects to the created agent' do
post :create, params: { subscribe: @attrs }
response.should redirect_to(assigns(:subscribe))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscribe as @subscribe' do
post :create, params: { subscribe: @invalid_attrs }
assigns(:subscribe).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { subscribe: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created subscribe as @subscribe' do
post :create, params: { subscribe: @attrs }
assigns(:subscribe).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscribe: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscribe as @subscribe' do
post :create, params: { subscribe: @invalid_attrs }
assigns(:subscribe).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscribe: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created subscribe as @subscribe' do
post :create, params: { subscribe: @attrs }
assigns(:subscribe).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscribe: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscribe as @subscribe' do
post :create, params: { subscribe: @invalid_attrs }
assigns(:subscribe).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscribe: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@subscribe = FactoryBot.create(:subscribe)
@attrs = valid_attributes
@invalid_attrs = { work_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
end
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
assigns(:subscribe).should eq(@subscribe)
response.should redirect_to(@subscribe)
end
end
describe 'with invalid params' do
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
end
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
assigns(:subscribe).should eq(@subscribe)
response.should redirect_to(@subscribe)
end
end
describe 'with invalid params' do
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
end
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
assigns(:subscribe).should eq(@subscribe)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @subscribe.id, subscribe: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested subscribe as @subscribe' do
put :update, params: { id: @subscribe.id, subscribe: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@subscribe = FactoryBot.create(:subscribe)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested subscribe' do
delete :destroy, params: { id: @subscribe.id }
end
it 'redirects to the subscribes list' do
delete :destroy, params: { id: @subscribe.id }
response.should redirect_to(subscribes_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested subscribe' do
delete :destroy, params: { id: @subscribe.id }
end
it 'redirects to the subscribes list' do
delete :destroy, params: { id: @subscribe.id }
response.should redirect_to(subscribes_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested subscribe' do
delete :destroy, params: { id: @subscribe.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subscribe.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested subscribe' do
delete :destroy, params: { id: @subscribe.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subscribe.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/news_posts_controller_spec.rb | spec/controllers/news_posts_controller_spec.rb | require 'rails_helper'
describe NewsPostsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:news_post)
end
describe "GET index" do
before(:each) do
FactoryBot.create(:news_post)
end
describe "When logged in as Administrator" do
login_admin
it "assigns all news_posts as @news_posts" do
get :index
assigns(:news_posts).should eq(NewsPost.page(1))
end
end
describe "When logged in as Librarian" do
login_librarian
it "assigns all news_posts as @news_posts" do
get :index
assigns(:news_posts).should eq(NewsPost.page(1))
end
end
describe "When logged in as User" do
login_user
it "assigns all news_posts as @news_posts" do
get :index
assigns(:news_posts).should eq(NewsPost.published.page(1))
end
end
describe "When not logged in" do
it "assigns all news_posts as @news_posts" do
get :index
assigns(:news_posts).should eq(NewsPost.published.page(1))
end
end
end
describe "GET show" do
before(:each) do
@news_post = FactoryBot.create(:news_post)
end
describe "When logged in as Administrator" do
login_admin
it "assigns the requested news_post as @news_post" do
get :show, params: { id: @news_post.id }
assigns(:news_post).should eq(@news_post)
end
end
describe "When logged in as Librarian" do
login_librarian
it "assigns the requested news_post as @news_post" do
get :show, params: { id: @news_post.id }
assigns(:news_post).should eq(@news_post)
end
end
describe "When logged in as User" do
login_user
it "assigns the requested news_post as @news_post" do
get :show, params: { id: @news_post.id }
assigns(:news_post).should eq(@news_post)
end
end
describe "When not logged in" do
it "assigns the requested news_post as @news_post" do
get :show, params: { id: @news_post.id }
assigns(:news_post).should eq(@news_post)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_admin
it "assigns the requested news_post as @news_post" do
get :new
assigns(:news_post).should_not be_valid
response.should be_successful
end
end
describe "When logged in as Librarian" do
login_librarian
it "should not assign the requested news_post as @news_post" do
get :new
assigns(:news_post).should be_nil
response.should be_forbidden
end
end
describe "When logged in as User" do
login_user
it "should not assign the requested news_post as @news_post" do
get :new
assigns(:news_post).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested news_post as @news_post" do
get :new
assigns(:news_post).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET edit" do
before(:each) do
@news_post = FactoryBot.create(:news_post)
end
describe "When logged in as Administrator" do
login_admin
it "assigns the requested news_post as @news_post" do
get :edit, params: { id: @news_post.id }
assigns(:news_post).should eq(@news_post)
end
end
describe "When logged in as Librarian" do
login_librarian
it "assigns the requested news_post as @news_post" do
get :edit, params: { id: @news_post.id }
response.should be_forbidden
end
end
describe "When logged in as User" do
login_user
it "assigns the requested news_post as @news_post" do
get :edit, params: { id: @news_post.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested news_post as @news_post" do
get :edit, params: { id: @news_post.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { body: '' }
end
describe "When logged in as Administrator" do
login_admin
describe "with valid params" do
it "assigns a newly created news_post as @news_post" do
post :create, params: { news_post: @attrs }
assigns(:news_post).should be_valid
end
it "redirects to the created news_post" do
post :create, params: { news_post: @attrs }
response.should redirect_to(assigns(:news_post))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_post as @news_post" do
post :create, params: { news_post: @invalid_attrs }
assigns(:news_post).should_not be_valid
end
it "should be successful" do
post :create, params: { news_post: @invalid_attrs }
response.should be_successful
end
end
end
describe "When logged in as Librarian" do
login_librarian
describe "with valid params" do
it "assigns a newly created news_post as @news_post" do
post :create, params: { news_post: @attrs }
assigns(:news_post).should be_nil
end
it "should be forbidden" do
post :create, params: { news_post: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_post as @news_post" do
post :create, params: { news_post: @invalid_attrs }
assigns(:news_post).should be_nil
end
it "should be forbidden" do
post :create, params: { news_post: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When logged in as User" do
login_user
describe "with valid params" do
it "assigns a newly created news_post as @news_post" do
post :create, params: { news_post: @attrs }
assigns(:news_post).should be_nil
end
it "should be forbidden" do
post :create, params: { news_post: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_post as @news_post" do
post :create, params: { news_post: @invalid_attrs }
assigns(:news_post).should be_nil
end
it "should be forbidden" do
post :create, params: { news_post: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "assigns a newly created news_post as @news_post" do
post :create, params: { news_post: @attrs }
assigns(:news_post).should be_nil
end
it "should be forbidden" do
post :create, params: { news_post: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_post as @news_post" do
post :create, params: { news_post: @invalid_attrs }
assigns(:news_post).should be_nil
end
it "should be forbidden" do
post :create, params: { news_post: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "PUT update" do
before(:each) do
@news_post = FactoryBot.create(:news_post)
@attrs = valid_attributes
@invalid_attrs = { body: '' }
end
describe "When logged in as Administrator" do
login_admin
describe "with valid params" do
it "updates the requested news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
end
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
assigns(:news_post).should eq(@news_post)
end
it "moves its position when specified" do
put :update, params: { id: @news_post.id, news_post: @attrs, move: 'lower' }
response.should redirect_to(news_posts_url)
end
end
describe "with invalid params" do
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @invalid_attrs }
response.should render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_librarian
describe "with valid params" do
it "updates the requested news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
end
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
assigns(:news_post).should eq(@news_post)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When logged in as User" do
login_user
describe "with valid params" do
it "updates the requested news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
end
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
assigns(:news_post).should eq(@news_post)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested news_post" do
put :update, params: { id: @news_post.id, news_post: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @news_post.id, news_post: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested news_post as @news_post" do
put :update, params: { id: @news_post.id, news_post: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@news_post = FactoryBot.create(:news_post)
end
describe "When logged in as Administrator" do
login_admin
it "destroys the requested news_post" do
delete :destroy, params: { id: @news_post.id }
end
it "redirects to the news_posts list" do
delete :destroy, params: { id: @news_post.id }
response.should redirect_to(news_posts_url)
end
end
describe "When logged in as Librarian" do
login_librarian
it "destroys the requested news_post" do
delete :destroy, params: { id: @news_post.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @news_post.id }
response.should be_forbidden
end
end
describe "When logged in as User" do
login_user
it "destroys the requested news_post" do
delete :destroy, params: { id: @news_post.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @news_post.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested news_post" do
delete :destroy, params: { id: @news_post.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @news_post.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/subscriptions_controller_spec.rb | spec/controllers/subscriptions_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe SubscriptionsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:subscription)
end
describe 'GET index', solr: true do
before do
Subscription.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all subscriptions as @subscriptions' do
get :index
assigns(:subscriptions).should eq(Subscription.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all subscriptions as @subscriptions' do
get :index
assigns(:subscriptions).should eq(Subscription.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all subscriptions as @subscriptions' do
get :index
assigns(:subscriptions).should be_nil
end
end
describe 'When not logged in' do
it 'assigns all subscriptions as @subscriptions' do
get :index
assigns(:subscriptions).should be_nil
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :show, params: { id: subscription.id }
assigns(:subscription).should eq(subscription)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :show, params: { id: subscription.id }
assigns(:subscription).should eq(subscription)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :show, params: { id: subscription.id }
assigns(:subscription).should eq(subscription)
end
end
describe 'When not logged in' do
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :show, params: { id: subscription.id }
assigns(:subscription).should eq(subscription)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested subscription as @subscription' do
get :new
assigns(:subscription).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested subscription as @subscription' do
get :new
assigns(:subscription).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested subscription as @subscription' do
get :new
assigns(:subscription).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subscription as @subscription' do
get :new
assigns(:subscription).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :edit, params: { id: subscription.id }
assigns(:subscription).should eq(subscription)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :edit, params: { id: subscription.id }
assigns(:subscription).should eq(subscription)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :edit, params: { id: subscription.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subscription as @subscription' do
subscription = FactoryBot.create(:subscription)
get :edit, params: { id: subscription.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { title: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created subscription as @subscription' do
post :create, params: { subscription: @attrs }
assigns(:subscription).should be_valid
end
it 'redirects to the created subscription' do
post :create, params: { subscription: @attrs }
response.should redirect_to(subscription_url(assigns(:subscription)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscription as @subscription' do
post :create, params: { subscription: @invalid_attrs }
assigns(:subscription).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { subscription: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created subscription as @subscription' do
post :create, params: { subscription: @attrs }
assigns(:subscription).should be_valid
end
it 'redirects to the created subscription' do
post :create, params: { subscription: @attrs }
response.should redirect_to(subscription_url(assigns(:subscription)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscription as @subscription' do
post :create, params: { subscription: @invalid_attrs }
assigns(:subscription).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { subscription: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created subscription as @subscription' do
post :create, params: { subscription: @attrs }
assigns(:subscription).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscription: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscription as @subscription' do
post :create, params: { subscription: @invalid_attrs }
assigns(:subscription).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscription: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created subscription as @subscription' do
post :create, params: { subscription: @attrs }
assigns(:subscription).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscription: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subscription as @subscription' do
post :create, params: { subscription: @invalid_attrs }
assigns(:subscription).should be_nil
end
it 'should be forbidden' do
post :create, params: { subscription: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@subscription = FactoryBot.create(:subscription)
@attrs = valid_attributes
@invalid_attrs = { title: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
end
it 'assigns the requested subscription as @subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
assigns(:subscription).should eq(@subscription)
end
end
describe 'with invalid params' do
it 'assigns the requested subscription as @subscription' do
put :update, params: { id: @subscription.id, subscription: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
end
it 'assigns the requested subscription as @subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
assigns(:subscription).should eq(@subscription)
response.should redirect_to(@subscription)
end
end
describe 'with invalid params' do
it 'assigns the subscription as @subscription' do
put :update, params: { id: @subscription, subscription: @invalid_attrs }
assigns(:subscription).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @subscription, subscription: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
end
it 'assigns the requested subscription as @subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
assigns(:subscription).should eq(@subscription)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested subscription as @subscription' do
put :update, params: { id: @subscription.id, subscription: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested subscription' do
put :update, params: { id: @subscription.id, subscription: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @subscription.id, subscription: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested subscription as @subscription' do
put :update, params: { id: @subscription.id, subscription: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@subscription = FactoryBot.create(:subscription)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested subscription' do
delete :destroy, params: { id: @subscription.id }
end
it 'redirects to the subscriptions list' do
delete :destroy, params: { id: @subscription.id }
response.should redirect_to(subscriptions_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested subscription' do
delete :destroy, params: { id: @subscription.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subscription.id }
response.should redirect_to(subscriptions_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested subscription' do
delete :destroy, params: { id: @subscription.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subscription.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested subscription' do
delete :destroy, params: { id: @subscription.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subscription.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_relationships_controller_spec.rb | spec/controllers/agent_relationships_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe AgentRelationshipsController do
fixtures :all
disconnect_sunspot
def valid_attributes
@attrs = FactoryBot.attributes_for(:agent_relationship)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:agent_relationship)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all agent_relationships as @agent_relationships' do
get :index
expect(assigns(:agent_relationships)).to eq(AgentRelationship.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all agent_relationships as @agent_relationships' do
get :index
expect(assigns(:agent_relationships)).to eq(AgentRelationship.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all agent_relationships as @agent_relationships' do
get :index
expect(assigns(:agent_relationships)).to eq(AgentRelationship.page(1))
end
end
describe 'When not logged in' do
it 'assigns all agent_relationships as @agent_relationships' do
get :index
expect(assigns(:agent_relationships)).to eq(AgentRelationship.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :show, params: { id: agent_relationship.id }
expect(assigns(:agent_relationship)).to eq(agent_relationship)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :show, params: { id: agent_relationship.id }
expect(assigns(:agent_relationship)).to eq(agent_relationship)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :show, params: { id: agent_relationship.id }
expect(assigns(:agent_relationship)).to eq(agent_relationship)
end
end
describe 'When not logged in' do
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :show, params: { id: agent_relationship.id }
expect(assigns(:agent_relationship)).to eq(agent_relationship)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_relationship as @agent_relationship' do
get :new
expect(assigns(:agent_relationship)).to be_nil
expect(response).to redirect_to agents_url
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested agent_relationship as @agent_relationship' do
get :new
expect(assigns(:agent_relationship)).to be_nil
expect(response).to redirect_to agents_url
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested agent_relationship as @agent_relationship' do
get :new
expect(assigns(:agent_relationship)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_relationship as @agent_relationship' do
get :new
expect(assigns(:agent_relationship)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :edit, params: { id: agent_relationship.id }
expect(assigns(:agent_relationship)).to eq(agent_relationship)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :edit, params: { id: agent_relationship.id }
expect(assigns(:agent_relationship)).to eq(agent_relationship)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :edit, params: { id: agent_relationship.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_relationship as @agent_relationship' do
agent_relationship = FactoryBot.create(:agent_relationship)
get :edit, params: { id: agent_relationship.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { parent_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent_relationship: @attrs }
expect(response).to redirect_to(assigns(:agent_relationship))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @invalid_attrs }
expect(assigns(:agent_relationship)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent_relationship: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent_relationship: @attrs }
expect(response).to redirect_to(assigns(:agent_relationship))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @invalid_attrs }
expect(assigns(:agent_relationship)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent_relationship: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @invalid_attrs }
expect(assigns(:agent_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_relationship as @agent_relationship' do
post :create, params: { agent_relationship: @invalid_attrs }
expect(assigns(:agent_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { agent_relationship: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@agent_relationship = FactoryBot.create(:agent_relationship)
@attrs = valid_attributes
@invalid_attrs = { parent_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
end
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to eq(@agent_relationship)
expect(response).to redirect_to(@agent_relationship)
end
it 'moves its position when specified' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs, move: 'lower', agent_id: @agent_relationship.parent.id }
expect(response).to redirect_to(agent_relationships_url(agent_id: @agent_relationship.parent_id))
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
end
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to eq(@agent_relationship)
expect(response).to redirect_to(@agent_relationship)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
end
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
expect(assigns(:agent_relationship)).to eq(@agent_relationship)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_relationship as @agent_relationship' do
put :update, params: { id: @agent_relationship.id, agent_relationship: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@agent_relationship = FactoryBot.create(:agent_relationship)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested agent_relationship' do
delete :destroy, params: { id: @agent_relationship.id }
end
it 'redirects to the agent_relationships list' do
delete :destroy, params: { id: @agent_relationship.id }
expect(response).to redirect_to(agent_relationships_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested agent_relationship' do
delete :destroy, params: { id: @agent_relationship.id }
end
it 'redirects to the agent_relationships list' do
delete :destroy, params: { id: @agent_relationship.id }
expect(response).to redirect_to(agent_relationships_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested agent_relationship' do
delete :destroy, params: { id: @agent_relationship.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_relationship.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested agent_relationship' do
delete :destroy, params: { id: @agent_relationship.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_relationship.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/series_statement_merge_lists_controller_spec.rb | spec/controllers/series_statement_merge_lists_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe SeriesStatementMergeListsController do
disconnect_sunspot
describe 'GET index' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns all series_statement_merge_lists as @series_statement_merge_lists' do
get :index
assigns(:series_statement_merge_lists).should eq(SeriesStatementMergeList.page(1))
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns all series_statement_merge_lists as @series_statement_merge_lists' do
get :index
assigns(:series_statement_merge_lists).should eq(SeriesStatementMergeList.page(1))
end
end
describe 'When logged in as User' do
login_user
it 'assigns empty as @series_statement_merge_lists' do
get :index
assigns(:series_statement_merge_lists).should be_nil
end
end
describe 'When not logged in' do
it 'assigns empty as @series_statement_merge_lists' do
get :index
assigns(:series_statement_merge_lists).should be_nil
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :show, params: { id: series_statement_merge_list.id }
assigns(:series_statement_merge_list).should eq(series_statement_merge_list)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :show, params: { id: series_statement_merge_list.id }
assigns(:series_statement_merge_list).should eq(series_statement_merge_list)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :show, params: { id: series_statement_merge_list.id }
assigns(:series_statement_merge_list).should eq(series_statement_merge_list)
end
end
describe 'When not logged in' do
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :show, params: { id: series_statement_merge_list.id }
assigns(:series_statement_merge_list).should eq(series_statement_merge_list)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
get :new
assigns(:series_statement_merge_list).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
get :new
assigns(:series_statement_merge_list).should_not be_valid
end
end
describe 'When logged in as User' do
login_user
it 'should not assign the requested series_statement_merge_list as @series_statement_merge_list' do
get :new
assigns(:series_statement_merge_list).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested series_statement_merge_list as @series_statement_merge_list' do
get :new
assigns(:series_statement_merge_list).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :edit, params: { id: series_statement_merge_list.id }
assigns(:series_statement_merge_list).should eq(series_statement_merge_list)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :edit, params: { id: series_statement_merge_list.id }
assigns(:series_statement_merge_list).should eq(series_statement_merge_list)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :edit, params: { id: series_statement_merge_list.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested series_statement_merge_list as @series_statement_merge_list' do
series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
get :edit, params: { id: series_statement_merge_list.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:series_statement_merge_list)
@invalid_attrs = { title: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'assigns a newly created series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should be_valid
end
it 'redirects to the created series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @attrs }
response.should redirect_to(series_statement_merge_list_url(assigns(:series_statement_merge_list)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @invalid_attrs }
assigns(:series_statement_merge_list).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { series_statement_merge_list: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'assigns a newly created series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should be_valid
end
it 'redirects to the created series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @attrs }
response.should redirect_to(series_statement_merge_list_url(assigns(:series_statement_merge_list)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @invalid_attrs }
assigns(:series_statement_merge_list).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { series_statement_merge_list: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'assigns a newly created series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement_merge_list: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @invalid_attrs }
assigns(:series_statement_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement_merge_list: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement_merge_list: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved series_statement_merge_list as @series_statement_merge_list' do
post :create, params: { series_statement_merge_list: @invalid_attrs }
assigns(:series_statement_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { series_statement_merge_list: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
@attrs = FactoryBot.attributes_for(:series_statement_merge_list)
@invalid_attrs = { title: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'updates the requested series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
end
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should eq(@series_statement_merge_list)
response.should redirect_to(@series_statement_merge_list)
end
end
describe 'with invalid params' do
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'updates the requested series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
end
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should eq(@series_statement_merge_list)
response.should redirect_to(@series_statement_merge_list)
end
end
describe 'with invalid params' do
it 'assigns the series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @invalid_attrs }
assigns(:series_statement_merge_list).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'updates the requested series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
end
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
assigns(:series_statement_merge_list).should eq(@series_statement_merge_list)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested series_statement_merge_list as @series_statement_merge_list' do
put :update, params: { id: @series_statement_merge_list.id, series_statement_merge_list: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@series_statement_merge_list = FactoryBot.create(:series_statement_merge_list)
end
describe 'When logged in as Administrator' do
login_admin
it 'destroys the requested series_statement_merge_list' do
delete :destroy, params: { id: @series_statement_merge_list.id }
end
it 'redirects to the series_statement_merge_lists list' do
delete :destroy, params: { id: @series_statement_merge_list.id }
response.should redirect_to(series_statement_merge_lists_url)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'destroys the requested series_statement_merge_list' do
delete :destroy, params: { id: @series_statement_merge_list.id }
end
it 'redirects to the series_statement_merge_lists list' do
delete :destroy, params: { id: @series_statement_merge_list.id }
response.should redirect_to(series_statement_merge_lists_url)
end
end
describe 'When logged in as User' do
login_user
it 'destroys the requested series_statement_merge_list' do
delete :destroy, params: { id: @series_statement_merge_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @series_statement_merge_list.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested series_statement_merge_list' do
delete :destroy, params: { id: @series_statement_merge_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @series_statement_merge_list.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/news_feeds_controller_spec.rb | spec/controllers/news_feeds_controller_spec.rb | require 'rails_helper'
describe NewsFeedsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:news_feed)
end
describe "GET index" do
before(:each) do
FactoryBot.create(:news_feed)
end
describe "When logged in as Administrator" do
login_admin
it "assigns all news_feeds as @news_feeds" do
get :index
assigns(:news_feeds).should eq(NewsFeed.page(1))
end
end
describe "When logged in as Librarian" do
login_librarian
it "assigns all news_feeds as @news_feeds" do
get :index
assigns(:news_feeds).should eq(NewsFeed.page(1))
end
end
describe "When logged in as User" do
login_user
it "assigns empty as @news_feeds" do
get :index
assigns(:news_feeds).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "assigns all news_feeds as @news_feeds" do
get :index
assigns(:news_feeds).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET show" do
before(:each) do
@news_feed = FactoryBot.create(:news_feed)
end
describe "When logged in as Administrator" do
login_admin
it "assigns the requested news_feed as @news_feed" do
get :show, params: { id: @news_feed.id }
assigns(:news_feed).should eq(@news_feed)
end
end
describe "When logged in as Librarian" do
login_librarian
it "assigns the requested news_feed as @news_feed" do
get :show, params: { id: @news_feed.id }
assigns(:news_feed).should eq(@news_feed)
end
end
describe "When logged in as User" do
login_user
it "assigns the requested news_feed as @news_feed" do
get :show, params: { id: @news_feed.id }
assigns(:news_feed).should eq(@news_feed)
end
end
describe "When not logged in" do
it "assigns the requested news_feed as @news_feed" do
get :show, params: { id: @news_feed.id }
assigns(:news_feed).should eq(@news_feed)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_admin
it "assigns the requested news_feed as @news_feed" do
get :new
assigns(:news_feed).should_not be_valid
response.should be_successful
end
end
describe "When logged in as Librarian" do
login_librarian
it "should not assign the requested news_feed as @news_feed" do
get :new
assigns(:news_feed).should be_nil
response.should be_forbidden
end
end
describe "When logged in as User" do
login_user
it "should not assign the requested news_feed as @news_feed" do
get :new
assigns(:news_feed).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested news_feed as @news_feed" do
get :new
assigns(:news_feed).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET edit" do
before(:each) do
@news_feed = FactoryBot.create(:news_feed)
end
describe "When logged in as Administrator" do
login_admin
it "assigns the requested news_feed as @news_feed" do
get :edit, params: { id: @news_feed.id }
assigns(:news_feed).should eq(@news_feed)
end
end
describe "When logged in as Librarian" do
login_librarian
it "assigns the requested news_feed as @news_feed" do
get :edit, params: { id: @news_feed.id }
response.should be_forbidden
end
end
describe "When logged in as User" do
login_user
it "assigns the requested news_feed as @news_feed" do
get :edit, params: { id: @news_feed.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested news_feed as @news_feed" do
get :edit, params: { id: @news_feed.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { title: '' }
end
describe "When logged in as Administrator" do
login_admin
describe "with valid params" do
it "assigns a newly created news_feed as @news_feed" do
post :create, params: { news_feed: @attrs }
assigns(:news_feed).should be_valid
end
it "redirects to the created news_feed" do
post :create, params: { news_feed: @attrs }
response.should redirect_to(assigns(:news_feed))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_feed as @news_feed" do
post :create, params: { news_feed: @invalid_attrs }
assigns(:news_feed).should_not be_valid
end
it "should be successful" do
post :create, params: { news_feed: @invalid_attrs }
response.should be_successful
end
end
end
describe "When logged in as Librarian" do
login_librarian
describe "with valid params" do
it "assigns a newly created news_feed as @news_feed" do
post :create, params: { news_feed: @attrs }
assigns(:news_feed).should be_nil
end
it "should be forbidden" do
post :create, params: { news_feed: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_feed as @news_feed" do
post :create, params: { news_feed: @invalid_attrs }
assigns(:news_feed).should be_nil
end
it "should be forbidden" do
post :create, params: { news_feed: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When logged in as User" do
login_user
describe "with valid params" do
it "assigns a newly created news_feed as @news_feed" do
post :create, params: { news_feed: @attrs }
assigns(:news_feed).should be_nil
end
it "should be forbidden" do
post :create, params: { news_feed: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_feed as @news_feed" do
post :create, params: { news_feed: @invalid_attrs }
assigns(:news_feed).should be_nil
end
it "should be forbidden" do
post :create, params: { news_feed: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "assigns a newly created news_feed as @news_feed" do
post :create, params: { news_feed: @attrs }
assigns(:news_feed).should be_nil
end
it "should be forbidden" do
post :create, params: { news_feed: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved news_feed as @news_feed" do
post :create, params: { news_feed: @invalid_attrs }
assigns(:news_feed).should be_nil
end
it "should be forbidden" do
post :create, params: { news_feed: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "PUT update" do
before(:each) do
@news_feed = FactoryBot.create(:news_feed)
@attrs = valid_attributes
@invalid_attrs = { title: '' }
end
describe "When logged in as Administrator" do
login_admin
describe "with valid params" do
it "updates the requested news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
end
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
assigns(:news_feed).should eq(@news_feed)
end
it "moves its position when specified" do
put :update, params: { id: @news_feed.id, news_feed: @attrs, move: 'lower' }
response.should redirect_to(news_feeds_url)
end
end
describe "with invalid params" do
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @invalid_attrs }
response.should render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_librarian
describe "with valid params" do
it "updates the requested news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
end
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
assigns(:news_feed).should eq(@news_feed)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When logged in as User" do
login_user
describe "with valid params" do
it "updates the requested news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
end
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
assigns(:news_feed).should eq(@news_feed)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @news_feed.id, news_feed: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested news_feed as @news_feed" do
put :update, params: { id: @news_feed.id, news_feed: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@news_feed = FactoryBot.create(:news_feed)
end
describe "When logged in as Administrator" do
login_admin
it "destroys the requested news_feed" do
delete :destroy, params: { id: @news_feed.id }
end
it "redirects to the news_feeds list" do
delete :destroy, params: { id: @news_feed.id }
response.should redirect_to(news_feeds_url)
end
end
describe "When logged in as Librarian" do
login_librarian
it "destroys the requested news_feed" do
delete :destroy, params: { id: @news_feed.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @news_feed.id }
response.should be_forbidden
end
end
describe "When logged in as User" do
login_user
it "destroys the requested news_feed" do
delete :destroy, params: { id: @news_feed.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @news_feed.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested news_feed" do
delete :destroy, params: { id: @news_feed.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @news_feed.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/manifestation_relationship_types_controller_spec.rb | spec/controllers/manifestation_relationship_types_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ManifestationRelationshipTypesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:manifestation_relationship_type)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:manifestation_relationship_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all manifestation_relationship_types as @manifestation_relationship_types' do
get :index
expect(assigns(:manifestation_relationship_types)).to eq(ManifestationRelationshipType.all)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all manifestation_relationship_types as @manifestation_relationship_types' do
get :index
expect(assigns(:manifestation_relationship_types)).to eq(ManifestationRelationshipType.all)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all manifestation_relationship_types as @manifestation_relationship_types' do
get :index
expect(assigns(:manifestation_relationship_types)).to eq(ManifestationRelationshipType.all)
end
end
describe 'When not logged in' do
it 'assigns all manifestation_relationship_types as @manifestation_relationship_types' do
get :index
expect(assigns(:manifestation_relationship_types)).to eq(ManifestationRelationshipType.all)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :show, params: { id: manifestation_relationship_type.id }
expect(assigns(:manifestation_relationship_type)).to eq(manifestation_relationship_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :show, params: { id: manifestation_relationship_type.id }
expect(assigns(:manifestation_relationship_type)).to eq(manifestation_relationship_type)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :show, params: { id: manifestation_relationship_type.id }
expect(assigns(:manifestation_relationship_type)).to eq(manifestation_relationship_type)
end
end
describe 'When not logged in' do
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :show, params: { id: manifestation_relationship_type.id }
expect(assigns(:manifestation_relationship_type)).to eq(manifestation_relationship_type)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
get :new
expect(assigns(:manifestation_relationship_type)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested manifestation_relationship_type as @manifestation_relationship_type' do
get :new
expect(assigns(:manifestation_relationship_type)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested manifestation_relationship_type as @manifestation_relationship_type' do
get :new
expect(assigns(:manifestation_relationship_type)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_relationship_type as @manifestation_relationship_type' do
get :new
expect(assigns(:manifestation_relationship_type)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :edit, params: { id: manifestation_relationship_type.id }
expect(assigns(:manifestation_relationship_type)).to eq(manifestation_relationship_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :edit, params: { id: manifestation_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :edit, params: { id: manifestation_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_relationship_type as @manifestation_relationship_type' do
manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
get :edit, params: { id: manifestation_relationship_type.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(response).to redirect_to(assigns(:manifestation_relationship_type))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(assigns(:manifestation_relationship_type)).not_to be_valid
end
it 'should be successful' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(response).to be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(assigns(:manifestation_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(assigns(:manifestation_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship_type: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship_type as @manifestation_relationship_type' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(assigns(:manifestation_relationship_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship_type: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
end
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to eq(@manifestation_relationship_type)
end
it 'moves its position when specified' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs, move: 'lower' }
expect(response).to redirect_to(manifestation_relationship_types_url)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
end
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to eq(@manifestation_relationship_type)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
end
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
expect(assigns(:manifestation_relationship_type)).to eq(@manifestation_relationship_type)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship_type as @manifestation_relationship_type' do
put :update, params: { id: @manifestation_relationship_type.id, manifestation_relationship_type: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@manifestation_relationship_type = FactoryBot.create(:manifestation_relationship_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested manifestation_relationship_type' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
end
it 'redirects to the manifestation_relationship_types list' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
expect(response).to redirect_to(manifestation_relationship_types_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested manifestation_relationship_type' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested manifestation_relationship_type' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested manifestation_relationship_type' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_relationship_type.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/use_restrictions_controller_spec.rb | spec/controllers/use_restrictions_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe UseRestrictionsController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:use_restriction)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:use_restriction)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all use_restrictions as @use_restrictions' do
get :index
assigns(:use_restrictions).should eq(UseRestriction.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all use_restrictions as @use_restrictions' do
get :index
assigns(:use_restrictions).should eq(UseRestriction.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should be forbidden' do
get :index
assigns(:use_restrictions).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all use_restrictions as @use_restrictions' do
get :index
assigns(:use_restrictions).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :show, params: { id: use_restriction.id }
assigns(:use_restriction).should eq(use_restriction)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :show, params: { id: use_restriction.id }
assigns(:use_restriction).should eq(use_restriction)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :show, params: { id: use_restriction.id }
assigns(:use_restriction).should eq(use_restriction)
end
end
describe 'When not logged in' do
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :show, params: { id: use_restriction.id }
assigns(:use_restriction).should eq(use_restriction)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'should be forbidden' do
get :new
assigns(:use_restriction).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should be forbidden' do
get :new
assigns(:use_restriction).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should be forbidden' do
get :new
assigns(:use_restriction).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should be redirected' do
get :new
assigns(:use_restriction).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :edit, params: { id: use_restriction.id }
assigns(:use_restriction).should eq(use_restriction)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :edit, params: { id: use_restriction.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :edit, params: { id: use_restriction.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested use_restriction as @use_restriction' do
use_restriction = FactoryBot.create(:use_restriction)
get :edit, params: { id: use_restriction.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created use_restriction as @use_restriction' do
post :create, params: { use_restriction: @attrs }
assigns(:use_restriction).should be_nil
end
it 'redirects to the created patron' do
post :create, params: { use_restriction: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved use_restriction as @use_restriction' do
post :create, params: { use_restriction: @invalid_attrs }
assigns(:use_restriction).should be_nil
end
it 'should be successful' do
post :create, params: { use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created use_restriction as @use_restriction' do
post :create, params: { use_restriction: @attrs }
assigns(:use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { use_restriction: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved use_restriction as @use_restriction' do
post :create, params: { use_restriction: @invalid_attrs }
assigns(:use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created use_restriction as @use_restriction' do
post :create, params: { use_restriction: @attrs }
assigns(:use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { use_restriction: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved use_restriction as @use_restriction' do
post :create, params: { use_restriction: @invalid_attrs }
assigns(:use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created use_restriction as @use_restriction' do
post :create, params: { use_restriction: @attrs }
assigns(:use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { use_restriction: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved use_restriction as @use_restriction' do
post :create, params: { use_restriction: @invalid_attrs }
assigns(:use_restriction).should be_nil
end
it 'should be forbidden' do
post :create, params: { use_restriction: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@use_restriction = FactoryBot.create(:use_restriction)
@attrs = valid_attributes
@invalid_attrs = { display_name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
end
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
assigns(:use_restriction).should eq(@use_restriction)
end
it 'moves its position when specified' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs, move: 'lower' }
response.should redirect_to(use_restrictions_url)
end
end
describe 'with invalid params' do
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
end
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
assigns(:use_restriction).should eq(@use_restriction)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
end
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
assigns(:use_restriction).should eq(@use_restriction)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @use_restriction.id, use_restriction: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested use_restriction as @use_restriction' do
put :update, params: { id: @use_restriction.id, use_restriction: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@use_restriction = FactoryBot.create(:use_restriction)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested use_restriction' do
delete :destroy, params: { id: @use_restriction.id }
end
it 'redirects to the use_restrictions list' do
delete :destroy, params: { id: @use_restriction.id }
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested use_restriction' do
delete :destroy, params: { id: @use_restriction.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @use_restriction.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested use_restriction' do
delete :destroy, params: { id: @use_restriction.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @use_restriction.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested use_restriction' do
delete :destroy, params: { id: @use_restriction.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @use_restriction.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/reserves_controller_spec.rb | spec/controllers/reserves_controller_spec.rb | require 'rails_helper'
describe ReservesController do
fixtures :all
describe 'GET index', solr: true do
before do
Reserve.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all reserves as @reserves' do
get :index
assigns(:reserves).should eq(Reserve.order('reserves.id DESC').includes(:manifestation).page(1))
end
it "should get other user's reservation" do
get :index, params: { user_id: users(:user1).username }
response.should be_successful
assigns(:reserves).should eq(users(:user1).reserves.order('reserves.id DESC').includes(:manifestation).page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all reserves as @reserves' do
get :index
assigns(:reserves).should eq(Reserve.order('reserves.id DESC').includes(:manifestation).page(1))
end
it 'should get index feed without user_id' do
get :index, format: 'rss'
response.should be_successful
assigns(:reserves).count.should eq assigns(:reserves).total_entries
assigns(:reserves).should eq(Reserve.order('reserves.id DESC').includes(:manifestation))
end
it 'should get index text without user_id' do
get :index, format: :text
response.should be_successful
assigns(:reserves).count.should eq assigns(:reserves).total_entries
assigns(:reserves).should eq(Reserve.order('reserves.id DESC').includes(:manifestation))
end
it 'should get index feed with user_id' do
get :index, params: { user_id: users(:user1).username, format: 'rss' }
response.should be_successful
assigns(:reserves).should eq(users(:user1).reserves.order('reserves.id DESC').includes(:manifestation).page(1))
end
it 'should get index text with user_id' do
get :index, params: { user_id: users(:user1).username, format: :text }
response.should be_successful
assigns(:reserves).should eq(users(:user1).reserves.order('reserves.id DESC').includes(:manifestation))
end
it "should get other user's index" do
get :index, params: { user_id: users(:user1).username }
response.should be_successful
assigns(:reserves).should eq(users(:user1).reserves.order('reserves.id DESC').includes(:manifestation).page(1))
end
it "should get other user's index feed" do
get :index, params: { user_id: users(:user1).username, format: :rss }
response.should be_successful
assigns(:reserves).should eq(users(:user1).reserves.order('reserves.id DESC').includes(:manifestation).page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns my reserves as @reserves' do
get :index
assigns(:reserves).should eq(users(:user1).reserves.order('reserves.id DESC').includes(:manifestation).page(1))
end
it 'should be redirected to my index' do
get :index
response.should be_successful
end
it 'should get my index feed' do
get :index, format: :rss
response.should be_successful
response.should render_template('index')
end
it 'should get my index text' do
get :index, format: :text
response.should be_successful
response.should render_template('index')
end
describe 'When my user_id is specified' do
it 'should redirect to my reservation' do
get :index, params: { user_id: users(:user1).username }
response.should redirect_to reserves_url
end
it 'should redirect to my reservation feed' do
get :index, params: { user_id: users(:user1).username, format: 'rss' }
response.should redirect_to reserves_url(format: :rss)
end
it 'should redirect to my reservation text' do
get :index, params: { user_id: users(:user1).username, format: :text }
response.should redirect_to reserves_url(format: :text)
end
end
describe 'When other user_id is specified' do
before(:each) do
@user = users(:user3)
end
it 'should not get any reserve as @reserves' do
get :index, params: { user_id: @user.username }
response.should be_forbidden
end
end
it "should not get other user's index" do
get :index, params: { user_id: users(:user2).username }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @reserves' do
get :index
assigns(:reserves).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :show, params: { id: reserve.id }
assigns(:reserve).should eq(reserve)
end
it "should show other user's reservation" do
get :show, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :show, params: { id: reserve.id }
assigns(:reserve).should eq(reserve)
end
it "should show other user's reservation" do
get :show, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :show, params: { id: reserve.id }
assigns(:reserve).should eq(reserve)
end
it 'should show my reservation' do
get :show, params: { id: 3 }
response.should be_successful
end
it "should not show other user's reservation" do
get :show, params: { id: 5 }
response.should be_forbidden
end
end
describe 'When not logged in' do
before(:each) do
@reserve = FactoryBot.create(:reserve)
end
it 'assigns the requested reserve as @reserve' do
get :show, params: { id: @reserve.id }
assigns(:reserve).should eq(@reserve)
end
it 'should be redirected to new_user_session_url' do
get :show, params: { id: @reserve.id }
response.should redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested reserve as @reserve' do
get :new
assigns(:reserve).should_not be_valid
end
it "should get other user's reservation" do
get :new, params: { user_id: users(:user1).username, manifestation_id: 3 }
assigns(:reserve).user.should eq users(:user1)
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested reserve as @reserve' do
get :new
assigns(:reserve).should_not be_valid
end
it 'should get new template without user_id' do
get :new, params: { manifestation_id: 3 }
response.should be_successful
end
it "should get other user's reservation" do
get :new, params: { user_id: users(:user1).username, manifestation_id: 3 }
assigns(:reserve).user.should eq users(:user1)
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested reserve as @reserve' do
get :new
assigns(:reserve).should_not be_valid
response.should be_successful
end
it 'should get my new reservation' do
get :new, params: { manifestation_id: 3 }
response.should be_successful
end
it "should not get other user's new reservation" do
get :new, params: { user_id: users(:user2).username, manifestation_id: 5 }
response.should be_forbidden
end
it 'should not get new reservation when user_number is not set' do
sign_in users(:user2)
get :new, params: { user_id: users(:user2).username, manifestation_id: 3 }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested reserve as @reserve' do
get :new
assigns(:reserve).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :edit, params: { id: reserve.id }
assigns(:reserve).should eq(reserve)
end
it "should edit other user's reservation" do
get :edit, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :edit, params: { id: reserve.id }
assigns(:reserve).should eq(reserve)
end
it 'should edit reserve without user_id' do
get :edit, params: { id: 3 }
response.should be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :edit, params: { id: reserve.id }
assigns(:reserve).should eq(reserve)
end
it 'should edit my reservation' do
get :edit, params: { id: 3 }
response.should be_successful
end
it "should not edit other user's reservation" do
get :edit, params: { id: 5 }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested reserve as @reserve' do
reserve = FactoryBot.create(:reserve)
get :edit, params: { id: reserve.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = { user_number: users(:user1).profile.user_number, manifestation_id: 5 }
@invalid_attrs = { user_number: users(:user1).profile.user_number, manifestation_id: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created reserve as @reserve' do
post :create, params: { reserve: @attrs }
assigns(:reserve).should be_valid
end
it 'redirects to the created reserve' do
post :create, params: { reserve: @attrs }
response.should redirect_to(assigns(:reserve))
assigns(:reserve).expired_at.should be_nil
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved reserve as @reserve' do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).should_not be_valid
end
it 'redirects to the list' do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).expired_at.should be_nil
response.should render_template('new')
response.should be_successful
end
end
it 'should not create reservation with past date' do
post :create, params: { reserve: { user_number: users(:user1).profile.user_number, manifestation_id: 5, expired_at: '1901-01-01' } }
assigns(:reserve).should_not be_valid
response.should be_successful
end
it "should create other user's reserve" do
post :create, params: { reserve: { user_number: users(:user1).profile.user_number, manifestation_id: 5 } }
assigns(:reserve).expired_at.should be_nil
response.should redirect_to reserve_url(assigns(:reserve))
end
it 'should not create reserve without manifestation_id' do
post :create, params: { reserve: { user_number: users(:admin).profile.user_number } }
response.should be_successful
end
it 'should not create reserve with missing user_number' do
post :create, params: { reserve: { user_number: 'missing', manifestation_id: 5 } }
response.should render_template('new')
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created reserve as @reserve' do
post :create, params: { reserve: @attrs }
assigns(:reserve).should be_valid
end
it 'redirects to the created reserve' do
post :create, params: { reserve: @attrs }
response.should redirect_to(assigns(:reserve))
assigns(:reserve).expired_at.should be_nil
end
it 'should send accepted messages' do
old_count = Message.count
post :create, params: { reserve: @attrs }
Message.count.should eq old_count + 2
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved reserve as @reserve' do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).expired_at.should be_nil
response.should render_template('new')
response.should be_successful
end
end
it "should create other user's reserve" do
post :create, params: { reserve: { user_number: users(:user1).profile.user_number, manifestation_id: 5 } }
assigns(:reserve).should be_valid
assigns(:reserve).expired_at.should be_nil
response.should redirect_to reserve_url(assigns(:reserve))
end
it 'should not create reserve over reserve_limit' do
post :create, params: { reserve: { user_number: users(:admin).profile.user_number, manifestation_id: 5 } }
assigns(:reserve).errors[:base].include?(I18n.t('reserve.excessed_reservation_limit')).should be_truthy
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created reserve as @reserve' do
post :create, params: { reserve: @attrs }
assigns(:reserve).should be_valid
end
it 'redirects to the created reserve' do
post :create, params: { reserve: @attrs }
response.should redirect_to(assigns(:reserve))
assigns(:reserve).expired_at.should be_nil
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved reserve as @reserve' do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).expired_at.should be_nil
response.should render_template('new')
response.should be_successful
end
end
it "should not create other user's reservation" do
post :create, params: { reserve: { user_number: users(:user2).profile.user_number, manifestation_id: 6 } }
assigns(:reserve).expired_at.should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created reserve as @reserve' do
post :create, params: { reserve: @attrs }
assigns(:reserve).should be_nil
end
it 'redirects to the login page' do
post :create, params: { reserve: @attrs }
response.should redirect_to new_user_session_url
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved reserve as @reserve' do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).should be_nil
end
it 'redirects to the login page' do
post :create, params: { reserve: @invalid_attrs }
assigns(:reserve).should be_nil
response.should redirect_to new_user_session_url
end
end
end
end
describe 'PUT update' do
before(:each) do
@reserve = FactoryBot.create(:reserve)
@attrs = FactoryBot.attributes_for(:reserve)
@invalid_attrs = { manifestation_id: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
end
it 'assigns the requested reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
assigns(:reserve).should eq(@reserve)
response.should redirect_to(assigns(:reserve))
end
end
describe 'with invalid params' do
it 'assigns the requested reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @reserve.id, reserve: @invalid_attrs }
response.should render_template('edit')
end
end
it 'should not update reserve without manifestation_id' do
put :update, params: { id: 1, reserve: { user_number: users(:admin).profile.user_number, manifestation_id: nil } }
assigns(:reserve).should_not be_valid
response.should be_successful
end
it "should update other user's reservation without user_id" do
put :update, params: { id: 3, reserve: { user_number: users(:user1).profile.user_number } }
assigns(:reserve).should be_valid
response.should redirect_to reserve_url(assigns(:reserve))
end
it 'should not update retained reservations if item_identifier is invalid' do
put :update, params: { id: 14, reserve: { item_identifier: 'invalid' } }
assigns(:reserve).should_not be_valid
response.should be_successful
end
it 'should not update retained reservations if force_retaining is disabled' do
put :update, params: { id: 15, reserve: { item_identifier: '00021' } }
assigns(:reserve).should_not be_valid
response.should be_successful
assigns(:reserve).current_state.should eq 'requested'
reserves(:reserve_00014).current_state.should eq 'retained'
end
it 'should update retained reservations if force_retaining is enabled' do
put :update, params: { id: 15, reserve: { item_identifier: '00021', force_retaining: '1' } }
assigns(:reserve).should be_valid
assigns(:reserve).current_state.should eq 'retained'
response.should redirect_to reserve_url(assigns(:reserve))
reserves(:reserve_00014).current_state.should eq 'postponed'
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
end
it 'assigns the requested reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
assigns(:reserve).should eq(@reserve)
response.should redirect_to(assigns(:reserve))
end
end
describe 'with invalid params' do
it 'assigns the reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @invalid_attrs }
assigns(:reserve).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @reserve.id, reserve: @invalid_attrs }
response.should render_template('edit')
end
end
it "should cancel other user's reservation" do
put :update, params: { id: 3, reserve: { user_number: users(:user1).profile.user_number }, mode: 'cancel' }
flash[:notice].should eq I18n.t('reserve.reservation_was_canceled')
assigns(:reserve).current_state.should eq 'canceled'
response.should redirect_to reserve_url(assigns(:reserve))
end
it 'should update reserve without user_id' do
put :update, params: { id: 3, reserve: { user_number: users(:user1).profile.user_number } }
assigns(:reserve).should be_valid
response.should redirect_to reserve_url(assigns(:reserve))
end
it "should update other user's reservation" do
put :update, params: { id: 3, reserve: { user_number: users(:user1).profile.user_number } }
assigns(:reserve).should be_valid
response.should redirect_to reserve_url(assigns(:reserve))
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
end
it 'assigns the requested reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
assigns(:reserve).should eq(@reserve)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @invalid_attrs }
response.should be_forbidden
end
end
it 'should cancel my reservation' do
put :update, params: { id: 3, mode: 'cancel' }
flash[:notice].should eq I18n.t('reserve.reservation_was_canceled')
assigns(:reserve).current_state.should eq 'canceled'
response.should redirect_to reserve_url(assigns(:reserve))
end
it 'should update my reservation' do
put :update, params: { id: 3, reserve: { user_number: users(:user1).profile.user_number } }
flash[:notice].should eq I18n.t('controller.successfully_updated', model: I18n.t('activerecord.models.reserve'))
response.should redirect_to reserve_url(assigns(:reserve))
end
it "should not update other user's reservation" do
put :update, params: { id: 5, reserve: { user_number: users(:user2).profile.user_number } }
response.should be_forbidden
end
it "should not cancel other user's reservation" do
put :update, params: { id: 5, reserve: { user_number: users(:user1).profile.user_number }, mode: 'cancel' }
response.should be_forbidden
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested reserve' do
put :update, params: { id: @reserve.id, reserve: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @reserve.id, reserve: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested reserve as @reserve' do
put :update, params: { id: @reserve.id, reserve: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@reserve = FactoryBot.create(:reserve)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested reserve' do
delete :destroy, params: { id: @reserve.id }
end
it 'redirects to the reserves list' do
delete :destroy, params: { id: @reserve.id }
response.should redirect_to(reserves_url)
end
it "should destroy other user's reservation" do
delete :destroy, params: { id: 3 }
response.should redirect_to reserves_url
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested reserve' do
delete :destroy, params: { id: @reserve.id }
end
it 'redirects to the reserves list' do
delete :destroy, params: { id: @reserve.id }
response.should redirect_to(reserves_url)
end
it "should destroy other user's reservation" do
delete :destroy, params: { id: 3 }
response.should redirect_to reserves_url
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested reserve' do
delete :destroy, params: { id: @reserve.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @reserve.id }
response.should be_forbidden
end
it 'should destroy my reservation' do
delete :destroy, params: { id: 3 }
response.should redirect_to reserves_url
end
it "should not destroy other user's reservation" do
delete :destroy, params: { id: 5 }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested reserve' do
delete :destroy, params: { id: @reserve.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @reserve.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/bookstores_controller_spec.rb | spec/controllers/bookstores_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe BookstoresController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:bookstore)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:bookstore)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all bookstores as @bookstores' do
get :index
assigns(:bookstores).should eq(Bookstore.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all bookstores as @bookstores' do
get :index
assigns(:bookstores).should eq(Bookstore.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all bookstores as @bookstores' do
get :index
assigns(:bookstores).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all bookstores as @bookstores' do
get :index
assigns(:bookstores).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
before(:each) do
@bookstore = FactoryBot.create(:bookstore)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested bookstore as @bookstore' do
get :show, params: { id: @bookstore.id }
assigns(:bookstore).should eq(@bookstore)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested bookstore as @bookstore' do
get :show, params: { id: @bookstore.id }
assigns(:bookstore).should eq(@bookstore)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested bookstore as @bookstore' do
get :show, params: { id: @bookstore.id }
assigns(:bookstore).should eq(@bookstore)
end
end
describe 'When not logged in' do
it 'assigns the requested bookstore as @bookstore' do
get :show, params: { id: @bookstore.id }
assigns(:bookstore).should eq(@bookstore)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested bookstore as @bookstore' do
get :new
assigns(:bookstore).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested bookstore as @bookstore' do
get :new
assigns(:bookstore).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested bookstore as @bookstore' do
get :new
assigns(:bookstore).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested bookstore as @bookstore' do
get :new
assigns(:bookstore).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
before(:each) do
@bookstore = FactoryBot.create(:bookstore)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested bookstore as @bookstore' do
get :edit, params: { id: @bookstore.id }
assigns(:bookstore).should eq(@bookstore)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested bookstore as @bookstore' do
get :edit, params: { id: @bookstore.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested bookstore as @bookstore' do
get :edit, params: { id: @bookstore.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested bookstore as @bookstore' do
get :edit, params: { id: @bookstore.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created bookstore as @bookstore' do
post :create, params: { bookstore: @attrs }
assigns(:bookstore).should be_valid
end
it 'redirects to the created bookstore' do
post :create, params: { bookstore: @attrs }
response.should redirect_to(assigns(:bookstore))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved bookstore as @bookstore' do
post :create, params: { bookstore: @invalid_attrs }
assigns(:bookstore).should_not be_valid
end
it 'should be successful' do
post :create, params: { bookstore: @invalid_attrs }
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created bookstore as @bookstore' do
post :create, params: { bookstore: @attrs }
assigns(:bookstore).should be_nil
end
it 'should be forbidden' do
post :create, params: { bookstore: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved bookstore as @bookstore' do
post :create, params: { bookstore: @invalid_attrs }
assigns(:bookstore).should be_nil
end
it 'should be forbidden' do
post :create, params: { bookstore: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created bookstore as @bookstore' do
post :create, params: { bookstore: @attrs }
assigns(:bookstore).should be_nil
end
it 'should be forbidden' do
post :create, params: { bookstore: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved bookstore as @bookstore' do
post :create, params: { bookstore: @invalid_attrs }
assigns(:bookstore).should be_nil
end
it 'should be forbidden' do
post :create, params: { bookstore: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created bookstore as @bookstore' do
post :create, params: { bookstore: @attrs }
assigns(:bookstore).should be_nil
end
it 'should be forbidden' do
post :create, params: { bookstore: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved bookstore as @bookstore' do
post :create, params: { bookstore: @invalid_attrs }
assigns(:bookstore).should be_nil
end
it 'should be forbidden' do
post :create, params: { bookstore: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@bookstore = FactoryBot.create(:bookstore)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
end
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
assigns(:bookstore).should eq(@bookstore)
end
it 'moves its position when specified' do
put :update, params: { id: @bookstore.id, bookstore: @attrs, move: 'lower' }
response.should redirect_to(bookstores_url)
end
end
describe 'with invalid params' do
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
end
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
assigns(:bookstore).should eq(@bookstore)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
end
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
assigns(:bookstore).should eq(@bookstore)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @bookstore.id, bookstore: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested bookstore as @bookstore' do
put :update, params: { id: @bookstore.id, bookstore: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@bookstore = FactoryBot.create(:bookstore)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested bookstore' do
delete :destroy, params: { id: @bookstore.id }
end
it 'redirects to the bookstores list' do
delete :destroy, params: { id: @bookstore.id }
response.should redirect_to(bookstores_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested bookstore' do
delete :destroy, params: { id: @bookstore.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @bookstore.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested bookstore' do
delete :destroy, params: { id: @bookstore.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @bookstore.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested bookstore' do
delete :destroy, params: { id: @bookstore.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @bookstore.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/items_controller_spec.rb | spec/controllers/items_controller_spec.rb | require 'rails_helper'
describe ItemsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:item)
end
describe 'GET index', solr: true do
before do
Item.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all items as @items' do
get :index
expect(assigns(:items)).to_not be_nil
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all items as @items' do
get :index
expect(assigns(:items)).to_not be_nil
end
it 'assigns items as @items with acquired_from and acquired_until' do
get :index, params: { acquired_from: '2015-09-20', acquired_until: '2015-09-26' }
expect(assigns(:items)).to_not be_nil
expect(assigns(:items).count).to eq 1
end
it 'assigns items as @items with acquired_from' do
get :index, params: { acquired_from: '2015-09-20' }
expect(assigns(:items)).to_not be_nil
expect(assigns(:items).count).to eq 1
end
it 'assigns items as @items with acquired_until' do
get :index, params: { acquired_until: '2015-09-20' }
expect(assigns(:items)).to_not be_nil
expect(assigns(:items).count).to eq 1
end
it 'accepts text format' do
get :index, format: :text
expect(assigns(:items)).to_not be_nil
end
describe 'in JSON response' do
render_views
it 'should not assign unnecessary attributes' do
get :index, format: :json
expect(response.body).to match /manifestation_id/
expect(response.body).not_to match /price/
expect(response.body).not_to match /memo/
expect(response.body).not_to match /bookstore_id/
expect(response.body).not_to match /budget_type_id/
end
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all items as @items' do
get :index
expect(assigns(:items)).to_not be_nil
end
describe 'in JSON response' do
render_views
it 'should not assign unnecessary attributes' do
get :index, format: :json
expect(response.body).to match /manifestation_id/
expect(response.body).not_to match /price/
expect(response.body).not_to match /memo/
expect(response.body).not_to match /bookstore_id/
expect(response.body).not_to match /budget_type_id/
end
end
end
describe 'When not logged in' do
it 'assigns all items as @items' do
get :index
expect(assigns(:items)).to_not be_nil
end
it 'should get index with agent_id' do
get :index, params: { agent_id: 1 }
expect(response).to be_successful
assigns(:agent).should eq Agent.find(1)
expect(assigns(:items)).to eq assigns(:agent).items.order('created_at DESC').page(1)
end
it 'should get index with manifestation_id' do
get :index, params: { manifestation_id: 1 }
expect(response).to be_successful
assigns(:manifestation).should eq Manifestation.find(1)
assigns(:items).collect(&:id).should eq assigns(:manifestation).items.order('items.created_at DESC').page(1).pluck(:id)
end
it 'should get index with shelf_id' do
get :index, params: { shelf_id: 1 }
expect(response).to be_successful
assigns(:shelf).should eq Shelf.find(1)
expect(assigns(:items).collect(&:id)).to eq assigns(:shelf).items.order('created_at DESC').page(1).pluck(:id)
end
describe 'in JSON response' do
render_views
it 'should not assign unnecessary attributes' do
get :index, format: :json
expect(response.body).to match /manifestation_id/
expect(response.body).not_to match /price/
expect(response.body).not_to match /memo/
expect(response.body).not_to match /bookstore_id/
expect(response.body).not_to match /budget_type_id/
end
end
end
end
describe 'GET show' do
before(:each) do
@item = FactoryBot.create(:item)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item as @item' do
get :show, params: { id: @item.id }
expect(assigns(:item)).to eq(@item)
end
it 'should not show missing item' do
lambda do
get :show, params: { id: 'missing' }
end.should raise_error(ActiveRecord::RecordNotFound)
# expect(response).to be_missing
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item as @item' do
get :show, params: { id: @item.id }
expect(assigns(:item)).to eq(@item)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested item as @item' do
get :show, params: { id: @item.id }
expect(assigns(:item)).to eq(@item)
end
end
describe 'When not logged in' do
it 'assigns the requested item as @item' do
get :show, params: { id: @item.id }
expect(assigns(:item)).to eq(@item)
end
end
end
describe 'GET new' do
before(:each) do
@manifestation = FactoryBot.create(:manifestation)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item as @item' do
get :new, params: { manifestation_id: @manifestation.id }
expect(assigns(:item)).to be_valid
expect(response).to be_successful
end
it 'should not get new without manifestation_id' do
get :new
expect(response).to redirect_to(manifestations_url)
end
it 'should work without exception, even if library and shelf is unavailable' do
Library.real.each do |library|
library.try(:shelves).to_a.each(&:destroy)
library.delete
end
get :new, params: { manifestation_id: @manifestation.id }
expect(response).to redirect_to(libraries_url)
end
it 'should not get new item for series_master' do
manifestation_serial = FactoryBot.create(:manifestation_serial)
get :new, params: { manifestation_id: manifestation_serial.id }
expect(response).to redirect_to(manifestations_url(parent_id: manifestation_serial.id))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item as @item' do
get :new, params: { manifestation_id: @manifestation.id }
expect(assigns(:item)).to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested item as @item' do
get :new, params: { manifestation_id: @manifestation.id }
expect(assigns(:item)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested item as @item' do
get :new, params: { manifestation_id: @manifestation.id }
expect(assigns(:item)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested item as @item' do
item = FactoryBot.create(:item)
get :edit, params: { id: item.id }
expect(assigns(:item)).to eq(item)
end
it 'should not edit missing item' do
lambda do
get :edit, params: { id: 'missing' }
end.should raise_error(ActiveRecord::RecordNotFound)
# expect(response).to be_missing
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested item as @item' do
item = FactoryBot.create(:item)
get :edit, params: { id: item.id }
expect(assigns(:item)).to eq(item)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested item as @item' do
item = FactoryBot.create(:item)
get :edit, params: { id: item.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested item as @item' do
item = FactoryBot.create(:item)
get :edit, params: { id: item.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
manifestation = FactoryBot.create(:manifestation)
@attrs = FactoryBot.attributes_for(:item, manifestation_id: manifestation.id)
@invalid_attrs = { item_identifier: '無効なID', manifestation_id: manifestation.id }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created item as @item' do
post :create, params: { item: @attrs }
expect(assigns(:item)).to be_valid
end
it 'redirects to the created item' do
post :create, params: { item: @attrs }
assigns(:item).manifestation.should_not be_nil
expect(response).to redirect_to(item_url(assigns(:item)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item as @item' do
post :create, params: { item: @invalid_attrs }
expect(assigns(:item)).to_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { item: @invalid_attrs }
expect(response).to render_template('new')
end
end
it 'should not create item without manifestation_id' do
lambda do
post :create, params: { item: { circulation_status_id: 1 } }
end.should raise_error(ActiveRecord::RecordNotFound)
expect(assigns(:item)).to_not be_valid
# expect(response).to be_missing
end
it 'should not create item already created' do
post :create, params: { item: { circulation_status_id: 1, item_identifier: '00001', manifestation_id: 1 } }
expect(assigns(:item)).to_not be_valid
expect(response).to be_successful
end
it 'should create item already reserved' do
post :create, params: { item: @attrs.merge(manifestation_id: 11) }
expect(assigns(:item)).to be_valid
expect(response).to redirect_to(item_url(assigns(:item)))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created item as @item' do
post :create, params: { item: @attrs }
expect(assigns(:item)).to be_valid
end
it 'redirects to the created item' do
post :create, params: { item: @attrs }
expect(response).to redirect_to(item_url(assigns(:item)))
end
it 'accepts custom values' do
post :create, params: { item: @attrs.merge(item_custom_values_attributes: Array.new(3) {FactoryBot.attributes_for(:item_custom_value, item_custom_property_id: FactoryBot.create(:item_custom_property).id)}) }
expect(assigns(:item)).to be_valid
expect(assigns(:item).item_custom_values.count).to eq 3
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item as @item' do
post :create, params: { item: @invalid_attrs }
expect(assigns(:item)).to_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { item: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created item as @item' do
post :create, params: { item: @attrs }
expect(assigns(:item)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item as @item' do
post :create, params: { item: @invalid_attrs }
expect(assigns(:item)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created item as @item' do
post :create, params: { item: @attrs }
expect(assigns(:item)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved item as @item' do
post :create, params: { item: @invalid_attrs }
expect(assigns(:item)).to be_nil
end
it 'should be forbidden' do
post :create, params: { item: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@item = FactoryBot.create(:item)
@attrs = FactoryBot.attributes_for(:item)
@invalid_attrs = { item_identifier: '無効なID' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested item' do
put :update, params: { id: @item.id, item: @attrs }
end
it 'assigns the requested item as @item' do
put :update, params: { id: @item.id, item: @attrs }
expect(assigns(:item)).to eq(@item)
end
end
describe 'with invalid params' do
it 'assigns the requested item as @item' do
put :update, params: { id: @item.id, item: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @item, item: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested item' do
put :update, params: { id: @item.id, item: @attrs }
end
it 'assigns the requested item as @item' do
put :update, params: { id: @item.id, item: @attrs }
expect(assigns(:item)).to eq(@item)
expect(response).to redirect_to(@item)
end
it 'accepts custom values' do
@item.item_custom_values << FactoryBot.build(:item_custom_value)
put :update, params: { id: @item.id, item: @attrs.merge(item_custom_values_attributes: [ { id: @item.item_custom_values.first.id, value: 'test' } ]) }
expect(assigns(:item)).to be_valid
expect(assigns(:item).item_custom_values.count).to eq 1
expect(assigns(:item).item_custom_values.first.value).to eq 'test'
end
it 'accepts custom values when the value is empty' do
@item.item_custom_values << FactoryBot.build(:item_custom_value)
put :update, params: { id: @item.id, item: @attrs.merge(item_custom_values_attributes: [ { id: @item.item_custom_values.first.id, value: '' } ]) }
expect(assigns(:item)).to be_valid
expect(assigns(:item).item_custom_values.count).to eq 1
expect(assigns(:item).item_custom_values.first.value).to eq ''
end
end
describe 'with invalid params' do
it 'assigns the item as @item' do
put :update, params: { id: @item, item: @invalid_attrs }
expect(assigns(:item)).to_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @item, item: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested item' do
put :update, params: { id: @item.id, item: @attrs }
end
it 'assigns the requested item as @item' do
put :update, params: { id: @item.id, item: @attrs }
expect(assigns(:item)).to eq(@item)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested item as @item' do
put :update, params: { id: @item.id, item: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested item' do
put :update, params: { id: @item.id, item: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @item.id, item: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested item as @item' do
put :update, params: { id: @item.id, item: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@item = FactoryBot.create(:item)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested item' do
delete :destroy, params: { id: @item.id }
end
it 'redirects to the items list' do
manifestation = @item.manifestation
delete :destroy, params: { id: @item.id }
expect(response).to redirect_to(items_url(manifestation_id: manifestation.id))
end
it 'should not destroy missing item' do
lambda do
delete :destroy, params: { id: 'missing' }
end.should raise_error(ActiveRecord::RecordNotFound)
# expect(response).to be_missing
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested item' do
delete :destroy, params: { id: @item.id }
end
it 'redirects to the items list' do
manifestation = @item.manifestation
delete :destroy, params: { id: @item.id }
expect(response).to redirect_to(items_url(manifestation_id: manifestation.id))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested item' do
delete :destroy, params: { id: @item.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested item' do
delete :destroy, params: { id: @item.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @item.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/classification_types_controller_spec.rb | spec/controllers/classification_types_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ClassificationTypesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:classification_type)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:classification_type)
end
describe 'When logged in as Administrator' do
login_admin
it 'assigns all classification_types as @classification_types' do
get :index
expect(assigns(:classification_types)).to eq(ClassificationType.order(:position))
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns all classification_types as @classification_types' do
get :index
expect(assigns(:classification_types)).to eq(ClassificationType.order(:position))
end
end
describe 'When logged in as User' do
login_user
it 'assigns all classification_types as @classification_types' do
get :index
expect(assigns(:classification_types)).to eq(ClassificationType.order(:position))
end
end
describe 'When not logged in' do
it 'assigns all classification_types as @classification_types' do
get :index
expect(assigns(:classification_types)).to eq(ClassificationType.order(:position))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :show, params: { id: classification_type.id }
expect(assigns(:classification_type)).to eq(classification_type)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :show, params: { id: classification_type.id }
expect(assigns(:classification_type)).to eq(classification_type)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :show, params: { id: classification_type.id }
expect(assigns(:classification_type)).to eq(classification_type)
end
end
describe 'When not logged in' do
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :show, params: { id: classification_type.id }
expect(assigns(:classification_type)).to eq(classification_type)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested classification_type as @classification_type' do
get :new
expect(assigns(:classification_type)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'should not assign the requested classification_type as @classification_type' do
get :new
expect(assigns(:classification_type)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'should not assign the requested classification_type as @classification_type' do
get :new
expect(assigns(:classification_type)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested classification_type as @classification_type' do
get :new
expect(assigns(:classification_type)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :edit, params: { id: classification_type.id }
expect(assigns(:classification_type)).to eq(classification_type)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :edit, params: { id: classification_type.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :edit, params: { id: classification_type.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested classification_type as @classification_type' do
classification_type = FactoryBot.create(:classification_type)
get :edit, params: { id: classification_type.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'assigns a newly created classification_type as @classification_type' do
post :create, params: { classification_type: @attrs }
expect(assigns(:classification_type)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { classification_type: @attrs }
expect(response).to redirect_to(assigns(:classification_type))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved classification_type as @classification_type' do
post :create, params: { classification_type: @invalid_attrs }
expect(assigns(:classification_type)).not_to be_valid
end
it 'should be successful' do
post :create, params: { classification_type: @invalid_attrs }
expect(response).to be_successful
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'assigns a newly created classification_type as @classification_type' do
post :create, params: { classification_type: @attrs }
expect(assigns(:classification_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { classification_type: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved classification_type as @classification_type' do
post :create, params: { classification_type: @invalid_attrs }
expect(assigns(:classification_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { classification_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'assigns a newly created classification_type as @classification_type' do
post :create, params: { classification_type: @attrs }
expect(assigns(:classification_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { classification_type: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved classification_type as @classification_type' do
post :create, params: { classification_type: @invalid_attrs }
expect(assigns(:classification_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { classification_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created classification_type as @classification_type' do
post :create, params: { classification_type: @attrs }
expect(assigns(:classification_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { classification_type: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved classification_type as @classification_type' do
post :create, params: { classification_type: @invalid_attrs }
expect(assigns(:classification_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { classification_type: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@classification_type = FactoryBot.create(:classification_type)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'updates the requested classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
end
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
expect(assigns(:classification_type)).to eq(@classification_type)
end
it 'moves its position when specified' do
put :update, params: { id: @classification_type.id, classification_type: @attrs, move: 'lower' }
expect(response).to redirect_to(classification_types_url)
end
end
describe 'with invalid params' do
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'updates the requested classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
end
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
expect(assigns(:classification_type)).to eq(@classification_type)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'updates the requested classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
end
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
expect(assigns(:classification_type)).to eq(@classification_type)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @classification_type.id, classification_type: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested classification_type as @classification_type' do
put :update, params: { id: @classification_type.id, classification_type: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@classification_type = FactoryBot.create(:classification_type)
end
describe 'When logged in as Administrator' do
login_admin
it 'destroys the requested classification_type' do
delete :destroy, params: { id: @classification_type.id }
end
it 'redirects to the classification_types list' do
delete :destroy, params: { id: @classification_type.id }
expect(response).to redirect_to(classification_types_url)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'destroys the requested classification_type' do
delete :destroy, params: { id: @classification_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @classification_type.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'destroys the requested classification_type' do
delete :destroy, params: { id: @classification_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @classification_type.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested classification_type' do
delete :destroy, params: { id: @classification_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @classification_type.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/page_controller_spec.rb | spec/controllers/page_controller_spec.rb | require 'rails_helper'
describe PageController do
fixtures :all
describe "GET page" do
describe "When logged in as Librarian" do
login_fixture_librarian
it "should get import" do
get :import
expect(response).to be_successful
end
it "should get configuration" do
get :configuration
expect(response).to be_successful
end
it "should get system information" do
get :system_information
expect(response).to be_successful
end
end
describe "When logged in as User" do
login_fixture_user
it "should redirect to user" do
get :index
expect(response).to be_successful
end
it "should not get import" do
get :import
expect(response).to be_forbidden
end
it "should not get configuration" do
get :configuration
expect(response).to be_forbidden
end
it "should not get system information" do
get :system_information
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should get index" do
get :index
expect(response).to be_successful
end
it "should get opensearch" do
get :opensearch, format: :xml
expect(response).to be_successful
end
it "should get routing_error" do
get :routing_error
expect(response).to be_not_found
expect(response).to render_template("page/404")
end
it "should get advanced_search" do
get :advanced_search
expect(response).to be_successful
expect(assigns(:libraries)).to eq Library.order(:position)
end
it "should get about" do
get :about
expect(response).to be_successful
end
it "should get statistics" do
get :statistics
expect(response).to be_successful
end
it "should not get import" do
get :import
expect(response).to redirect_to new_user_session_url
end
it "should not get configuration" do
get :configuration
expect(response).to redirect_to new_user_session_url
end
it "should not get system information" do
get :system_information
expect(response).to redirect_to new_user_session_url
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/user_reserve_stats_controller_spec.rb | spec/controllers/user_reserve_stats_controller_spec.rb | require 'rails_helper'
describe UserReserveStatsController do
fixtures :all
describe 'GET index' do
before(:each) do
FactoryBot.create(:user_reserve_stat)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all user_reserve_stats as @user_reserve_stats' do
get :index
assigns(:user_reserve_stats).should eq(UserReserveStat.order('id DESC').page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all user_reserve_stats as @user_reserve_stats' do
get :index
assigns(:user_reserve_stats).should eq(UserReserveStat.order('id DESC').page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all user_reserve_stats as @user_reserve_stats' do
get :index
assigns(:user_reserve_stats).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign user_reserve_stats as @user_reserve_stats' do
get :index
assigns(:user_reserve_stats).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :show, params: { id: user_reserve_stat.id }
assigns(:user_reserve_stat).should eq(user_reserve_stat)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :show, params: { id: user_reserve_stat.id }
assigns(:user_reserve_stat).should eq(user_reserve_stat)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :show, params: { id: user_reserve_stat.id }
assigns(:user_reserve_stat).should eq(user_reserve_stat)
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :show, params: { id: user_reserve_stat.id }
assigns(:user_reserve_stat).should eq(user_reserve_stat)
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
get :new
assigns(:user_reserve_stat).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
get :new
assigns(:user_reserve_stat).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested user_reserve_stat as @user_reserve_stat' do
get :new
assigns(:user_reserve_stat).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested user_reserve_stat as @user_reserve_stat' do
get :new
assigns(:user_reserve_stat).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :edit, params: { id: user_reserve_stat.id }
assigns(:user_reserve_stat).should eq(user_reserve_stat)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :edit, params: { id: user_reserve_stat.id }
assigns(:user_reserve_stat).should eq(user_reserve_stat)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :edit, params: { id: user_reserve_stat.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested user_reserve_stat as @user_reserve_stat' do
user_reserve_stat = FactoryBot.create(:user_reserve_stat)
get :edit, params: { id: user_reserve_stat.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:user_reserve_stat)
@invalid_attrs = { start_date: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should be_valid
end
it 'redirects to the created user_reserve_stat' do
post :create, params: { user_reserve_stat: @attrs }
response.should redirect_to(user_reserve_stat_url(assigns(:user_reserve_stat)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @invalid_attrs }
assigns(:user_reserve_stat).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { user_reserve_stat: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should be_valid
end
it 'redirects to the created user_reserve_stat' do
post :create, params: { user_reserve_stat: @attrs }
response.should redirect_to(user_reserve_stat_url(assigns(:user_reserve_stat)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @invalid_attrs }
assigns(:user_reserve_stat).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { user_reserve_stat: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_reserve_stat: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @invalid_attrs }
assigns(:user_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_reserve_stat: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_reserve_stat: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_reserve_stat as @user_reserve_stat' do
post :create, params: { user_reserve_stat: @invalid_attrs }
assigns(:user_reserve_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_reserve_stat: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@user_reserve_stat = FactoryBot.create(:user_reserve_stat)
@attrs = FactoryBot.attributes_for(:user_reserve_stat)
@invalid_attrs = { start_date: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
end
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should eq(@user_reserve_stat)
end
end
describe 'with invalid params' do
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
end
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should eq(@user_reserve_stat)
response.should redirect_to(@user_reserve_stat)
end
end
describe 'with invalid params' do
it 'assigns the user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat, user_reserve_stat: @invalid_attrs }
assigns(:user_reserve_stat).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @user_reserve_stat, user_reserve_stat: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
end
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
assigns(:user_reserve_stat).should eq(@user_reserve_stat)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested user_reserve_stat as @user_reserve_stat' do
put :update, params: { id: @user_reserve_stat.id, user_reserve_stat: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@user_reserve_stat = FactoryBot.create(:user_reserve_stat)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested user_reserve_stat' do
delete :destroy, params: { id: @user_reserve_stat.id }
end
it 'redirects to the user_reserve_stats list' do
delete :destroy, params: { id: @user_reserve_stat.id }
response.should redirect_to(user_reserve_stats_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested user_reserve_stat' do
delete :destroy, params: { id: @user_reserve_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_reserve_stat.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested user_reserve_stat' do
delete :destroy, params: { id: @user_reserve_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_reserve_stat.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested user_reserve_stat' do
delete :destroy, params: { id: @user_reserve_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_reserve_stat.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/languages_controller_spec.rb | spec/controllers/languages_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe LanguagesController do
disconnect_sunspot
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:language)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:language)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all languages as @languages' do
get :index
expect(assigns(:languages)).to eq(Language.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all languages as @languages' do
get :index
expect(assigns(:languages)).to eq(Language.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all languages as @languages' do
get :index
expect(assigns(:languages)).to eq(Language.page(1))
end
end
describe 'When not logged in' do
it 'assigns all languages as @languages' do
get :index
expect(assigns(:languages)).to eq(Language.page(1))
end
end
end
describe 'GET show' do
before(:each) do
@language = FactoryBot.create(:language)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested language as @language' do
get :show, params: { id: @language.id }
expect(assigns(:language)).to eq(@language)
end
end
describe 'When not logged in' do
it 'assigns the requested language as @language' do
get :show, params: { id: @language.id }
expect(assigns(:language)).to eq(@language)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested language as @language' do
get :new
expect(assigns(:language)).to_not be_valid
end
end
describe 'When not logged in' do
it 'should not assign the requested language as @language' do
get :new
expect(assigns(:language)).to be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
before(:each) do
@language = FactoryBot.create(:language)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested language as @language' do
get :edit, params: { id: @language.id }
expect(assigns(:language)).to eq(@language)
end
end
describe 'When not logged in' do
it 'should not assign the requested language as @language' do
get :edit, params: { id: @language.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created language as @language' do
post :create, params: { language: @attrs }
expect(assigns(:language)).to be_valid
end
it 'redirects to the created language' do
post :create, params: { language: @attrs }
response.should redirect_to(assigns(:language))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved language as @language' do
post :create, params: { language: @invalid_attrs }
expect(assigns(:language)).to_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { language: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created language as @language' do
post :create, params: { language: @attrs }
expect(assigns(:language)).to be_nil
end
it 'should be forbidden' do
post :create, params: { language: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved language as @language' do
post :create, params: { language: @invalid_attrs }
expect(assigns(:language)).to be_nil
end
it 'should be forbidden' do
post :create, params: { language: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created language as @language' do
post :create, params: { language: @attrs }
expect(assigns(:language)).to be_nil
end
it 'should be forbidden' do
post :create, params: { language: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved language as @language' do
post :create, params: { language: @invalid_attrs }
expect(assigns(:language)).to be_nil
end
it 'should be forbidden' do
post :create, params: { language: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created language as @language' do
post :create, params: { language: @attrs }
expect(assigns(:language)).to be_nil
end
it 'should be forbidden' do
post :create, params: { language: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved language as @language' do
post :create, params: { language: @invalid_attrs }
expect(assigns(:language)).to be_nil
end
it 'should be forbidden' do
post :create, params: { language: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@language = FactoryBot.create(:language)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested language' do
put :update, params: { id: @language.id, language: @attrs }
end
it 'assigns the requested language as @language' do
put :update, params: { id: @language.id, language: @attrs }
expect(assigns(:language)).to eq(@language)
end
it 'moves its position when specified' do
put :update, params: { id: @language.id, language: @attrs, move: 'lower' }
response.should redirect_to(languages_url)
end
end
describe 'with invalid params' do
it 'assigns the requested language as @language' do
put :update, params: { id: @language.id, language: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested language' do
put :update, params: { id: @language.id, language: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @language.id, language: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested language as @language' do
put :update, params: { id: @language.id, language: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@language = FactoryBot.create(:language)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested language' do
delete :destroy, params: { id: @language.id }
end
it 'redirects to the languagees list' do
delete :destroy, params: { id: @language.id }
response.should redirect_to(languages_url)
end
end
describe 'When not logged in' do
it 'destroys the requested language' do
delete :destroy, params: { id: @language.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @language.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_import_results_controller_spec.rb | spec/controllers/agent_import_results_controller_spec.rb | require 'rails_helper'
describe AgentImportResultsController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all agent_import_results as @agent_import_results' do
get :index
expect(assigns(:agent_import_results)).to eq(AgentImportResult.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all agent_import_results as @agent_import_results' do
get :index
expect(assigns(:agent_import_results)).to eq(AgentImportResult.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns empty as @agent_import_results' do
get :index
expect(assigns(:agent_import_results)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @agent_import_results' do
get :index
expect(assigns(:agent_import_results)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_import_result as @agent_import_result' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_result)).to eq(AgentImportResult.find(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_import_result as @agent_import_result' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_result)).to eq(AgentImportResult.find(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_import_result as @agent_import_result' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_result)).to eq(AgentImportResult.find(1))
end
end
describe 'When not logged in' do
it 'assigns the requested agent_import_result as @agent_import_result' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_result)).to eq(AgentImportResult.find(1))
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/manifestation_custom_properties_controller_spec.rb | spec/controllers/manifestation_custom_properties_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ManifestationCustomPropertiesController do
fixtures :all
disconnect_sunspot
def valid_attributes
@attrs = FactoryBot.attributes_for(:manifestation_custom_property)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:manifestation_custom_property)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all manifestation_custom_properties as @manifestation_custom_properties' do
get :index
expect(assigns(:manifestation_custom_properties)).to eq(ManifestationCustomProperty.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all manifestation_custom_properties as @manifestation_custom_properties' do
get :index
expect(assigns(:manifestation_custom_properties)).to eq(ManifestationCustomProperty.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all manifestation_custom_properties as @manifestation_custom_properties' do
get :index
expect(assigns(:manifestation_custom_properties)).to eq nil
end
end
describe 'When not logged in' do
it 'assigns all manifestation_custom_properties as @manifestation_custom_properties' do
get :index
expect(assigns(:manifestation_custom_properties)).to eq nil
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :show, params: { id: manifestation_custom_property.id }
expect(assigns(:manifestation_custom_property)).to eq(manifestation_custom_property)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :show, params: { id: manifestation_custom_property.id }
expect(assigns(:manifestation_custom_property)).to eq(manifestation_custom_property)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :show, params: { id: manifestation_custom_property.id }
expect(assigns(:manifestation_custom_property)).to eq(manifestation_custom_property)
end
end
describe 'When not logged in' do
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :show, params: { id: manifestation_custom_property.id }
expect(assigns(:manifestation_custom_property)).to eq(manifestation_custom_property)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
get :new
expect(assigns(:manifestation_custom_property)).to be_a_new(ManifestationCustomProperty)
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested manifestation_custom_property as @manifestation_custom_property' do
get :new
expect(assigns(:manifestation_custom_property)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested manifestation_custom_property as @manifestation_custom_property' do
get :new
expect(assigns(:manifestation_custom_property)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_custom_property as @manifestation_custom_property' do
get :new
expect(assigns(:manifestation_custom_property)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :edit, params: { id: manifestation_custom_property.id }
expect(assigns(:manifestation_custom_property)).to eq(manifestation_custom_property)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :edit, params: { id: manifestation_custom_property.id }
expect(assigns(:manifestation_custom_property)).to eq(manifestation_custom_property)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :edit, params: { id: manifestation_custom_property.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_custom_property as @manifestation_custom_property' do
manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
get :edit, params: { id: manifestation_custom_property.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to be_valid
end
it 'redirects to the created manifestation' do
post :create, params: { manifestation_custom_property: @attrs }
expect(response).to redirect_to(assigns(:manifestation_custom_property))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(assigns(:manifestation_custom_property)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to be_nil
end
it 'redirects to the created manifestation' do
post :create, params: { manifestation_custom_property: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(assigns(:manifestation_custom_property)).to be_nil
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_custom_property: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(assigns(:manifestation_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_custom_property: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_custom_property as @manifestation_custom_property' do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(assigns(:manifestation_custom_property)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_custom_property: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
end
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to eq(@manifestation_custom_property)
expect(response).to redirect_to(@manifestation_custom_property)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @invalid_attrs }
expect(response).to render_template('edit')
end
end
it 'moves its position when specified' do
manifestation_custom_property = ManifestationCustomProperty.create! valid_attributes
position = manifestation_custom_property.position
put :update, params: { id: manifestation_custom_property.id, move: 'higher' }
expect(response).to redirect_to manifestation_custom_properties_url
assigns(:manifestation_custom_property).reload.position.should eq position - 1
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
end
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to eq @manifestation_custom_property
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
end
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
expect(assigns(:manifestation_custom_property)).to eq(@manifestation_custom_property)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_custom_property as @manifestation_custom_property' do
put :update, params: { id: @manifestation_custom_property.id, manifestation_custom_property: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@manifestation_custom_property = FactoryBot.create(:manifestation_custom_property)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested manifestation_custom_property' do
delete :destroy, params: { id: @manifestation_custom_property.id }
end
it 'redirects to the manifestation_custom_properties list' do
delete :destroy, params: { id: @manifestation_custom_property.id }
expect(response).to redirect_to(manifestation_custom_properties_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested manifestation_custom_property' do
delete :destroy, params: { id: @manifestation_custom_property.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_custom_property.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested manifestation_custom_property' do
delete :destroy, params: { id: @manifestation_custom_property.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_custom_property.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested manifestation_custom_property' do
delete :destroy, params: { id: @manifestation_custom_property.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_custom_property.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/user_group_has_checkout_types_controller_spec.rb | spec/controllers/user_group_has_checkout_types_controller_spec.rb | require 'rails_helper'
describe UserGroupHasCheckoutTypesController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all user_group_has_checkout_types as @user_group_has_checkout_types' do
get :index
assigns(:user_group_has_checkout_types).should eq(UserGroupHasCheckoutType.includes([ :user_group, :checkout_type ]).order('user_groups.position, checkout_types.position').page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all user_group_has_checkout_types as @user_group_has_checkout_types' do
get :index
assigns(:user_group_has_checkout_types).should eq(UserGroupHasCheckoutType.includes([ :user_group, :checkout_type ]).order('user_groups.position, checkout_types.position').page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all user_group_has_checkout_types as @user_group_has_checkout_types' do
get :index
assigns(:user_group_has_checkout_types).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns all user_group_has_checkout_types as @user_group_has_checkout_types' do
get :index
assigns(:user_group_has_checkout_types).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :show, params: { id: user_group_has_checkout_type.id }
assigns(:user_group_has_checkout_type).should eq(user_group_has_checkout_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :show, params: { id: user_group_has_checkout_type.id }
assigns(:user_group_has_checkout_type).should eq(user_group_has_checkout_type)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :show, params: { id: user_group_has_checkout_type.id }
assigns(:user_group_has_checkout_type).should eq(user_group_has_checkout_type)
end
end
describe 'When not logged in' do
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :show, params: { id: user_group_has_checkout_type.id }
assigns(:user_group_has_checkout_type).should eq(user_group_has_checkout_type)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
get :new
assigns(:user_group_has_checkout_type).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
get :new
assigns(:user_group_has_checkout_type).should be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
get :new
assigns(:user_group_has_checkout_type).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
get :new
assigns(:user_group_has_checkout_type).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :edit, params: { id: user_group_has_checkout_type.id }
assigns(:user_group_has_checkout_type).should eq(user_group_has_checkout_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :edit, params: { id: user_group_has_checkout_type.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :edit, params: { id: user_group_has_checkout_type.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
get :edit, params: { id: user_group_has_checkout_type.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:user_group_has_checkout_type)
@invalid_attrs = { user_group_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should be_valid
end
it 'redirects to the created patron' do
post :create, params: { user_group_has_checkout_type: @attrs }
response.should redirect_to(assigns(:user_group_has_checkout_type))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
assigns(:user_group_has_checkout_type).should_not be_valid
end
it 'should be successful' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group_has_checkout_type: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
assigns(:user_group_has_checkout_type).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group_has_checkout_type: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
assigns(:user_group_has_checkout_type).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group_has_checkout_type: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved user_group_has_checkout_type as @user_group_has_checkout_type' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
assigns(:user_group_has_checkout_type).should be_nil
end
it 'should be forbidden' do
post :create, params: { user_group_has_checkout_type: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
@attrs = FactoryBot.attributes_for(:user_group_has_checkout_type)
@invalid_attrs = { user_group_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
end
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should eq(@user_group_has_checkout_type)
end
end
describe 'with invalid params' do
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
end
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should eq(@user_group_has_checkout_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
end
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
assigns(:user_group_has_checkout_type).should eq(@user_group_has_checkout_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested user_group_has_checkout_type as @user_group_has_checkout_type' do
put :update, params: { id: @user_group_has_checkout_type.id, user_group_has_checkout_type: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@user_group_has_checkout_type = FactoryBot.create(:user_group_has_checkout_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested user_group_has_checkout_type' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
end
it 'redirects to the user_group_has_checkout_types list' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
response.should redirect_to(user_group_has_checkout_types_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested user_group_has_checkout_type' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested user_group_has_checkout_type' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested user_group_has_checkout_type' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_group_has_checkout_type.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/event_import_files_controller_spec.rb | spec/controllers/event_import_files_controller_spec.rb | require 'rails_helper'
describe EventImportFilesController do
fixtures :all
describe "GET index" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all event_import_files as @event_import_files" do
get :index
assigns(:event_import_files).should eq(EventImportFile.order(created_at: :desc).page(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all event_import_files as @event_import_files" do
get :index
assigns(:event_import_files).should eq(EventImportFile.order(created_at: :desc).page(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns empty as @event_import_files" do
get :index
assigns(:event_import_files).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "assigns empty as @event_import_files" do
get :index
assigns(:event_import_files).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_import_file as @event_import_file" do
get :show, params: { id: 1 }
assigns(:event_import_file).should eq(EventImportFile.find(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event_import_file as @event_import_file" do
get :show, params: { id: 1 }
assigns(:event_import_file).should eq(EventImportFile.find(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event_import_file as @event_import_file" do
get :show, params: { id: 1 }
assigns(:event_import_file).should eq(EventImportFile.find(1))
end
end
describe "When not logged in" do
it "assigns the requested event_import_file as @event_import_file" do
get :show, params: { id: 1 }
assigns(:event_import_file).should eq(EventImportFile.find(1))
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_import_file as @event_import_file" do
get :new
assigns(:event_import_file).should_not be_valid
response.should be_successful
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "should not assign the requested event_import_file as @event_import_file" do
get :new
assigns(:event_import_file).should_not be_valid
response.should be_successful
end
end
describe "When logged in as User" do
login_fixture_user
it "should not assign the requested event_import_file as @event_import_file" do
get :new
assigns(:event_import_file).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested event_import_file as @event_import_file" do
get :new
assigns(:event_import_file).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
describe "When logged in as Librarian" do
login_fixture_librarian
it "should create event_import_file" do
post :create, params: { event_import_file: { attachment: fixture_file_upload("event_import_file_sample1.tsv", 'text/csv') } }
assigns(:event_import_file).should be_valid
assigns(:event_import_file).user.username.should eq @user.username
response.should redirect_to event_import_file_url(assigns(:event_import_file))
end
it "should import user" do
old_events_count = Event.count
post :create, params: { event_import_file: { attachment: fixture_file_upload("event_import_file_sample2.tsv", 'text/csv'), default_library_id: 3, default_event_category_id: 3 } }
assigns(:event_import_file).import_start
Event.count.should eq old_events_count + 2
response.should redirect_to event_import_file_url(assigns(:event_import_file))
end
end
describe "When logged in as User" do
login_fixture_user
it "should be forbidden" do
post :create, params: { event_import_file: { attachment: fixture_file_upload("event_import_file_sample1.tsv", 'text/csv') } }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should be redirect to new session url" do
post :create, params: { event_import_file: { attachment: fixture_file_upload("event_import_file_sample1.tsv", 'text/csv') } }
response.should redirect_to new_user_session_url
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event_import_file as @event_import_file" do
event_import_file = event_import_files(:event_import_file_00001)
get :edit, params: { id: event_import_file.id }
assigns(:event_import_file).should eq(event_import_file)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event_import_file as @event_import_file" do
event_import_file = event_import_files(:event_import_file_00001)
get :edit, params: { id: event_import_file.id }
assigns(:event_import_file).should eq(event_import_file)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event_import_file as @event_import_file" do
event_import_file = event_import_files(:event_import_file_00001)
get :edit, params: { id: event_import_file.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested event_import_file as @event_import_file" do
event_import_file = event_import_files(:event_import_file_00001)
get :edit, params: { id: event_import_file.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe "PUT update" do
describe "When logged in as Librarian" do
login_fixture_librarian
it "should update event_import_file" do
put :update, params: { id: event_import_files(:event_import_file_00003).id, event_import_file: { edit_mode: 'update' } }
response.should redirect_to event_import_file_url(assigns(:event_import_file))
end
end
describe "When logged in as User" do
login_fixture_user
it "should not update event_import_file" do
put :update, params: { id: event_import_files(:event_import_file_00003).id, event_import_file: {} }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not update event_import_file" do
put :update, params: { id: event_import_files(:event_import_file_00003).id, event_import_file: {} }
response.should redirect_to new_user_session_url
end
end
end
describe "DELETE destroy" do
before(:each) do
@event_import_file = event_import_files(:event_import_file_00001)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested event_import_file" do
delete :destroy, params: { id: @event_import_file.id }
end
it "redirects to the event_import_files list" do
delete :destroy, params: { id: @event_import_file.id }
response.should redirect_to(event_import_files_url)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested event_import_file" do
delete :destroy, params: { id: @event_import_file.id }
end
it "redirects to the event_import_files list" do
delete :destroy, params: { id: @event_import_file.id }
response.should redirect_to(event_import_files_url)
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested event_import_file" do
delete :destroy, params: { id: @event_import_file.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event_import_file.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested event_import_file" do
delete :destroy, params: { id: @event_import_file.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event_import_file.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/countries_controller_spec.rb | spec/controllers/countries_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe CountriesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:country)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:country)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all countries as @countries' do
get :index
assigns(:countries).should eq(Country.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all countries as @countries' do
get :index
assigns(:countries).should eq(Country.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all countries as @countries' do
get :index
assigns(:countries).should eq(Country.page(1))
end
end
describe 'When not logged in' do
it 'assigns all countries as @countries' do
get :index
assigns(:countries).should eq(Country.page(1))
end
end
end
describe 'GET show' do
before(:each) do
@country = FactoryBot.create(:country)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested country as @country' do
get :show, params: { id: @country.id }
assigns(:country).should eq(@country)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested country as @country' do
get :show, params: { id: @country.id }
assigns(:country).should eq(@country)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested country as @country' do
get :show, params: { id: @country.id }
assigns(:country).should eq(@country)
end
end
describe 'When not logged in' do
it 'assigns the requested country as @country' do
get :show, params: { id: @country.id }
assigns(:country).should eq(@country)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested country as @country' do
get :new
assigns(:country).should_not be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested country as @country' do
get :new
assigns(:country).should be_nil
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested country as @country' do
get :new
assigns(:country).should be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested country as @country' do
get :new
assigns(:country).should be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested country as @country' do
country = FactoryBot.create(:country)
get :edit, params: { id: country.id }
assigns(:country).should eq(country)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested country as @country' do
country = FactoryBot.create(:country)
get :edit, params: { id: country.id }
assigns(:country).should eq(country)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested country as @country' do
country = FactoryBot.create(:country)
get :edit, params: { id: country.id }
assigns(:country).should eq(country)
end
end
describe 'When not logged in' do
it 'should not assign the requested country as @country' do
country = FactoryBot.create(:country)
get :edit, params: { id: country.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created country as @country' do
post :create, params: { country: @attrs }
assigns(:country).should be_valid
end
it 'redirects to the created country' do
post :create, params: { country: @attrs }
expect(response).to redirect_to(assigns(:country))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved country as @country' do
post :create, params: { country: @invalid_attrs }
assigns(:country).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { country: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created country as @country' do
post :create, params: { country: @attrs }
assigns(:country).should be_nil
end
it 'should be forbidden' do
post :create, params: { country: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved country as @country' do
post :create, params: { country: @invalid_attrs }
assigns(:country).should be_nil
end
it 'should be forbidden' do
post :create, params: { country: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created country as @country' do
post :create, params: { country: @attrs }
assigns(:country).should be_nil
end
it 'should be forbidden' do
post :create, params: { country: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved country as @country' do
post :create, params: { country: @invalid_attrs }
assigns(:country).should be_nil
end
it 'should be forbidden' do
post :create, params: { country: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created country as @country' do
post :create, params: { country: @attrs }
assigns(:country).should be_nil
end
it 'should be forbidden' do
post :create, params: { country: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved country as @country' do
post :create, params: { country: @invalid_attrs }
assigns(:country).should be_nil
end
it 'should be forbidden' do
post :create, params: { country: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@country = FactoryBot.create(:country)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested country' do
put :update, params: { id: @country.id, country: @attrs }
end
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @attrs }
assigns(:country).should eq(@country)
end
it 'moves its position when specified' do
put :update, params: { id: @country.id, country: @attrs, move: 'lower' }
expect(response).to redirect_to(countries_url)
end
end
describe 'with invalid params' do
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested country' do
put :update, params: { id: @country.id, country: @attrs }
end
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @attrs }
assigns(:country).should eq(@country)
end
it 'moves its position when specified' do
put :update, params: { id: @country.id, country: @attrs, move: 'lower' }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested country' do
put :update, params: { id: @country.id, country: @attrs }
end
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @attrs }
assigns(:country).should eq(@country)
end
it 'moves its position when specified' do
put :update, params: { id: @country.id, country: @attrs, move: 'lower' }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested country' do
put :update, params: { id: @country.id, country: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @country.id, country: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested country as @country' do
put :update, params: { id: @country.id, country: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@country = FactoryBot.create(:country)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested country' do
delete :destroy, params: { id: @country.id }
end
it 'redirects to the countries list' do
delete :destroy, params: { id: @country.id }
expect(response).to redirect_to(countries_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested country' do
delete :destroy, params: { id: @country.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @country.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested country' do
delete :destroy, params: { id: @country.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @country.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested country' do
delete :destroy, params: { id: @country.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @country.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/manifestation_checkout_stats_controller_spec.rb | spec/controllers/manifestation_checkout_stats_controller_spec.rb | require 'rails_helper'
describe ManifestationCheckoutStatsController do
fixtures :all
describe 'GET index' do
before(:each) do
FactoryBot.create(:manifestation_checkout_stat)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all manifestation_checkout_stats as @manifestation_checkout_stats' do
get :index
assigns(:manifestation_checkout_stats).should eq(ManifestationCheckoutStat.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all manifestation_checkout_stats as @manifestation_checkout_stats' do
get :index
assigns(:manifestation_checkout_stats).should eq(ManifestationCheckoutStat.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all manifestation_checkout_stats as @manifestation_checkout_stats' do
get :index
assigns(:manifestation_checkout_stats).should eq(ManifestationCheckoutStat.page(1))
end
end
describe 'When not logged in' do
it 'should not assign manifestation_checkout_stats as @manifestation_checkout_stats' do
get :index
assigns(:manifestation_checkout_stats).should eq(ManifestationCheckoutStat.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :show, params: { id: manifestation_checkout_stat.id }
assigns(:manifestation_checkout_stat).should eq(manifestation_checkout_stat)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :show, params: { id: manifestation_checkout_stat.id }
assigns(:manifestation_checkout_stat).should eq(manifestation_checkout_stat)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :show, params: { id: manifestation_checkout_stat.id }
assigns(:manifestation_checkout_stat).should eq(manifestation_checkout_stat)
end
end
describe 'When not logged in' do
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :show, params: { id: manifestation_checkout_stat.id }
assigns(:manifestation_checkout_stat).should eq(manifestation_checkout_stat)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
get :new
assigns(:manifestation_checkout_stat).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
get :new
assigns(:manifestation_checkout_stat).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
get :new
assigns(:manifestation_checkout_stat).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
get :new
assigns(:manifestation_checkout_stat).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :edit, params: { id: manifestation_checkout_stat.id }
assigns(:manifestation_checkout_stat).should eq(manifestation_checkout_stat)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :edit, params: { id: manifestation_checkout_stat.id }
assigns(:manifestation_checkout_stat).should eq(manifestation_checkout_stat)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :edit, params: { id: manifestation_checkout_stat.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
get :edit, params: { id: manifestation_checkout_stat.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:manifestation_checkout_stat)
@invalid_attrs = { start_date: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should be_valid
# assigns(:manifestation_checkout_stat).current_state.should eq 'completed'
end
it 'redirects to the created manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @attrs }
response.should redirect_to(manifestation_checkout_stat_url(assigns(:manifestation_checkout_stat)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
assigns(:manifestation_checkout_stat).should_not be_valid
assigns(:manifestation_checkout_stat).current_state.should eq 'pending'
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should be_valid
end
it 'redirects to the created manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @attrs }
response.should redirect_to(manifestation_checkout_stat_url(assigns(:manifestation_checkout_stat)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
assigns(:manifestation_checkout_stat).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_checkout_stat: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
assigns(:manifestation_checkout_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_checkout_stat: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_checkout_stat as @manifestation_checkout_stat' do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
assigns(:manifestation_checkout_stat).should be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_checkout_stat: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
@attrs = FactoryBot.attributes_for(:manifestation_checkout_stat)
@invalid_attrs = { start_date: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
end
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should eq(@manifestation_checkout_stat)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
end
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should eq(@manifestation_checkout_stat)
response.should redirect_to(@manifestation_checkout_stat)
end
end
describe 'with invalid params' do
it 'assigns the manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat, manifestation_checkout_stat: @invalid_attrs }
assigns(:manifestation_checkout_stat).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @manifestation_checkout_stat, manifestation_checkout_stat: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
end
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
assigns(:manifestation_checkout_stat).should eq(@manifestation_checkout_stat)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_checkout_stat as @manifestation_checkout_stat' do
put :update, params: { id: @manifestation_checkout_stat.id, manifestation_checkout_stat: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@manifestation_checkout_stat = FactoryBot.create(:manifestation_checkout_stat)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested manifestation_checkout_stat' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
end
it 'redirects to the manifestation_checkout_stats list' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
response.should redirect_to(manifestation_checkout_stats_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested manifestation_checkout_stat' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
end
it 'redirects to the manifestation_checkout_stats list' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
response.should redirect_to(manifestation_checkout_stats_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested manifestation_checkout_stat' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested manifestation_checkout_stat' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_checkout_stat.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/budget_types_controller_spec.rb | spec/controllers/budget_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe BudgetTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# BudgetType. As you add validations to BudgetType, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:budget_type)
end
describe 'GET index' do
it 'assigns all budget_types as @budget_types' do
budget_type = BudgetType.create! valid_attributes
get :index
assigns(:budget_types).should eq(BudgetType.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested budget_type as @budget_type' do
budget_type = BudgetType.create! valid_attributes
get :show, params: { id: budget_type.id }
assigns(:budget_type).should eq(budget_type)
end
end
describe 'GET new' do
it 'assigns a new budget_type as @budget_type' do
get :new
assigns(:budget_type).should be_a_new(BudgetType)
end
end
describe 'GET edit' do
it 'assigns the requested budget_type as @budget_type' do
budget_type = BudgetType.create! valid_attributes
get :edit, params: { id: budget_type.id }
assigns(:budget_type).should eq(budget_type)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new BudgetType' do
expect do
post :create, params: { budget_type: valid_attributes }
end.to change(BudgetType, :count).by(1)
end
it 'assigns a newly created budget_type as @budget_type' do
post :create, params: { budget_type: valid_attributes }
assigns(:budget_type).should be_a(BudgetType)
assigns(:budget_type).should be_persisted
end
it 'redirects to the created budget_type' do
post :create, params: { budget_type: valid_attributes }
response.should redirect_to(BudgetType.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved budget_type as @budget_type' do
# Trigger the behavior that occurs when invalid params are submitted
BudgetType.any_instance.stub(:save).and_return(false)
post :create, params: { budget_type: { note: 'test' } }
assigns(:budget_type).should be_a_new(BudgetType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
BudgetType.any_instance.stub(:save).and_return(false)
post :create, params: { budget_type: { note: 'test' } }
# response.should render_template("new")
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested budget_type' do
budget_type = BudgetType.create! valid_attributes
# Assuming there are no other budget_types in the database, this
# specifies that the BudgetType created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# BudgetType.any_instance.should_receive(:update).with('note' => 'test')
put :update, params: { id: budget_type.id, budget_type: { note: 'test' } }
end
it 'assigns the requested budget_type as @budget_type' do
budget_type = BudgetType.create! valid_attributes
put :update, params: { id: budget_type.id, budget_type: valid_attributes }
assigns(:budget_type).should eq(budget_type)
end
it 'redirects to the budget_type' do
budget_type = BudgetType.create! valid_attributes
put :update, params: { id: budget_type.id, budget_type: valid_attributes }
response.should redirect_to(budget_type)
end
it 'moves its position when specified' do
budget_type = BudgetType.create! valid_attributes
position = budget_type.position
put :update, params: { id: budget_type.id, move: 'higher' }
response.should redirect_to budget_types_url
budget_type.reload
budget_type.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the budget_type as @budget_type' do
budget_type = BudgetType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
BudgetType.any_instance.stub(:save).and_return(false)
put :update, params: { id: budget_type.id, budget_type: { note: 'test' } }
assigns(:budget_type).should eq(budget_type)
end
it "re-renders the 'edit' template" do
budget_type = BudgetType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
BudgetType.any_instance.stub(:save).and_return(false)
put :update, params: { id: budget_type.id, budget_type: { note: 'test' } }
# response.should render_template("edit")
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested budget_type' do
budget_type = BudgetType.create! valid_attributes
expect do
delete :destroy, params: { id: budget_type.id }
end.to change(BudgetType, :count).by(-1)
end
it 'redirects to the budget_types list' do
budget_type = BudgetType.create! valid_attributes
delete :destroy, params: { id: budget_type.id }
response.should redirect_to(budget_types_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/manifestations_controller_spec.rb | spec/controllers/manifestations_controller_spec.rb | require 'rails_helper'
describe ManifestationsController do
fixtures :all
def valid_attributes
FactoryBot.attributes_for(:manifestation)
end
describe 'GET index', solr: true do
before do
Manifestation.reindex
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all manifestations as @manifestations' do
get :index
expect(assigns(:manifestations)).to_not be_nil
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all manifestations as @manifestations' do
get :index
expect(assigns(:manifestations)).to_not be_nil
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all manifestations as @manifestations' do
get :index
expect(assigns(:manifestations)).to_not be_nil
end
end
describe 'When not logged in' do
it 'assigns all manifestations as @manifestations' do
get :index
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations in xml format without operation' do
get :index, format: 'xml'
expect(response).to be_successful
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations in text format without operation' do
get :index, format: :text
expect(response).to be_successful
expect(assigns(:manifestations)).to_not be_nil
expect(response).to render_template('manifestations/index')
end
it 'assigns all manifestations as @manifestations in xlsx format' do
get :index, format: :xlsx
expect(response).to be_successful
expect(assigns(:manifestations)).to_not be_nil
expect(response).to render_template('manifestations/index')
end
it 'assigns all manifestations as @manifestations in openurl' do
get :index, params: { api: 'openurl', title: 'ruby' }
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations when pub_date_from and pub_date_until are specified' do
get :index, params: { pub_date_from: '2000', pub_date_until: '2007' }
assigns(:query).should eq "date_of_publication_d:[#{Time.zone.parse('2000-01-01').beginning_of_day.utc.iso8601} TO #{Time.zone.parse('2007-12-31').end_of_year.utc.iso8601}]"
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations when old pub_date_from and pub_date_until are specified' do
get :index, params: { pub_date_from: '200', pub_date_until: '207' }
assigns(:query).should eq "date_of_publication_d:[#{Time.zone.parse('200-01-01').utc.iso8601} TO #{Time.zone.parse('207-12-31').end_of_year.utc.iso8601}]"
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations when acquired_from and pub_date_until are specified' do
get :index, params: { acquired_from: '2000', acquired_until: '2007' }
assigns(:query).should eq "acquired_at_d:[#{Time.zone.parse('2000-01-01').beginning_of_day.utc.iso8601} TO #{Time.zone.parse('2007-12-31').end_of_year.utc.iso8601}]"
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations when old acquired_from and pub_date_until are specified' do
get :index, params: { acquired_from: '200', acquired_until: '207' }
assigns(:query).should eq "acquired_at_d:[#{Time.zone.parse('200-01-01').utc.iso8601} TO #{Time.zone.parse('207-12-31').end_of_day.utc.iso8601}]"
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations when number_of_pages_at_least and number_of_pages_at_most are specified' do
get :index, params: { number_of_pages_at_least: '100', number_of_pages_at_most: '200' }
expect(assigns(:manifestations)).to_not be_nil
end
it 'assigns all manifestations as @manifestations in mods format' do
get :index, format: 'mods'
expect(assigns(:manifestations)).to_not be_nil
expect(response).to render_template('manifestations/index')
end
it 'assigns all manifestations as @manifestations in rdf format' do
get :index, format: 'rdf'
expect(assigns(:manifestations)).to_not be_nil
expect(response).to render_template('manifestations/index')
end
it 'should get index with manifestation_id' do
get :index, params: { manifestation_id: 1 }
expect(response).to be_successful
expect(assigns(:manifestation)).to eq Manifestation.find(1)
assigns(:manifestations).collect(&:id).should eq assigns(:manifestation).derived_manifestations.collect(&:id)
end
it 'should get index with query' do
get :index, params: { query: '2005' }
expect(response).to be_successful
expect(assigns(:manifestations)).to_not be_blank
end
it 'should get index with page number' do
get :index, params: { query: '2005', number_of_pages_at_least: 1, number_of_pages_at_most: 100 }
expect(response).to be_successful
assigns(:query).should eq '2005 number_of_pages_i:[1 TO 100]'
end
it 'should get index with pub_date_from' do
get :index, params: { query: '2005', pub_date_from: '2000' }
expect(response).to be_successful
expect(assigns(:manifestations)).to be_truthy
assigns(:query).should eq '2005 date_of_publication_d:[1999-12-31T15:00:00Z TO *]'
end
it 'should get index with pub_date_until' do
get :index, params: { query: '2005', pub_date_until: '2000' }
expect(response).to be_successful
expect(assigns(:manifestations)).to be_truthy
assigns(:query).should eq '2005 date_of_publication_d:[* TO 2000-12-31T14:59:59Z]'
end
it 'should show manifestation with isbn', solr: true do
get :index, params: { isbn: '4798002062' }
expect(response).to be_successful
expect(assigns(:manifestations).count).to eq 1
end
it 'should not show missing manifestation with isbn', solr: true do
get :index, params: { isbn: '47980020620' }
expect(response).to be_successful
expect(assigns(:manifestations)).to be_empty
end
it 'should show manifestation with library 3', solr: true do
get :index, params: { library_adv: [ 'hachioji' ] }
expect(response).to be_successful
expect(assigns(:manifestations).size).to eq 1
end
it 'should show manifestation with library 2 or 3', solr: true do
get :index, params: { library_adv: %w(hachioji kamata) }
expect(response).to be_successful
expect(assigns(:manifestations).size).to eq 3
end
it "should show manifestation with shelf", solr: true do
shelf = FactoryBot.create(:shelf)
library = shelf.library
item = FactoryBot.create(:item, shelf: shelf)
get :index, params: { :"#{library.name}_shelf" => [ shelf.name ] }
expect(response).to be_successful
expect(assigns(:manifestations).size).to eq 1
expect(assigns(:manifestations).first).to eq item.manifestation
end
it 'should show manifestation with call_number', solr: true do
get :index, params: { call_number: '547|ヤ' }
expect(response).to be_successful
expect(assigns(:manifestations)).not_to be_empty
end
it 'should show manifestation with NDC', solr: true do
classification = FactoryBot.create(:classification, category: '007.3', classification_type_id: 1)
Manifestation.first.classifications << classification
get :index, params: { classification: '007', classification_type: 1 }
expect(response).to be_successful
expect(assigns(:manifestations)).not_to be_empty
end
it 'should not search with classification if classification is blank' do
get :index, params: { classification: '', classification_type: 1 }
expect(response).to be_successful
expect(assigns(:query)).not_to match /classification/
end
it 'should show manifestation with subject', solr: true do
subject = FactoryBot.create(:subject, term: 'test_subject')
manifestation = FactoryBot.create(:manifestation)
manifestation.subjects << subject
get :index, params: { subject_text: 'test_subject' }
expect(response).to be_successful
expect(assigns(:manifestations)).not_to be_empty
expect(assigns(:manifestations).first).to eq manifestation
end
it 'should accept per_page params' do
get :index, params: { per_page: 3 }
expect(assigns(:manifestations).count).to eq 3
expect(assigns(:manifestations).total_count).to eq 119
end
it 'should accept page parameter' do
get :index
original_manifestations = assigns(:manifestations)
expect(original_manifestations.count).to eq 10
get :index, params: { page: 2 }
manifestations_page2 = assigns(:manifestations)
expect(manifestations_page2.count).to eq 10
expect(original_manifestations.first).not_to eq manifestations_page2.first
end
it 'should accept sort_by parameter' do
get :index, params: { sort_by: 'created_at:desc' }
manifestations = assigns(:manifestations)
expect(manifestations.first.created_at).to be >= manifestations.last.created_at
get :index, params: { sort_by: 'created_at:asc' }
manifestations = assigns(:manifestations)
expect(manifestations.first.created_at).to be <= manifestations.last.created_at
end
it "should get manifestations with series for its children's information" do
periodical = FactoryBot.create(:manifestation_serial)
manifestation = FactoryBot.create(:manifestation, description: "foo")
periodical.derived_manifestations << manifestation
periodical.save!
manifestation.save!
get :index, params: { query: "foo" }
manifestations = assigns(:manifestations)
expect(manifestations).not_to be_blank
expect(manifestations.map {|e| e.id }).to include periodical.id
end
describe "with render_views" do
render_views
it "should accept query & language parameters" do
get :index, params: { query: "test" }
expect(response.body).to have_link "unknown (1)", href: "/manifestations?language=unknown&query=test"
end
it "should accept facets and query parameters in sort_by menu" do
get :index, params: { query: "test", carrier_type: "volume" }
expect(response.body).to have_selector "div.right input[type=hidden][name=query][value=test]", visible: false
expect(response.body).to have_selector "div.right input[type=hidden][name=carrier_type][value=volume]", visible: false
end
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation as @manifestation' do
get :show, params: { id: 1 }
expect(assigns(:manifestation)).to eq(Manifestation.find(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation as @manifestation' do
get :show, params: { id: 1 }
expect(assigns(:manifestation)).to eq(Manifestation.find(1))
end
it 'should show manifestation with agent who does not produce it' do
get :show, params: { id: 3, agent_id: 3 }
expect(assigns(:manifestation)).to eq assigns(:agent).manifestations.find(3)
expect(response).to be_successful
end
it 'should not show manifestation with required_role of admin' do
manifestation = FactoryBot.create(:manifestation, required_role_id: 4)
get :show, params: { id: manifestation.id }
expect(response).not_to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation as @manifestation' do
get :show, params: { id: 1 }
expect(assigns(:manifestation)).to eq(Manifestation.find(1))
end
it 'should send manifestation detail email' do
get :show, params: { id: 1, mode: 'send_email' }
expect(response).to redirect_to manifestation_url(assigns(:manifestation))
end
# it "should show myself" do
# get :show, :id => users(:user1).agent
# expect(response).to be_successful
# end
end
describe 'When not logged in' do
it 'assigns the requested manifestation as @manifestation' do
get :show, params: { id: 1 }
expect(assigns(:manifestation)).to eq(Manifestation.find(1))
end
it 'guest should show manifestation mods template' do
get :show, params: { id: 22, format: 'mods' }
expect(assigns(:manifestation)).to eq Manifestation.find(22)
expect(response).to render_template('manifestations/show')
end
it 'should show manifestation rdf template' do
get :show, params: { id: 22, format: 'rdf' }
expect(assigns(:manifestation)).to eq Manifestation.find(22)
expect(response).to render_template('manifestations/show')
end
it 'should show manifestation xlsx template' do
get :show, params: { id: 22, format: 'xlsx' }
expect(assigns(:manifestation)).to eq Manifestation.find(22)
expect(response).to render_template('manifestations/show')
end
it 'should show manifestation with holding' do
get :show, params: { id: 1, mode: 'holding' }
expect(response).to be_successful
end
it 'should show manifestation with show_creators' do
get :show, params: { id: 1, mode: 'show_creators' }
expect(response).to render_template('manifestations/_show_creators')
expect(response).to be_successful
end
it 'should show manifestation with show_all_creators' do
get :show, params: { id: 1, mode: 'show_all_creators' }
expect(response).to render_template('manifestations/_show_creators')
expect(response).to be_successful
end
it "should not send manifestation's detail email" do
get :show, params: { id: 1, mode: 'send_email' }
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation as @manifestation' do
get :new
expect(assigns(:manifestation)).to_not be_valid
end
it 'should get new template without expression_id' do
get :new
expect(response).to be_successful
end
it 'should get new template with expression_id' do
get :new, params: { expression_id: 1 }
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation as @manifestation' do
get :new
expect(assigns(:manifestation)).to_not be_valid
end
it 'should get new template without expression_id' do
get :new
expect(response).to be_successful
end
it 'should get new template with expression_id' do
get :new, params: { expression_id: 1 }
expect(response).to be_successful
end
it 'should get new template with parent_id' do
serial = FactoryBot.create(:manifestation_serial,
statement_of_responsibility: 'statement_of_responsibility1',
title_alternative: 'title_alternative1',
publication_place: 'publication_place1',
height: 123,
width: 123,
depth: 123,
price: 'price1',
access_address: 'http://example.jp',
language_id: FactoryBot.create(:language).id,
frequency_id: FactoryBot.create(:frequency).id,
required_role_id: FactoryBot.create(:role).id)
serial.creators << FactoryBot.create(:agent)
serial.contributors << FactoryBot.create(:agent)
serial.publishers << FactoryBot.create(:agent)
serial.reload
serial.subjects << FactoryBot.create(:subject)
serial.classifications << FactoryBot.create(:classification)
serial.save!
get :new, params: { parent_id: serial.id }
expect(response).to be_successful
manifestation = assigns(:manifestation)
parent = assigns(:parent)
expect(parent).to be_truthy
expect(manifestation.original_title).to eq parent.original_title
expect(manifestation.creators).to eq parent.creators
expect(manifestation.contributors).to eq parent.contributors
expect(manifestation.publishers).to eq parent.publishers
expect(manifestation.classifications).to eq parent.classifications
expect(manifestation.subjects).to eq parent.subjects
expect(manifestation.statement_of_responsibility).to eq parent.statement_of_responsibility
expect(manifestation.title_alternative).to eq parent.title_alternative
expect(manifestation.publication_place).to eq parent.publication_place
expect(manifestation.height).to eq parent.height
expect(manifestation.width).to eq parent.width
expect(manifestation.depth).to eq parent.depth
expect(manifestation.price).to eq parent.price
expect(manifestation.access_address).to eq parent.access_address
expect(manifestation.language).to eq parent.language
expect(manifestation.frequency).to eq parent.frequency
expect(manifestation.required_role).to eq parent.required_role
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested manifestation as @manifestation' do
get :new
expect(assigns(:manifestation)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation as @manifestation' do
get :new
expect(assigns(:manifestation)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation as @manifestation' do
manifestation = FactoryBot.create(:manifestation)
get :edit, params: { id: manifestation.id }
expect(assigns(:manifestation)).to eq(manifestation)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation as @manifestation' do
manifestation = FactoryBot.create(:manifestation)
get :edit, params: { id: manifestation.id }
expect(assigns(:manifestation)).to eq(manifestation)
end
render_views
it 'assigns the identifiers to @manifestation' do
manifestation = FactoryBot.create(:manifestation)
identifier = FactoryBot.create(:identifier)
manifestation.identifiers << identifier
get :edit, params: { id: manifestation.id }
expect(assigns(:manifestation)).to eq manifestation
expect(assigns(:manifestation).identifiers).to eq manifestation.identifiers
expect(response).to render_template(partial: 'manifestations/_identifier_fields')
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation as @manifestation' do
manifestation = FactoryBot.create(:manifestation)
get :edit, params: { id: manifestation.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation as @manifestation' do
manifestation = FactoryBot.create(:manifestation)
get :edit, params: { id: manifestation.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { original_title: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created manifestation as @manifestation' do
post :create, params: { manifestation: @attrs }
expect(assigns(:manifestation)).to be_valid
end
it 'assigns a series_statement' do
post :create, params: { manifestation: @attrs.merge(series_statements_attributes: { '0' => { original_title: SeriesStatement.find(1).original_title } }) }
assigns(:manifestation).reload
assigns(:manifestation).series_statements.pluck(:original_title).include?(series_statements(:one).original_title).should be_truthy
end
it 'redirects to the created manifestation' do
post :create, params: { manifestation: @attrs }
expect(response).to redirect_to(manifestation_url(assigns(:manifestation)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation as @manifestation' do
post :create, params: { manifestation: @invalid_attrs }
expect(assigns(:manifestation)).to_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created manifestation as @manifestation' do
post :create, params: { manifestation: @attrs }
expect(assigns(:manifestation)).to be_valid
end
it 'redirects to the created manifestation' do
post :create, params: { manifestation: @attrs }
expect(response).to redirect_to(manifestation_url(assigns(:manifestation)))
end
it 'accepts an attachment file' do
post :create, params: { manifestation: @attrs.merge(attachment: fixture_file_upload('resource_import_file_sample1.tsv', 'text/csv')) }
expect(assigns(:manifestation)).to be_valid
end
it 'accepts custom values' do
post :create, params: { manifestation: @attrs.merge(manifestation_custom_values_attributes: Array.new(3) {FactoryBot.attributes_for(:manifestation_custom_value, manifestation_custom_property_id: FactoryBot.create(:manifestation_custom_property).id)}) }
expect(assigns(:manifestation)).to be_valid
expect(assigns(:manifestation).manifestation_custom_values.count).to eq 3
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation as @manifestation' do
post :create, params: { manifestation: @invalid_attrs }
expect(assigns(:manifestation)).to_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created manifestation as @manifestation' do
post :create, params: { manifestation: @attrs }
expect(assigns(:manifestation)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation as @manifestation' do
post :create, params: { manifestation: @invalid_attrs }
expect(assigns(:manifestation)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created manifestation as @manifestation' do
post :create, params: { manifestation: @attrs }
expect(assigns(:manifestation)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation as @manifestation' do
post :create, params: { manifestation: @invalid_attrs }
expect(assigns(:manifestation)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@manifestation = FactoryBot.create(:manifestation)
@manifestation.series_statements = [ SeriesStatement.find(1) ]
@manifestation.publishers << FactoryBot.create(:agent)
@attrs = valid_attributes
@invalid_attrs = { original_title: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
end
it 'assigns a series_statement' do
put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(series_statements_attributes: { '0' => { :original_title => series_statements(:two).original_title, '_destroy' => 'false' } }) }
assigns(:manifestation).reload
assigns(:manifestation).series_statements.pluck(:original_title).include?(series_statements(:two).original_title).should be_truthy
end
it 'assigns the requested manifestation as @manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
expect(assigns(:manifestation)).to eq(@manifestation)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation as @manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
end
it 'assigns the requested manifestation as @manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
expect(assigns(:manifestation)).to eq(@manifestation)
expect(response).to redirect_to(@manifestation)
end
it 'assigns identifiers to @manifestation' do
identifiers_attrs = {
identifier_attributes: [ FactoryBot.create(:identifier) ]
}
put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(identifiers_attrs) }
expect(assigns(:manifestation)).to eq @manifestation
end
it 'assigns identifiers and publishers to @manifestation' do
identifiers_attrs = {
identifier_attributes: [ FactoryBot.create(:identifier) ]
}
publishers_attrs = {
publisher_attributes: [ FactoryBot.create(:agent) ]
}
put :update, params: {
id: @manifestation.id, manifestation: @attrs.merge(identifiers_attrs).merge(publishers_attrs)
}
expect(assigns(:manifestation)).to eq @manifestation
end
it 'accepts custom values' do
@manifestation.manifestation_custom_values << FactoryBot.build(:manifestation_custom_value)
put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(manifestation_custom_values_attributes: [ { id: @manifestation.manifestation_custom_values.first.id, value: 'test' } ]) }
expect(assigns(:manifestation)).to be_valid
expect(assigns(:manifestation).manifestation_custom_values.count).to eq 1
expect(assigns(:manifestation).manifestation_custom_values.first.value).to eq 'test'
end
it 'accepts custom values when the value is empty' do
@manifestation.manifestation_custom_values << FactoryBot.build(:manifestation_custom_value)
put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(manifestation_custom_values_attributes: [ { id: @manifestation.manifestation_custom_values.first.id, value: '' } ]) }
expect(assigns(:manifestation)).to be_valid
expect(assigns(:manifestation).manifestation_custom_values.count).to eq 1
expect(assigns(:manifestation).manifestation_custom_values.first.value).to eq ''
end
it 'deletes an attachment file' do
@manifestation.attachment.attach(io: File.open(Rails.root.join('spec/fixtures/files/resource_import_file_sample1.tsv')), filename: 'attachment.txt')
@manifestation.save
expect(@manifestation.attachment.attached?).to be_truthy
put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(delete_attachment: '1') }
expect(assigns(:manifestation).attachment.attached?).to be_falsy
end
end
describe 'with invalid params' do
it 'assigns the manifestation as @manifestation' do
put :update, params: { id: @manifestation, manifestation: @invalid_attrs }
expect(assigns(:manifestation)).to_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @manifestation, manifestation: @invalid_attrs }
expect(response).to render_template('edit')
end
it 'assigns identifiers and publishers to @manifestation' do
identifiers_attrs = {
identifier_attributes: [ FactoryBot.create(:identifier) ]
}
publishers_attrs = {
publisher_attributes: [ FactoryBot.create(:agent) ]
}
put :update, params: {
id: @manifestation.id, manifestation: @invalid_attrs.merge(identifiers_attrs).merge(publishers_attrs)
}
expect(assigns(:manifestation)).to_not be_valid
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
end
it 'assigns the requested manifestation as @manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
expect(assigns(:manifestation)).to eq(@manifestation)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation as @manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested manifestation' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @manifestation.id, manifestation: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | true |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/licenses_controller_spec.rb | spec/controllers/licenses_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe LicensesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# License. As you add validations to License, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:license)
end
describe 'GET index' do
it 'assigns all licenses as @licenses' do
license = License.create! valid_attributes
get :index
expect(assigns(:licenses)).to eq(License.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested license as @license' do
license = License.create! valid_attributes
get :show, params: { id: license.id }
expect(assigns(:license)).to eq(license)
end
end
describe 'GET new' do
it 'assigns a new license as @license' do
get :new
expect(assigns(:license)).to be_a_new(License)
end
end
describe 'GET edit' do
it 'assigns the requested license as @license' do
license = License.create! valid_attributes
get :edit, params: { id: license.id }
expect(assigns(:license)).to eq(license)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new License' do
expect do
post :create, params: { license: valid_attributes }
end.to change(License, :count).by(1)
end
it 'assigns a newly created license as @license' do
post :create, params: { license: valid_attributes }
expect(assigns(:license)).to be_a(License)
expect(assigns(:license)).to be_persisted
end
it 'redirects to the created license' do
post :create, params: { license: valid_attributes }
expect(response).to redirect_to(License.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved license as @license' do
# Trigger the behavior that occurs when invalid params are submitted
License.any_instance.stub(:save).and_return(false)
post :create, params: { license: { name: 'test' } }
expect(assigns(:license)).to be_a_new(License)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
License.any_instance.stub(:save).and_return(false)
post :create, params: { license: { name: 'test' } }
# expect(response).to render_template("new")
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested license' do
license = License.create! valid_attributes
# Assuming there are no other licenses in the database, this
# specifies that the License created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# License.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: license.id, license: { 'name' => 'test' } }
end
it 'assigns the requested license as @license' do
license = License.create! valid_attributes
put :update, params: { id: license.id, license: valid_attributes }
expect(assigns(:license)).to eq(license)
end
it 'redirects to the license' do
license = License.create! valid_attributes
put :update, params: { id: license.id, license: valid_attributes }
expect(response).to redirect_to(license)
end
it 'moves its position when specified' do
license = License.create! valid_attributes
position = license.position
put :update, params: { id: license.id, move: 'higher' }
expect(response).to redirect_to licenses_url
assigns(:license).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the license as @license' do
license = License.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
License.any_instance.stub(:save).and_return(false)
put :update, params: { id: license.id, license: { name: 'test' } }
expect(assigns(:license)).to eq(license)
end
it "re-renders the 'edit' template" do
license = License.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
License.any_instance.stub(:save).and_return(false)
put :update, params: { id: license.id, license: { name: 'test' } }
# expect(response).to render_template("edit")
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested license' do
license = License.create! valid_attributes
expect do
delete :destroy, params: { id: license.id }
end.to change(License, :count).by(-1)
end
it 'redirects to the licenses list' do
license = License.create! valid_attributes
delete :destroy, params: { id: license.id }
expect(response).to redirect_to(licenses_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/creates_controller_spec.rb | spec/controllers/creates_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe CreatesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:create)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:create)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all creates as @creates' do
get :index
expect(assigns(:creates)).to eq(Create.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all creates as @creates' do
get :index
expect(assigns(:creates)).to eq(Create.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all creates as @creates' do
get :index
expect(assigns(:creates)).to eq(Create.page(1))
end
end
describe 'When not logged in' do
it 'assigns all creates as @creates' do
get :index
expect(assigns(:creates)).to eq(Create.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :show, params: { id: create.id }
expect(assigns(:create)).to eq(create)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :show, params: { id: create.id }
expect(assigns(:create)).to eq(create)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :show, params: { id: create.id }
expect(assigns(:create)).to eq(create)
end
end
describe 'When not logged in' do
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :show, params: { id: create.id }
expect(assigns(:create)).to eq(create)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested create as @create' do
get :new
expect(assigns(:create)).not_to be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested create as @create' do
get :new
expect(assigns(:create)).not_to be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested create as @create' do
get :new
expect(assigns(:create)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested create as @create' do
get :new
expect(assigns(:create)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :edit, params: { id: create.id }
expect(assigns(:create)).to eq(create)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :edit, params: { id: create.id }
expect(assigns(:create)).to eq(create)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested create as @create' do
create = FactoryBot.create(:create)
get :edit, params: { id: create.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested create as @create' do
create = FactoryBot.create(:create)
get :edit, params: { id: create.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { work_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created create as @create' do
post :create, params: { create: @attrs }
expect(assigns(:create)).to be_valid
end
it 'redirects to the created create' do
post :create, params: { create: @attrs }
expect(response).to redirect_to(create_url(assigns(:create)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved create as @create' do
post :create, params: { create: @invalid_attrs }
expect(assigns(:create)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { create: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created create as @create' do
post :create, params: { create: @attrs }
expect(assigns(:create)).to be_valid
end
it 'redirects to the created create' do
post :create, params: { create: @attrs }
expect(response).to redirect_to(create_url(assigns(:create)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved create as @create' do
post :create, params: { create: @invalid_attrs }
expect(assigns(:create)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { create: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created create as @create' do
post :create, params: { create: @attrs }
expect(assigns(:create)).to be_nil
end
it 'should be forbidden' do
post :create, params: { create: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved create as @create' do
post :create, params: { create: @invalid_attrs }
expect(assigns(:create)).to be_nil
end
it 'should be forbidden' do
post :create, params: { create: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created create as @create' do
post :create, params: { create: @attrs }
expect(assigns(:create)).to be_nil
end
it 'should be forbidden' do
post :create, params: { create: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved create as @create' do
post :create, params: { create: @invalid_attrs }
expect(assigns(:create)).to be_nil
end
it 'should be redirected to new session url' do
post :create, params: { create: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@create = creates(:create_00001)
@attrs = valid_attributes
@invalid_attrs = { work_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested create' do
put :update, params: { id: @create.id, create: @attrs }
end
it 'assigns the requested create as @create' do
put :update, params: { id: @create.id, create: @attrs }
expect(assigns(:create)).to eq(@create)
end
end
describe 'with invalid params' do
it 'assigns the requested create as @create' do
put :update, params: { id: @create.id, create: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested create' do
put :update, params: { id: @create.id, create: @attrs }
end
it 'assigns the requested create as @create' do
put :update, params: { id: @create.id, create: @attrs }
expect(assigns(:create)).to eq(@create)
expect(response).to redirect_to(@create)
end
it 'moves its position when specified' do
position = @create.position
put :update, params: { id: @create.id, work_id: @create.work.id, move: 'lower' }
expect(response).to redirect_to creates_url(work_id: @create.work_id)
assigns(:create).reload.position.should eq position + 1
end
end
describe 'with invalid params' do
it 'assigns the create as @create' do
put :update, params: { id: @create, create: @invalid_attrs }
expect(assigns(:create)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @create, create: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested create' do
put :update, params: { id: @create.id, create: @attrs }
end
it 'assigns the requested create as @create' do
put :update, params: { id: @create.id, create: @attrs }
expect(assigns(:create)).to eq(@create)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested create as @create' do
put :update, params: { id: @create.id, create: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested create' do
put :update, params: { id: @create.id, create: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @create.id, create: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested create as @create' do
put :update, params: { id: @create.id, create: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@create = FactoryBot.create(:create)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested create' do
delete :destroy, params: { id: @create.id }
end
it 'redirects to the creates list' do
delete :destroy, params: { id: @create.id }
expect(response).to redirect_to(creates_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested create' do
delete :destroy, params: { id: @create.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @create.id }
expect(response).to redirect_to(creates_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested create' do
delete :destroy, params: { id: @create.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @create.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested create' do
delete :destroy, params: { id: @create.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @create.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_import_files_controller_spec.rb | spec/controllers/agent_import_files_controller_spec.rb | require 'rails_helper'
describe AgentImportFilesController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all agent_import_files as @agent_import_files' do
get :index
expect(assigns(:agent_import_files)).to eq(AgentImportFile.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all agent_import_files as @agent_import_files' do
get :index
expect(assigns(:agent_import_files)).to eq(AgentImportFile.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns empty as @agent_import_files' do
get :index
expect(assigns(:agent_import_files)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @agent_import_files' do
get :index
expect(assigns(:agent_import_files)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_import_file as @agent_import_file' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_file)).to eq(AgentImportFile.find(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_import_file as @agent_import_file' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_file)).to eq(AgentImportFile.find(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_import_file as @agent_import_file' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_file)).to eq(AgentImportFile.find(1))
end
end
describe 'When not logged in' do
it 'assigns the requested agent_import_file as @agent_import_file' do
get :show, params: { id: 1 }
expect(assigns(:agent_import_file)).to eq(AgentImportFile.find(1))
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_import_file as @agent_import_file' do
get :new
expect(assigns(:agent_import_file)).to_not be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested agent_import_file as @agent_import_file' do
get :new
expect(assigns(:agent_import_file)).to_not be_valid
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested agent_import_file as @agent_import_file' do
get :new
expect(assigns(:agent_import_file)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_import_file as @agent_import_file' do
get :new
expect(assigns(:agent_import_file)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should create agent_import_file' do
post :create, params: { agent_import_file: { attachment: fixture_file_upload('agent_import_file_sample1.tsv', 'text/csv') } }
expect(assigns(:agent_import_file)).to be_valid
assigns(:agent_import_file).user.username.should eq @user.username
expect(response).to redirect_to agent_import_file_url(assigns(:agent_import_file))
end
it 'should import user' do
old_agents_count = Agent.count
post :create, params: { agent_import_file: { attachment: fixture_file_upload('agent_import_file_sample2.tsv', 'text/csv') } }
assigns(:agent_import_file).import_start
Agent.count.should eq old_agents_count + 3
expect(response).to redirect_to agent_import_file_url(assigns(:agent_import_file))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should be forbidden' do
post :create, params: { agent_import_file: { attachment: fixture_file_upload('agent_import_file_sample1.tsv', 'text/csv') } }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should be redirect to new session url' do
post :create, params: { agent_import_file: { attachment: fixture_file_upload('agent_import_file_sample1.tsv', 'text/csv') } }
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested agent_import_file as @agent_import_file' do
agent_import_file = agent_import_files(:agent_import_file_00001)
get :edit, params: { id: agent_import_file.id }
expect(assigns(:agent_import_file)).to eq(agent_import_file)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested agent_import_file as @agent_import_file' do
agent_import_file = agent_import_files(:agent_import_file_00001)
get :edit, params: { id: agent_import_file.id }
expect(assigns(:agent_import_file)).to eq(agent_import_file)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested agent_import_file as @agent_import_file' do
agent_import_file = agent_import_files(:agent_import_file_00001)
get :edit, params: { id: agent_import_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_import_file as @agent_import_file' do
agent_import_file = agent_import_files(:agent_import_file_00001)
get :edit, params: { id: agent_import_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'PUT update' do
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should update agent_import_file' do
put :update, params: { id: agent_import_files(:agent_import_file_00003).id, agent_import_file: { mode: 'modify' } }
expect(response).to redirect_to agent_import_file_url(assigns(:agent_import_file))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not update agent_import_file' do
put :update, params: { id: agent_import_files(:agent_import_file_00003).id, agent_import_file: { mode: 'modify' } }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not update agent_import_file' do
put :update, params: { id: agent_import_files(:agent_import_file_00003).id, agent_import_file: { mode: 'modify' } }
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'DELETE destroy' do
before(:each) do
@agent_import_file = agent_import_files(:agent_import_file_00001)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested agent_import_file' do
delete :destroy, params: { id: @agent_import_file.id }
end
it 'redirects to the agent_import_files list' do
delete :destroy, params: { id: @agent_import_file.id }
expect(response).to redirect_to(agent_import_files_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested agent_import_file' do
delete :destroy, params: { id: @agent_import_file.id }
end
it 'redirects to the agent_import_files list' do
delete :destroy, params: { id: @agent_import_file.id }
expect(response).to redirect_to(agent_import_files_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested agent_import_file' do
delete :destroy, params: { id: @agent_import_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_import_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested agent_import_file' do
delete :destroy, params: { id: @agent_import_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_import_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/accepts_controller_spec.rb | spec/controllers/accepts_controller_spec.rb | require 'rails_helper'
describe AcceptsController do
fixtures :all
def mock_user(stubs = {})
(@mock_user ||= mock_model(Accept).as_null_object).tap do |user|
user.stub(stubs) unless stubs.empty?
end
end
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all accepts as @accepts' do
get :index
assigns(:accepts).should_not be_nil
response.should be_successful
end
describe 'When basket_id is specified' do
it 'assigns all accepts as @accepts' do
get :index, params: { basket_id: 10 }
assigns(:accepts).should eq baskets(:basket_00010).accepts.order('accepts.created_at DESC').page(1)
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all accepts as @accepts' do
get :index
assigns(:accepts).should_not be_nil
response.should be_successful
end
describe 'When basket_id is specified' do
it 'assigns all accepts as @accepts' do
get :index, params: { basket_id: 9 }
assigns(:accepts).should eq baskets(:basket_00009).accepts.order('accepts.created_at DESC').page(1)
response.should be_successful
end
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign all accepts as @accepts' do
get :index
assigns(:accepts).should be_nil
response.should be_forbidden
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested accept as @accept' do
accept = FactoryBot.create(:accept)
get :show, params: { id: accept.id }
assigns(:accept).should eq(accept)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested accept as @accept' do
accept = FactoryBot.create(:accept)
get :show, params: { id: accept.id }
assigns(:accept).should eq(accept)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested accept as @accept' do
accept = FactoryBot.create(:accept)
get :show, params: { id: accept.id }
assigns(:accept).should eq(accept)
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested accept as @accept' do
accept = FactoryBot.create(:accept)
get :show, params: { id: accept.id }
assigns(:accept).should eq(accept)
response.should redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested accept as @accept' do
get :new
assigns(:accept).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested accept as @accept' do
get :new
assigns(:accept).should_not be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested accept as @accept' do
get :new
assigns(:accept).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested accept as @accept' do
get :new
assigns(:accept).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = { item_identifier: '00003' }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created accept as @accept' do
post :create, params: { accept: @attrs }
assigns(:accept).should be_nil
end
it 'should not create a new accept without basket_id' do
post :create, params: { accept: @attrs }
response.should be_forbidden
end
describe 'When basket_id is specified' do
it 'redirects to the created accept' do
post :create, params: { accept: @attrs, basket_id: 9 }
response.should redirect_to(accepts_url(basket_id: assigns(:accept).basket.id))
assigns(:accept).item.circulation_status.name.should eq 'Available On Shelf'
end
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved accept as @accept' do
post :create, params: { accept: @invalid_attrs }
assigns(:accept).should be_nil
end
it 'should be forbidden' do
post :create, params: { accept: @invalid_attrs }
response.should be_forbidden
end
end
it 'should not create accept without item_id' do
post :create, params: { accept: { item_identifier: nil }, basket_id: 9 }
assigns(:accept).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created accept as @accept' do
post :create, params: { accept: @attrs }
assigns(:accept).should be_nil
end
it 'should not create a new accept without basket_id' do
post :create, params: { accept: @attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created accept as @accept' do
post :create, params: { accept: @attrs }
assigns(:accept).should be_nil
end
it 'should be forbidden' do
post :create, params: { accept: @attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
before(:each) do
@attrs = { item_identifier: '00003' }
@invalid_attrs = { item_identifier: 'invalid' }
end
describe 'with valid params' do
it 'assigns a newly created accept as @accept' do
post :create, params: { accept: @attrs }
end
it 'should redirect to new session url' do
post :create, params: { accept: @attrs }
response.should redirect_to new_user_session_url
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@accept = FactoryBot.create(:accept)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested accept' do
delete :destroy, params: { id: @accept.id }
end
it 'redirects to the accepts list' do
delete :destroy, params: { id: @accept.id }
response.should redirect_to(accepts_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested accept' do
delete :destroy, params: { id: @accept.id }
end
it 'redirects to the accepts list' do
delete :destroy, params: { id: @accept.id }
response.should redirect_to(accepts_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested accept' do
delete :destroy, params: { id: @accept.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @accept.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested accept' do
delete :destroy, params: { id: @accept.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @accept.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/produces_controller_spec.rb | spec/controllers/produces_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ProducesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:produce)
end
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all produces as @produces' do
get :index
expect(assigns(:produces)).to eq(Produce.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all produces as @produces' do
get :index
expect(assigns(:produces)).to eq(Produce.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all produces as @produces' do
get :index
expect(assigns(:produces)).to eq(Produce.page(1))
end
end
describe 'When not logged in' do
it 'assigns all produces as @produces' do
get :index
expect(assigns(:produces)).to eq(Produce.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :show, params: { id: produce.id }
expect(assigns(:produce)).to eq(produce)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :show, params: { id: produce.id }
expect(assigns(:produce)).to eq(produce)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :show, params: { id: produce.id }
expect(assigns(:produce)).to eq(produce)
end
end
describe 'When not logged in' do
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :show, params: { id: produce.id }
expect(assigns(:produce)).to eq(produce)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested produce as @produce' do
get :new
expect(assigns(:produce)).not_to be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested produce as @produce' do
get :new
expect(assigns(:produce)).not_to be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested produce as @produce' do
get :new
expect(assigns(:produce)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested produce as @produce' do
get :new
expect(assigns(:produce)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :edit, params: { id: produce.id }
expect(assigns(:produce)).to eq(produce)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :edit, params: { id: produce.id }
expect(assigns(:produce)).to eq(produce)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :edit, params: { id: produce.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested produce as @produce' do
produce = FactoryBot.create(:produce)
get :edit, params: { id: produce.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { manifestation_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created produce as @produce' do
post :create, params: { produce: @attrs }
expect(assigns(:produce)).to be_valid
end
it 'redirects to the created produce' do
post :create, params: { produce: @attrs }
expect(response).to redirect_to(produce_url(assigns(:produce)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved produce as @produce' do
post :create, params: { produce: @invalid_attrs }
expect(assigns(:produce)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { produce: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created produce as @produce' do
post :create, params: { produce: @attrs }
expect(assigns(:produce)).to be_valid
end
it 'redirects to the created produce' do
post :create, params: { produce: @attrs }
expect(response).to redirect_to(produce_url(assigns(:produce)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved produce as @produce' do
post :create, params: { produce: @invalid_attrs }
expect(assigns(:produce)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { produce: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created produce as @produce' do
post :create, params: { produce: @attrs }
expect(assigns(:produce)).to be_nil
end
it 'should be forbidden' do
post :create, params: { produce: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved produce as @produce' do
post :create, params: { produce: @invalid_attrs }
expect(assigns(:produce)).to be_nil
end
it 'should be forbidden' do
post :create, params: { produce: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created produce as @produce' do
post :create, params: { produce: @attrs }
expect(assigns(:produce)).to be_nil
end
it 'should be forbidden' do
post :create, params: { produce: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved produce as @produce' do
post :create, params: { produce: @invalid_attrs }
expect(assigns(:produce)).to be_nil
end
it 'should be forbidden' do
post :create, params: { produce: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@produce = produces(:produce_00001)
@attrs = valid_attributes
@invalid_attrs = { manifestation_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested produce' do
put :update, params: { id: @produce.id, produce: @attrs }
end
it 'assigns the requested produce as @produce' do
put :update, params: { id: @produce.id, produce: @attrs }
expect(assigns(:produce)).to eq(@produce)
end
end
describe 'with invalid params' do
it 'assigns the requested produce as @produce' do
put :update, params: { id: @produce.id, produce: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested produce' do
put :update, params: { id: @produce.id, produce: @attrs }
end
it 'assigns the requested produce as @produce' do
put :update, params: { id: @produce.id, produce: @attrs }
expect(assigns(:produce)).to eq(@produce)
expect(response).to redirect_to(@produce)
end
it 'moves its position when specified' do
position = @produce.position
put :update, params: { id: @produce.id, manifestation_id: @produce.manifestation.id, move: 'lower' }
expect(response).to redirect_to produces_url(manifestation_id: @produce.manifestation_id)
assigns(:produce).reload.position.should eq position + 1
end
end
describe 'with invalid params' do
it 'assigns the produce as @produce' do
put :update, params: { id: @produce, produce: @invalid_attrs }
expect(assigns(:produce)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @produce, produce: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested produce' do
put :update, params: { id: @produce.id, produce: @attrs }
end
it 'assigns the requested produce as @produce' do
put :update, params: { id: @produce.id, produce: @attrs }
expect(assigns(:produce)).to eq(@produce)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested produce as @produce' do
put :update, params: { id: @produce.id, produce: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested produce' do
put :update, params: { id: @produce.id, produce: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @produce.id, produce: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested produce as @produce' do
put :update, params: { id: @produce.id, produce: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@produce = FactoryBot.create(:produce)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested produce' do
delete :destroy, params: { id: @produce.id }
end
it 'redirects to the produces list' do
delete :destroy, params: { id: @produce.id }
expect(response).to redirect_to(produces_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested produce' do
delete :destroy, params: { id: @produce.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @produce.id }
expect(response).to redirect_to(produces_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested produce' do
delete :destroy, params: { id: @produce.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @produce.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested produce' do
delete :destroy, params: { id: @produce.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @produce.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/produce_types_controller_spec.rb | spec/controllers/produce_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe ProduceTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# ProduceType. As you add validations to ProduceType, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:produce_type)
end
describe 'GET index' do
it 'assigns all produce_types as @produce_types' do
produce_type = ProduceType.create! valid_attributes
get :index
expect(assigns(:produce_types)).to eq(ProduceType.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested produce_type as @produce_type' do
produce_type = ProduceType.create! valid_attributes
get :show, params: { id: produce_type.id }
expect(assigns(:produce_type)).to eq(produce_type)
end
end
describe 'GET new' do
it 'assigns a new produce_type as @produce_type' do
get :new
expect(assigns(:produce_type)).to be_a_new(ProduceType)
end
end
describe 'GET edit' do
it 'assigns the requested produce_type as @produce_type' do
produce_type = ProduceType.create! valid_attributes
get :edit, params: { id: produce_type.id }
expect(assigns(:produce_type)).to eq(produce_type)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new ProduceType' do
expect do
post :create, params: { produce_type: valid_attributes }
end.to change(ProduceType, :count).by(1)
end
it 'assigns a newly created produce_type as @produce_type' do
post :create, params: { produce_type: valid_attributes }
expect(assigns(:produce_type)).to be_a(ProduceType)
expect(assigns(:produce_type)).to be_persisted
end
it 'redirects to the created produce_type' do
post :create, params: { produce_type: valid_attributes }
expect(response).to redirect_to(ProduceType.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved produce_type as @produce_type' do
# Trigger the behavior that occurs when invalid params are submitted
ProduceType.any_instance.stub(:save).and_return(false)
post :create, params: { produce_type: { name: 'test' } }
expect(assigns(:produce_type)).to be_a_new(ProduceType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
ProduceType.any_instance.stub(:save).and_return(false)
post :create, params: { produce_type: { name: 'test' } }
# expect(response).to render_template("new")
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested produce_type' do
produce_type = ProduceType.create! valid_attributes
# Assuming there are no other produce_types in the database, this
# specifies that the ProduceType created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# ProduceType.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: produce_type.id, produce_type: { 'name' => 'test' } }
end
it 'assigns the requested produce_type as @produce_type' do
produce_type = ProduceType.create! valid_attributes
put :update, params: { id: produce_type.id, produce_type: valid_attributes }
expect(assigns(:produce_type)).to eq(produce_type)
end
it 'redirects to the produce_type' do
produce_type = ProduceType.create! valid_attributes
put :update, params: { id: produce_type.id, produce_type: valid_attributes }
expect(response).to redirect_to(produce_type)
end
it 'moves its position when specified' do
produce_type = ProduceType.create! valid_attributes
position = produce_type.position
put :update, params: { id: produce_type.id, move: 'higher' }
expect(response).to redirect_to produce_types_url
assigns(:produce_type).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the produce_type as @produce_type' do
produce_type = ProduceType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
ProduceType.any_instance.stub(:save).and_return(false)
put :update, params: { id: produce_type.id, produce_type: { name: 'test' } }
expect(assigns(:produce_type)).to eq(produce_type)
end
it "re-renders the 'edit' template" do
produce_type = ProduceType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
ProduceType.any_instance.stub(:save).and_return(false)
put :update, params: { id: produce_type.id, produce_type: { name: 'test' } }
# expect(response).to render_template("edit")
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested produce_type' do
produce_type = ProduceType.create! valid_attributes
expect do
delete :destroy, params: { id: produce_type.id }
end.to change(ProduceType, :count).by(-1)
end
it 'redirects to the produce_types list' do
produce_type = ProduceType.create! valid_attributes
delete :destroy, params: { id: produce_type.id }
expect(response).to redirect_to(produce_types_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/user_import_results_controller_spec.rb | spec/controllers/user_import_results_controller_spec.rb | require 'rails_helper'
describe UserImportResultsController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all user_import_results as @user_import_results' do
get :index
assigns(:user_import_results).should eq(UserImportResult.page(1))
end
describe 'With @user_import_file parameter' do
before(:each) do
@file = UserImportFile.create attachment: fixture_file_upload("user_import_file_sample_long.tsv"), user: users(:admin)
@file.default_user_group = UserGroup.find(2)
@file.default_library = Library.find(3)
@file.save
@file.import_start
end
render_views
it 'should assign all user_import_results for the user_import_file with a page parameter' do
get :index, params: { user_import_file_id: @file.id }
results = assigns(:user_import_results)
results.should_not be_empty
response.body.should match /<td>11<\/td>/
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all user_import_results as @user_import_results' do
get :index
assigns(:user_import_results).should eq(UserImportResult.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns empty as @user_import_results' do
get :index
assigns(:user_import_results).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @user_import_results' do
get :index
assigns(:user_import_results).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested user_import_result as @user_import_result' do
get :show, params: { id: 1 }
assigns(:user_import_result).should eq(UserImportResult.find(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested user_import_result as @user_import_result' do
get :show, params: { id: 1 }
assigns(:user_import_result).should eq(UserImportResult.find(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested user_import_result as @user_import_result' do
get :show, params: { id: 1 }
assigns(:user_import_result).should eq(UserImportResult.find(1))
end
end
describe 'When not logged in' do
it 'assigns the requested user_import_result as @user_import_result' do
get :show, params: { id: 1 }
assigns(:user_import_result).should eq(UserImportResult.find(1))
response.should redirect_to(new_user_session_url)
end
end
end
describe 'DELETE destroy' do
before(:each) do
@user_import_result = user_import_results(:one)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested user_import_result' do
delete :destroy, params: { id: @user_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_import_result.id }
response.should be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested user_import_result' do
delete :destroy, params: { id: @user_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_import_result.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested user_import_result' do
delete :destroy, params: { id: @user_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_import_result.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested user_import_result' do
delete :destroy, params: { id: @user_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @user_import_result.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_merges_controller_spec.rb | spec/controllers/agent_merges_controller_spec.rb | require 'rails_helper'
describe AgentMergesController do
fixtures :all
describe 'GET index' do
before(:each) do
FactoryBot.create(:agent_merge)
end
describe 'When logged in as Administrator' do
login_admin
it 'assigns all agent_merges as @agent_merges' do
get :index
assigns(:agent_merges).should eq(AgentMerge.page(1))
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns all agent_merges as @agent_merges' do
get :index
assigns(:agent_merges).should eq(AgentMerge.page(1))
end
end
describe 'When logged in as User' do
login_user
it 'should be forbidden' do
get :index
assigns(:agent_merges).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should be forbidden' do
get :index
assigns(:agent_merges).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :show, params: { id: agent_merge.id }
assigns(:agent_merge).should eq(agent_merge)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :show, params: { id: agent_merge.id }
assigns(:agent_merge).should eq(agent_merge)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :show, params: { id: agent_merge.id }
assigns(:agent_merge).should eq(agent_merge)
end
end
describe 'When not logged in' do
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :show, params: { id: agent_merge.id }
assigns(:agent_merge).should eq(agent_merge)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested agent_merge as @agent_merge' do
get :new
assigns(:agent_merge).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested agent_merge as @agent_merge' do
get :new
assigns(:agent_merge).should_not be_valid
response.should be_successful
end
end
describe 'When logged in as User' do
login_user
it 'should not assign the requested agent_merge as @agent_merge' do
get :new
assigns(:agent_merge).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_merge as @agent_merge' do
get :new
assigns(:agent_merge).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :edit, params: { id: agent_merge.id }
assigns(:agent_merge).should eq(agent_merge)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :edit, params: { id: agent_merge.id }
assigns(:agent_merge).should eq(agent_merge)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :edit, params: { id: agent_merge.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_merge as @agent_merge' do
agent_merge = FactoryBot.create(:agent_merge)
get :edit, params: { id: agent_merge.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:agent_merge)
@invalid_attrs = { agent_id: 'invalid', agent_merge_list_id: 'invalid' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'assigns a newly created agent_merge as @agent_merge' do
post :create, params: { agent_merge: @attrs }
assigns(:agent_merge).should be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent_merge: @attrs }
response.should redirect_to(assigns(:agent_merge))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge as @agent_merge' do
post :create, params: { agent_merge: @invalid_attrs }
assigns(:agent_merge).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent_merge: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'assigns a newly created agent_merge as @agent_merge' do
post :create, params: { agent_merge: @attrs }
assigns(:agent_merge).should be_valid
end
it 'redirects to the created agent' do
post :create, params: { agent_merge: @attrs }
response.should redirect_to(assigns(:agent_merge))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge as @agent_merge' do
post :create, params: { agent_merge: @invalid_attrs }
assigns(:agent_merge).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent_merge: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'assigns a newly created agent_merge as @agent_merge' do
post :create, params: { agent_merge: @attrs }
assigns(:agent_merge).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge as @agent_merge' do
post :create, params: { agent_merge: @invalid_attrs }
assigns(:agent_merge).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created agent_merge as @agent_merge' do
post :create, params: { agent_merge: @attrs }
assigns(:agent_merge).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge as @agent_merge' do
post :create, params: { agent_merge: @invalid_attrs }
assigns(:agent_merge).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@agent_merge = FactoryBot.create(:agent_merge)
@attrs = FactoryBot.attributes_for(:agent_merge)
@invalid_attrs = { agent_merge_list_id: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'updates the requested agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
end
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
assigns(:agent_merge).should eq(@agent_merge)
response.should redirect_to(@agent_merge)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'updates the requested agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
end
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
assigns(:agent_merge).should eq(@agent_merge)
response.should redirect_to(@agent_merge)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'updates the requested agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
end
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
assigns(:agent_merge).should eq(@agent_merge)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @agent_merge.id, agent_merge: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge as @agent_merge' do
put :update, params: { id: @agent_merge.id, agent_merge: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@agent_merge = FactoryBot.create(:agent_merge)
end
describe 'When logged in as Administrator' do
login_admin
it 'destroys the requested agent_merge' do
delete :destroy, params: { id: @agent_merge.id }
end
it 'redirects to the agent_merges list' do
delete :destroy, params: { id: @agent_merge.id }
response.should redirect_to(agent_merges_url)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'destroys the requested agent_merge' do
delete :destroy, params: { id: @agent_merge.id }
end
it 'redirects to the agent_merges list' do
delete :destroy, params: { id: @agent_merge.id }
response.should redirect_to(agent_merges_url)
end
end
describe 'When logged in as User' do
login_user
it 'destroys the requested agent_merge' do
delete :destroy, params: { id: @agent_merge.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_merge.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested agent_merge' do
delete :destroy, params: { id: @agent_merge.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_merge.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/request_types_controller_spec.rb | spec/controllers/request_types_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe RequestTypesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:request_status_type)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:request_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all request_types as @request_types' do
get :index
assigns(:request_types).should eq(RequestType.order(:position))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all request_types as @request_types' do
get :index
assigns(:request_types).should eq(RequestType.order(:position))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign request_types as @request_types' do
get :index
assigns(:request_types).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign request_types as @request_types' do
get :index
assigns(:request_types).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
before(:each) do
@request_type = FactoryBot.create(:request_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested request_type as @request_type' do
get :show, params: { id: @request_type.id }
assigns(:request_type).should eq(@request_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested request_type as @request_type' do
get :show, params: { id: @request_type.id }
assigns(:request_type).should eq(@request_type)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested request_type as @request_type' do
get :show, params: { id: @request_type.id }
assigns(:request_type).should eq(@request_type)
end
end
describe 'When not logged in' do
it 'assigns the requested request_type as @request_type' do
get :show, params: { id: @request_type.id }
assigns(:request_type).should eq(@request_type)
end
end
end
describe 'GET edit' do
before(:each) do
@request_type = FactoryBot.create(:request_type)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested request_type as @request_type' do
get :edit, params: { id: @request_type.id }
assigns(:request_type).should eq(@request_type)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested request_type as @request_type' do
get :edit, params: { id: @request_type.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested request_type as @request_type' do
get :edit, params: { id: @request_type.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested request_type as @request_type' do
get :edit, params: { id: @request_type.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'PUT update' do
before(:each) do
@request_type = FactoryBot.create(:request_type)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
end
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
assigns(:request_type).should eq(@request_type)
end
it 'moves its position when specified' do
put :update, params: { id: @request_type.id, request_type: @attrs, move: 'lower' }
response.should redirect_to(request_types_url)
end
end
describe 'with invalid params' do
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
end
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
assigns(:request_type).should eq(@request_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
end
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
assigns(:request_type).should eq(@request_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested request_type' do
put :update, params: { id: @request_type.id, request_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @request_type.id, request_type: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested request_type as @request_type' do
put :update, params: { id: @request_type.id, request_type: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_merge_lists_controller_spec.rb | spec/controllers/agent_merge_lists_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe AgentMergeListsController do
fixtures :all
disconnect_sunspot
describe 'GET index' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns all agent_merge_lists as @agent_merge_lists' do
get :index
assigns(:agent_merge_lists).should eq(AgentMergeList.page(1))
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns all agent_merge_lists as @agent_merge_lists' do
get :index
assigns(:agent_merge_lists).should eq(AgentMergeList.page(1))
end
end
describe 'When logged in as User' do
login_user
it 'assigns empty as @agent_merge_lists' do
get :index
assigns(:agent_merge_lists).should be_nil
end
end
describe 'When not logged in' do
it 'assigns empty as @agent_merge_lists' do
get :index
assigns(:agent_merge_lists).should be_nil
end
end
end
describe 'GET show' do
before(:each) do
@agent_merge_list = FactoryBot.create(:agent_merge_list)
end
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested agent_merge_list as @agent_merge_list' do
get :show, params: { id: @agent_merge_list.id }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested agent_merge_list as @agent_merge_list' do
get :show, params: { id: @agent_merge_list.id }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should be_successful
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested agent_merge_list as @agent_merge_list' do
get :show, params: { id: @agent_merge_list.id }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested agent_merge_list as @agent_merge_list' do
get :show, params: { id: @agent_merge_list.id }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should redirect_to new_user_session_url
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested agent_merge_list as @agent_merge_list' do
get :new
assigns(:agent_merge_list).should_not be_valid
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested agent_merge_list as @agent_merge_list' do
get :new
assigns(:agent_merge_list).should_not be_valid
end
end
describe 'When logged in as User' do
login_user
it 'should not assign the requested agent_merge_list as @agent_merge_list' do
get :new
assigns(:agent_merge_list).should be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_merge_list as @agent_merge_list' do
get :new
assigns(:agent_merge_list).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested agent_merge_list as @agent_merge_list' do
agent_merge_list = FactoryBot.create(:agent_merge_list)
get :edit, params: { id: agent_merge_list.id }
assigns(:agent_merge_list).should eq(agent_merge_list)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested agent_merge_list as @agent_merge_list' do
agent_merge_list = FactoryBot.create(:agent_merge_list)
get :edit, params: { id: agent_merge_list.id }
assigns(:agent_merge_list).should eq(agent_merge_list)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested agent_merge_list as @agent_merge_list' do
agent_merge_list = FactoryBot.create(:agent_merge_list)
get :edit, params: { id: agent_merge_list.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested agent_merge_list as @agent_merge_list' do
agent_merge_list = FactoryBot.create(:agent_merge_list)
get :edit, params: { id: agent_merge_list.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:agent_merge_list)
@invalid_attrs = { title: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'assigns a newly created agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @attrs }
assigns(:agent_merge_list).should be_valid
end
it 'redirects to the created agent_merge_list' do
post :create, params: { agent_merge_list: @attrs }
response.should redirect_to(agent_merge_list_url(assigns(:agent_merge_list)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @invalid_attrs }
assigns(:agent_merge_list).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent_merge_list: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'assigns a newly created agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @attrs }
assigns(:agent_merge_list).should be_valid
end
it 'redirects to the created agent_merge_list' do
post :create, params: { agent_merge_list: @attrs }
response.should redirect_to(agent_merge_list_url(assigns(:agent_merge_list)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @invalid_attrs }
assigns(:agent_merge_list).should_not be_valid
end
it "re-renders the 'new' template" do
post :create, params: { agent_merge_list: @invalid_attrs }
response.should render_template('new')
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'assigns a newly created agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @attrs }
assigns(:agent_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge_list: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @invalid_attrs }
assigns(:agent_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge_list: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @attrs }
assigns(:agent_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge_list: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_merge_list as @agent_merge_list' do
post :create, params: { agent_merge_list: @invalid_attrs }
assigns(:agent_merge_list).should be_nil
end
it 'should be forbidden' do
post :create, params: { agent_merge_list: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@agent_merge_list = FactoryBot.create(:agent_merge_list)
@attrs = FactoryBot.attributes_for(:agent_merge_list)
@invalid_attrs = { title: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'updates the requested agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
end
it 'assigns the requested agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should redirect_to(@agent_merge_list)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'updates the requested agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
end
it 'assigns the requested agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should redirect_to(@agent_merge_list)
end
end
describe 'with invalid params' do
it 'assigns the agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @invalid_attrs }
assigns(:agent_merge_list).should_not be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @invalid_attrs }
response.should render_template('edit')
end
end
it 'should not merge agents without selected_agent_id' do
put :update, params: { id: agent_merge_lists(:agent_merge_list_00001).id, mode: 'merge' }
flash[:notice].should eq I18n.t('merge_list.specify_id', model: I18n.t('activerecord.models.agent'))
response.should redirect_to agent_merge_list_url(assigns(:agent_merge_list))
end
it 'should merge agents with selected_agent_idand merge_mode' do
put :update, params: { id: agent_merge_lists(:agent_merge_list_00001).id, selected_agent_id: 3, mode: 'merge' }
flash[:notice].should eq I18n.t('merge_list.successfully_merged', model: I18n.t('activerecord.models.agent'))
response.should redirect_to agent_merge_list_url(assigns(:agent_merge_list))
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'updates the requested agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
end
it 'assigns the requested agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
assigns(:agent_merge_list).should eq(@agent_merge_list)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested agent_merge_list as @agent_merge_list' do
put :update, params: { id: @agent_merge_list.id, agent_merge_list: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@agent_merge_list = FactoryBot.create(:agent_merge_list)
end
describe 'When logged in as Administrator' do
login_admin
it 'destroys the requested agent_merge_list' do
delete :destroy, params: { id: @agent_merge_list.id }
end
it 'redirects to the agent_merge_lists list' do
delete :destroy, params: { id: @agent_merge_list.id }
response.should redirect_to(agent_merge_lists_url)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'destroys the requested agent_merge_list' do
delete :destroy, params: { id: @agent_merge_list.id }
end
it 'redirects to the agent_merge_lists list' do
delete :destroy, params: { id: @agent_merge_list.id }
response.should redirect_to(agent_merge_lists_url)
end
end
describe 'When logged in as User' do
login_user
it 'destroys the requested agent_merge_list' do
delete :destroy, params: { id: @agent_merge_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_merge_list.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested agent_merge_list' do
delete :destroy, params: { id: @agent_merge_list.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @agent_merge_list.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/agent_types_controller_spec.rb | spec/controllers/agent_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe AgentTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# AgentType. As you add validations to AgentType, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:agent_type)
end
describe 'GET index' do
it 'assigns all agent_types as @agent_types' do
agent_type = AgentType.create! valid_attributes
get :index
expect(assigns(:agent_types)).to eq(AgentType.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested agent_type as @agent_type' do
agent_type = AgentType.create! valid_attributes
get :show, params: { id: agent_type.id }
expect(assigns(:agent_type)).to eq(agent_type)
end
end
describe 'GET new' do
it 'assigns a new agent_type as @agent_type' do
get :new
expect(assigns(:agent_type)).to be_a_new(AgentType)
end
end
describe 'GET edit' do
it 'assigns the requested agent_type as @agent_type' do
agent_type = AgentType.create! valid_attributes
get :edit, params: { id: agent_type.id }
expect(assigns(:agent_type)).to eq(agent_type)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new AgentType' do
expect do
post :create, params: { agent_type: valid_attributes }
end.to change(AgentType, :count).by(1)
end
it 'assigns a newly created agent_type as @agent_type' do
post :create, params: { agent_type: valid_attributes }
expect(assigns(:agent_type)).to be_a(AgentType)
expect(assigns(:agent_type)).to be_persisted
end
it 'redirects to the created agent_type' do
post :create, params: { agent_type: valid_attributes }
expect(response).to redirect_to(AgentType.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved agent_type as @agent_type' do
# Trigger the behavior that occurs when invalid params are submitted
AgentType.any_instance.stub(:save).and_return(false)
post :create, params: { agent_type: { name: 'test' } }
expect(assigns(:agent_type)).to be_a_new(AgentType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
AgentType.any_instance.stub(:save).and_return(false)
post :create, params: { agent_type: { name: 'test' } }
expect(response).to render_template('new')
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested agent_type' do
agent_type = AgentType.create! valid_attributes
# Assuming there are no other agent_types in the database, this
# specifies that the AgentType created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# AgentType.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: agent_type.id, agent_type: { 'name' => 'test' } }
end
it 'assigns the requested agent_type as @agent_type' do
agent_type = AgentType.create! valid_attributes
put :update, params: { id: agent_type.id, agent_type: valid_attributes }
expect(assigns(:agent_type)).to eq(agent_type)
end
it 'redirects to the agent_type' do
agent_type = AgentType.create! valid_attributes
put :update, params: { id: agent_type.id, agent_type: valid_attributes }
expect(response).to redirect_to(agent_type)
end
it 'moves its position when specified' do
agent_type = AgentType.create! valid_attributes
position = agent_type.position
put :update, params: { id: agent_type.id, move: 'higher' }
expect(response).to redirect_to agent_types_url
assigns(:agent_type).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the agent_type as @agent_type' do
agent_type = AgentType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
AgentType.any_instance.stub(:save).and_return(false)
put :update, params: { id: agent_type.id, agent_type: { name: 'test' } }
expect(assigns(:agent_type)).to eq(agent_type)
end
it "re-renders the 'edit' template" do
agent_type = AgentType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
AgentType.any_instance.stub(:save).and_return(false)
put :update, params: { id: agent_type.id, agent_type: { name: 'test' } }
expect(response).to render_template('edit')
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested agent_type' do
agent_type = AgentType.create! valid_attributes
expect do
delete :destroy, params: { id: agent_type.id }
end.to change(AgentType, :count).by(-1)
end
it 'redirects to the agent_types list' do
agent_type = AgentType.create! valid_attributes
delete :destroy, params: { id: agent_type.id }
expect(response).to redirect_to(agent_types_url)
end
it 'should not destroy agent_type that contains agents' do
delete :destroy, params: { id: agent_types(:agent_type_00001) }
expect(response).to be_forbidden
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/library_groups_controller_spec.rb | spec/controllers/library_groups_controller_spec.rb | require 'rails_helper'
describe LibraryGroupsController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all library_groups as @library_groups' do
get :index
assigns(:library_groups).should_not be_empty
end
end
describe 'When not logged in' do
it 'assigns all library_groups as @library_groups' do
get :index
assigns(:library_groups).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested library_group as @library_group' do
get :show, params: { id: 1 }
assigns(:library_group).should eq(LibraryGroup.find(1))
end
end
describe 'When not logged in' do
it 'assigns the requested library_group as @library_group' do
get :show, params: { id: 1 }
assigns(:library_group).should eq(LibraryGroup.find(1))
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested library_group as @library_group' do
library_group = LibraryGroup.find(1)
get :edit, params: { id: library_group.id }
assigns(:library_group).should eq(library_group)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested library_group as @library_group' do
library_group = LibraryGroup.find(1)
get :edit, params: { id: library_group.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested library_group as @library_group' do
library_group = LibraryGroup.find(1)
get :edit, params: { id: library_group.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested library_group as @library_group' do
library_group = LibraryGroup.find(1)
get :edit, params: { id: library_group.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'PUT update' do
before(:each) do
@library_group = LibraryGroup.find(1)
@attrs = { name: 'example' }
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested library_group' do
put :update, params: { id: @library_group.id, library_group: @attrs }
end
it 'assigns the requested library_group as @library_group' do
put :update, params: { id: @library_group.id, library_group: @attrs }
assigns(:library_group).should eq(@library_group)
end
end
describe 'with invalid params' do
it 'assigns the requested library_group as @library_group' do
put :update, params: { id: @library_group.id, library_group: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested library_group' do
put :update, params: { id: @library_group.id, library_group: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @library_group.id, library_group: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested library_group as @library_group' do
put :update, params: { id: @library_group.id, library_group: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/events_controller_spec.rb | spec/controllers/events_controller_spec.rb | require 'rails_helper'
describe EventsController do
fixtures :all
describe "GET index", solr: true do
before do
Event.reindex
end
before(:each) do
FactoryBot.create(:event)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all events as @events" do
get :index
assigns(:events).should_not be_nil
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all events as @events" do
get :index
assigns(:events).should_not be_nil
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns all events as @events" do
get :index
assigns(:events).should_not be_nil
end
end
describe "When not logged in" do
it "assigns all events as @events" do
get :index
assigns(:events).should_not be_nil
end
it "assigns all events as @events in rss format" do
get :index, format: 'rss'
assigns(:events).should_not be_nil
end
it "assigns all events as @events in ics format" do
get :index, format: 'ics'
assigns(:events).should_not be_nil
end
it "assigns all events as @events in text format" do
get :index, format: :text
assigns(:events).should_not be_nil
end
it "should get index with library_id" do
get :index, params: { library_id: 'kamata' }
response.should be_successful
assigns(:library).should eq libraries(:library_00002)
assigns(:events).should_not be_nil
end
it "should get upcoming event index" do
get :index, params: { mode: 'upcoming' }
response.should be_successful
assigns(:events).should_not be_nil
end
it "should get past event index" do
get :index, params: { mode: 'past' }
response.should be_successful
assigns(:events).should_not be_nil
end
describe "with json data (calendar feed)" do
render_views
it "should get all events data" do
20.times do
FactoryBot.create(:event)
end
Event.reindex
today = Time.zone.today
get :index, params: { format: "json", start: today.beginning_of_month.to_s, end: today.end_of_month.to_s }
expect(response).to be_successful
events = assigns(:events)
expect(events).not_to be_nil
expect(events.size).to be >= 20
expect(response.body).to match(/\A\[/)
data = JSON.parse(response.body)
expect(data.first).not_to be_nil
expect(data.first).to have_key("start")
expect(data.first).to have_key("url")
end
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :show, params: { id: event.id }
assigns(:event).should eq(event)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :show, params: { id: event.id }
assigns(:event).should eq(event)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :show, params: { id: event.id }
assigns(:event).should eq(event)
end
end
describe "When not logged in" do
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :show, params: { id: event.id }
assigns(:event).should eq(event)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event as @event" do
get :new
assigns(:event).should_not be_valid
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "should not assign the requested event as @event" do
get :new
assigns(:event).should_not be_valid
end
end
describe "When logged in as User" do
login_fixture_user
it "should not assign the requested event as @event" do
get :new
assigns(:event).should be_nil
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested event as @event" do
get :new
assigns(:event).should be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :edit, params: { id: event.id }
assigns(:event).should eq(event)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :edit, params: { id: event.id }
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested event as @event" do
event = FactoryBot.create(:event)
get :edit, params: { id: event.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested event as @event" do
event = FactoryBot.create(:event)
get :edit, params: { id: event.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
before(:each) do
@attrs = FactoryBot.attributes_for(:event)
@invalid_attrs = { name: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "assigns a newly created event as @event" do
post :create, params: { event: @attrs }
assigns(:event).should be_valid
end
it "redirects to the created event" do
post :create, params: { event: @attrs }
response.should redirect_to(assigns(:event))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event as @event" do
post :create, params: { event: @invalid_attrs }
assigns(:event).should_not be_valid
end
it "should be forbidden" do
post :create, params: { event: @invalid_attrs }
response.should render_template("new")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "assigns a newly created event as @event" do
post :create, params: { event: @attrs }
assigns(:event).should be_valid
end
it "redirects to the created event" do
post :create, params: { event: @attrs }
response.should redirect_to(assigns(:event))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event as @event" do
post :create, params: { event: @invalid_attrs }
assigns(:event).should_not be_valid
end
it "should be forbidden" do
post :create, params: { event: @invalid_attrs }
response.should render_template("new")
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "assigns a newly created event as @event" do
post :create, params: { event: @attrs }
assigns(:event).should be_nil
end
it "should be forbidden" do
post :create, params: { event: @attrs }
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event as @event" do
post :create, params: { event: @invalid_attrs }
assigns(:event).should be_nil
end
it "should be forbidden" do
post :create, params: { event: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "assigns a newly created event as @event" do
post :create, params: { event: @attrs }
assigns(:event).should be_nil
end
it "should be forbidden" do
post :create, params: { event: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved event as @event" do
post :create, params: { event: @invalid_attrs }
assigns(:event).should be_nil
end
it "should be forbidden" do
post :create, params: { event: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "PUT update" do
before(:each) do
@event = FactoryBot.create(:event)
@attrs = FactoryBot.attributes_for(:event)
@invalid_attrs = { name: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "updates the requested event" do
put :update, params: { id: @event.id, event: @attrs }
end
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @attrs }
assigns(:event).should eq(@event)
end
end
describe "with invalid params" do
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @invalid_attrs }
response.should render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "updates the requested event" do
put :update, params: { id: @event.id, event: @attrs }
end
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @attrs }
assigns(:event).should eq(@event)
end
end
describe "with invalid params" do
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @invalid_attrs }
response.should render_template("edit")
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "updates the requested event" do
put :update, params: { id: @event.id, event: @attrs }
end
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @attrs }
assigns(:event).should eq(@event)
response.should be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @invalid_attrs }
response.should be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested event" do
put :update, params: { id: @event.id, event: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @event.id, event: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested event as @event" do
put :update, params: { id: @event.id, event: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@event = FactoryBot.create(:event)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested event" do
delete :destroy, params: { id: @event.id }
end
it "redirects to the events list" do
delete :destroy, params: { id: @event.id }
response.should redirect_to(events_url)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested event" do
delete :destroy, params: { id: @event.id }
end
it "redirects to the events list" do
delete :destroy, params: { id: @event.id }
response.should redirect_to(events_url)
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested event" do
delete :destroy, params: { id: @event.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event.id }
response.should be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested event" do
delete :destroy, params: { id: @event.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @event.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/ndl_books_controller_spec.rb | spec/controllers/ndl_books_controller_spec.rb | require 'rails_helper'
describe NdlBooksController do
fixtures :all
it "should be a kind of enju_ndl" do
assert_kind_of Module, EnjuNdl
end
describe "GET index" do
login_fixture_admin
it "should get index", vcr: true do
get :index, params: { query: 'library' }
assigns(:books).should_not be_empty
end
it "should be empty if a query is not set", vcr: true do
get :index
assigns(:books).should be_empty
end
end
describe "POST create" do
login_fixture_admin
it "should create a bibliographic record if jpno is set", vcr: true do
post :create, params: { book: { iss_itemno: 'R100000002-I000002539673' } }
expect(assigns(:manifestation).jpno_record.body).to eq '97024234'
response.should redirect_to manifestation_url(assigns(:manifestation))
end
it "should not create a bibliographic record if jpno is not set", vcr: true do
post :create, params: { book: { jpno: nil } }
assigns(:manifestation).should be_nil
response.should redirect_to ndl_books_url
end
it "should create a serial record", vcr: true do
post :create, params: { book: { iss_itemno: 'R100000002-I000000029371' } }
expect(assigns(:manifestation).jpno_record.body).to eq '00029793'
response.should redirect_to manifestation_url(assigns(:manifestation))
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/bookmark_stats_controller_spec.rb | spec/controllers/bookmark_stats_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe BookmarkStatsController do
fixtures :all
disconnect_sunspot
describe "GET index" do
before(:each) do
FactoryBot.create(:bookmark_stat)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all bookmark_stats as @bookmark_stats" do
get :index
expect(assigns(:bookmark_stats)).to eq(BookmarkStat.page(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all bookmark_stats as @bookmark_stats" do
get :index
expect(assigns(:bookmark_stats)).to eq(BookmarkStat.page(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns all bookmark_stats as @bookmark_stats" do
get :index
expect(assigns(:bookmark_stats)).to eq(BookmarkStat.page(1))
end
end
describe "When not logged in" do
it "should not assign bookmark_stats as @bookmark_stats" do
get :index
expect(assigns(:bookmark_stats)).to eq(BookmarkStat.page(1))
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :show, params: { id: bookmark_stat.id }
expect(assigns(:bookmark_stat)).to eq(bookmark_stat)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :show, params: { id: bookmark_stat.id }
expect(assigns(:bookmark_stat)).to eq(bookmark_stat)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :show, params: { id: bookmark_stat.id }
expect(assigns(:bookmark_stat)).to eq(bookmark_stat)
end
end
describe "When not logged in" do
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :show, params: { id: bookmark_stat.id }
expect(assigns(:bookmark_stat)).to eq(bookmark_stat)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested bookmark_stat as @bookmark_stat" do
get :new
expect(assigns(:bookmark_stat)).not_to be_valid
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested bookmark_stat as @bookmark_stat" do
get :new
expect(assigns(:bookmark_stat)).not_to be_valid
end
end
describe "When logged in as User" do
login_fixture_user
it "should not assign the requested bookmark_stat as @bookmark_stat" do
get :new
expect(assigns(:bookmark_stat)).to be_nil
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested bookmark_stat as @bookmark_stat" do
get :new
expect(assigns(:bookmark_stat)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :edit, params: { id: bookmark_stat.id }
expect(assigns(:bookmark_stat)).to eq(bookmark_stat)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :edit, params: { id: bookmark_stat.id }
expect(assigns(:bookmark_stat)).to eq(bookmark_stat)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :edit, params: { id: bookmark_stat.id }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested bookmark_stat as @bookmark_stat" do
bookmark_stat = FactoryBot.create(:bookmark_stat)
get :edit, params: { id: bookmark_stat.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
before(:each) do
@attrs = FactoryBot.attributes_for(:bookmark_stat)
@invalid_attrs = { start_date: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "assigns a newly created bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to be_valid
end
it "redirects to the created bookmark_stat" do
post :create, params: { bookmark_stat: @attrs }
expect(response).to redirect_to(bookmark_stat_url(assigns(:bookmark_stat)))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(assigns(:bookmark_stat)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(response).to render_template("new")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "assigns a newly created bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to be_valid
end
it "redirects to the created bookmark_stat" do
post :create, params: { bookmark_stat: @attrs }
expect(response).to redirect_to(bookmark_stat_url(assigns(:bookmark_stat)))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(assigns(:bookmark_stat)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(response).to render_template("new")
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "assigns a newly created bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to be_nil
end
it "should be forbidden" do
post :create, params: { bookmark_stat: @attrs }
expect(response).to be_forbidden
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(assigns(:bookmark_stat)).to be_nil
end
it "should be forbidden" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "assigns a newly created bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to be_nil
end
it "should be forbidden" do
post :create, params: { bookmark_stat: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved bookmark_stat as @bookmark_stat" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(assigns(:bookmark_stat)).to be_nil
end
it "should be forbidden" do
post :create, params: { bookmark_stat: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe "PUT update" do
before(:each) do
@bookmark_stat = FactoryBot.create(:bookmark_stat)
@attrs = FactoryBot.attributes_for(:bookmark_stat)
@invalid_attrs = { start_date: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "updates the requested bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
end
it "assigns the requested bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to eq(@bookmark_stat)
end
end
describe "with invalid params" do
it "assigns the requested bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
describe "with valid params" do
it "updates the requested bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
end
it "assigns the requested bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to eq(@bookmark_stat)
expect(response).to redirect_to(@bookmark_stat)
end
end
describe "with invalid params" do
it "assigns the bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat, bookmark_stat: @invalid_attrs }
expect(assigns(:bookmark_stat)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @bookmark_stat, bookmark_stat: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When logged in as User" do
login_fixture_user
describe "with valid params" do
it "updates the requested bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
end
it "assigns the requested bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
expect(assigns(:bookmark_stat)).to eq(@bookmark_stat)
expect(response).to be_forbidden
end
end
describe "with invalid params" do
it "assigns the requested bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested bookmark_stat as @bookmark_stat" do
put :update, params: { id: @bookmark_stat.id, bookmark_stat: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe "DELETE destroy" do
before(:each) do
@bookmark_stat = FactoryBot.create(:bookmark_stat)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested bookmark_stat" do
delete :destroy, params: { id: @bookmark_stat.id }
end
it "redirects to the bookmark_stats list" do
delete :destroy, params: { id: @bookmark_stat.id }
expect(response).to redirect_to(bookmark_stats_url)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested bookmark_stat" do
delete :destroy, params: { id: @bookmark_stat.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @bookmark_stat.id }
expect(response).to be_forbidden
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested bookmark_stat" do
delete :destroy, params: { id: @bookmark_stat.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @bookmark_stat.id }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested bookmark_stat" do
delete :destroy, params: { id: @bookmark_stat.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @bookmark_stat.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/identifier_types_controller_spec.rb | spec/controllers/identifier_types_controller_spec.rb | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe IdentifierTypesController do
fixtures :all
login_fixture_admin
# This should return the minimal set of attributes required to create a valid
# IdentifierType. As you add validations to IdentifierType, be sure to
# update the return value of this method accordingly.
def valid_attributes
FactoryBot.attributes_for(:identifier_type)
end
describe 'GET index' do
it 'assigns all identifier_types as @identifier_types' do
identifier_type = IdentifierType.create! valid_attributes
get :index
expect(assigns(:identifier_types)).to eq(IdentifierType.order(:position))
end
end
describe 'GET show' do
it 'assigns the requested identifier_type as @identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
get :show, params: { id: identifier_type.id }
expect(assigns(:identifier_type)).to eq(identifier_type)
end
end
describe 'GET new' do
it 'assigns a new identifier_type as @identifier_type' do
get :new
expect(assigns(:identifier_type)).to be_a_new(IdentifierType)
end
end
describe 'GET edit' do
it 'assigns the requested identifier_type as @identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
get :edit, params: { id: identifier_type.id }
expect(assigns(:identifier_type)).to eq(identifier_type)
end
end
describe 'POST create' do
describe 'with valid params' do
it 'creates a new IdentifierType' do
expect do
post :create, params: { identifier_type: valid_attributes }
end.to change(IdentifierType, :count).by(1)
end
it 'assigns a newly created identifier_type as @identifier_type' do
post :create, params: { identifier_type: valid_attributes }
expect(assigns(:identifier_type)).to be_a(IdentifierType)
expect(assigns(:identifier_type)).to be_persisted
end
it 'redirects to the created identifier_type' do
post :create, params: { identifier_type: valid_attributes }
expect(response).to redirect_to(IdentifierType.last)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved identifier_type as @identifier_type' do
# Trigger the behavior that occurs when invalid params are submitted
IdentifierType.any_instance.stub(:save).and_return(false)
post :create, params: { identifier_type: { name: 'test' } }
expect(assigns(:identifier_type)).to be_a_new(IdentifierType)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
IdentifierType.any_instance.stub(:save).and_return(false)
post :create, params: { identifier_type: { name: 'test' } }
expect(response).to render_template('new')
end
end
end
describe 'PUT update' do
describe 'with valid params' do
it 'updates the requested identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
# Assuming there are no other identifier_types in the database, this
# specifies that the IdentifierType created on the previous line
# receives the :update message with whatever params are
# submitted in the request.
# IdentifierType.any_instance.should_receive(:update).with('name' => 'test')
put :update, params: { id: identifier_type.id, identifier_type: { 'name' => 'test' } }
end
it 'assigns the requested identifier_type as @identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
put :update, params: { id: identifier_type.id, identifier_type: valid_attributes }
expect(assigns(:identifier_type)).to eq(identifier_type)
end
it 'redirects to the identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
put :update, params: { id: identifier_type.id, identifier_type: valid_attributes }
expect(response).to redirect_to(identifier_type)
end
it 'moves its position when specified' do
identifier_type = IdentifierType.create! valid_attributes
position = identifier_type.position
put :update, params: { id: identifier_type.id, move: 'higher' }
expect(response).to redirect_to identifier_types_url
assigns(:identifier_type).reload.position.should eq position - 1
end
end
describe 'with invalid params' do
it 'assigns the identifier_type as @identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
IdentifierType.any_instance.stub(:save).and_return(false)
put :update, params: { id: identifier_type.id, identifier_type: { name: 'test' } }
expect(assigns(:identifier_type)).to eq(identifier_type)
end
it "re-renders the 'edit' template" do
identifier_type = IdentifierType.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
IdentifierType.any_instance.stub(:save).and_return(false)
put :update, params: { id: identifier_type.id, identifier_type: { name: 'test' } }
expect(response).to render_template('edit')
end
end
end
describe 'DELETE destroy' do
it 'destroys the requested identifier_type' do
identifier_type = IdentifierType.create! valid_attributes
expect do
delete :destroy, params: { id: identifier_type.id }
end.to change(IdentifierType, :count).by(-1)
end
it 'redirects to the identifier_types list' do
identifier_type = IdentifierType.create! valid_attributes
delete :destroy, params: { id: identifier_type.id }
expect(response).to redirect_to(identifier_types_url)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/cinii_books_controller_spec.rb | spec/controllers/cinii_books_controller_spec.rb | require 'rails_helper'
describe CiniiBooksController do
fixtures :all
it "should be a kind of enju_nii" do
assert_kind_of Module, EnjuNii
end
describe "GET index" do
login_fixture_admin
it "should get index", vcr: true do
get :index, params: { query: 'library' }
assigns(:books).should_not be_empty
end
it "should be empty if a query is not set", vcr: true do
get :index, params: { query: '' }
assigns(:books).should be_empty
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/subject_heading_types_controller_spec.rb | spec/controllers/subject_heading_types_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe SubjectHeadingTypesController do
fixtures :all
disconnect_sunspot
def valid_attributes
FactoryBot.attributes_for(:subject_heading_type)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:subject_heading_type)
end
describe 'When logged in as Administrator' do
login_admin
it 'assigns all subject_heading_types as @subject_heading_types' do
get :index
expect(assigns(:subject_heading_types)).to eq(SubjectHeadingType.order(:position))
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns all subject_heading_types as @subject_heading_types' do
get :index
expect(assigns(:subject_heading_types)).to eq(SubjectHeadingType.order(:position))
end
end
describe 'When logged in as User' do
login_user
it 'assigns all subject_heading_types as @subject_heading_types' do
get :index
expect(assigns(:subject_heading_types)).to eq(SubjectHeadingType.order(:position))
end
end
describe 'When not logged in' do
it 'assigns all subject_heading_types as @subject_heading_types' do
get :index
expect(assigns(:subject_heading_types)).to eq(SubjectHeadingType.order(:position))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :show, params: { id: subject_heading_type.id }
expect(assigns(:subject_heading_type)).to eq(subject_heading_type)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :show, params: { id: subject_heading_type.id }
expect(assigns(:subject_heading_type)).to eq(subject_heading_type)
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :show, params: { id: subject_heading_type.id }
expect(assigns(:subject_heading_type)).to eq(subject_heading_type)
end
end
describe 'When not logged in' do
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :show, params: { id: subject_heading_type.id }
expect(assigns(:subject_heading_type)).to eq(subject_heading_type)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested subject_heading_type as @subject_heading_type' do
get :new
expect(assigns(:subject_heading_type)).not_to be_valid
response.should be_successful
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'should not assign the requested subject_heading_type as @subject_heading_type' do
get :new
expect(assigns(:subject_heading_type)).to be_nil
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'should not assign the requested subject_heading_type as @subject_heading_type' do
get :new
expect(assigns(:subject_heading_type)).to be_nil
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subject_heading_type as @subject_heading_type' do
get :new
expect(assigns(:subject_heading_type)).to be_nil
response.should redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_admin
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :edit, params: { id: subject_heading_type.id }
expect(assigns(:subject_heading_type)).to eq(subject_heading_type)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :edit, params: { id: subject_heading_type.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'assigns the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :edit, params: { id: subject_heading_type.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested subject_heading_type as @subject_heading_type' do
subject_heading_type = FactoryBot.create(:subject_heading_type)
get :edit, params: { id: subject_heading_type.id }
response.should redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'assigns a newly created subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to be_valid
end
it 'redirects to the created agent' do
post :create, params: { subject_heading_type: @attrs }
response.should redirect_to(assigns(:subject_heading_type))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @invalid_attrs }
expect(assigns(:subject_heading_type)).not_to be_valid
end
it 'should be successful' do
post :create, params: { subject_heading_type: @invalid_attrs }
response.should be_successful
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'assigns a newly created subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject_heading_type: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @invalid_attrs }
expect(assigns(:subject_heading_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject_heading_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'assigns a newly created subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject_heading_type: @attrs }
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @invalid_attrs }
expect(assigns(:subject_heading_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject_heading_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject_heading_type: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved subject_heading_type as @subject_heading_type' do
post :create, params: { subject_heading_type: @invalid_attrs }
expect(assigns(:subject_heading_type)).to be_nil
end
it 'should be forbidden' do
post :create, params: { subject_heading_type: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@subject_heading_type = FactoryBot.create(:subject_heading_type)
@attrs = valid_attributes
@invalid_attrs = { name: '' }
end
describe 'When logged in as Administrator' do
login_admin
describe 'with valid params' do
it 'updates the requested subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
end
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to eq(@subject_heading_type)
end
it 'moves its position when specified' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs, move: 'lower' }
response.should redirect_to(subject_heading_types_url)
end
end
describe 'with invalid params' do
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @invalid_attrs }
response.should render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_librarian
describe 'with valid params' do
it 'updates the requested subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
end
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to eq(@subject_heading_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When logged in as User' do
login_user
describe 'with valid params' do
it 'updates the requested subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
end
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
expect(assigns(:subject_heading_type)).to eq(@subject_heading_type)
response.should be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @invalid_attrs }
response.should be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @attrs }
response.should redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested subject_heading_type as @subject_heading_type' do
put :update, params: { id: @subject_heading_type.id, subject_heading_type: @invalid_attrs }
response.should redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@subject_heading_type = FactoryBot.create(:subject_heading_type)
end
describe 'When logged in as Administrator' do
login_admin
it 'destroys the requested subject_heading_type' do
delete :destroy, params: { id: @subject_heading_type.id }
end
it 'redirects to the subject_heading_types list' do
delete :destroy, params: { id: @subject_heading_type.id }
response.should redirect_to(subject_heading_types_url)
end
end
describe 'When logged in as Librarian' do
login_librarian
it 'destroys the requested subject_heading_type' do
delete :destroy, params: { id: @subject_heading_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subject_heading_type.id }
response.should be_forbidden
end
end
describe 'When logged in as User' do
login_user
it 'destroys the requested subject_heading_type' do
delete :destroy, params: { id: @subject_heading_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subject_heading_type.id }
response.should be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested subject_heading_type' do
delete :destroy, params: { id: @subject_heading_type.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @subject_heading_type.id }
response.should redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/roles_controller_spec.rb | spec/controllers/roles_controller_spec.rb | require 'spec_helper'
describe RolesController do
fixtures :all
describe "GET index" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all roles as @roles" do
get :index
expect(assigns(:roles)).to eq(Role.order(:position))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all roles as @roles" do
get :index
expect(assigns(:roles)).to eq(Role.order(:position))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns all roles as @roles" do
get :index
expect(assigns(:roles)).to be_nil
end
end
describe "When not logged in" do
it "assigns all roles as @roles" do
get :index
expect(assigns(:roles)).to be_nil
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested role as @role" do
role = Role.find(1)
get :show, params: { id: role.id }
expect(assigns(:role)).to eq(role)
end
end
describe "When not logged in" do
it "assigns the requested role as @role" do
role = Role.find(1)
get :show, params: { id: role.id }
expect(assigns(:role)).to eq(role)
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested role as @role" do
role = Role.find(1)
get :edit, params: { id: role.id }
expect(assigns(:role)).to eq(role)
end
end
describe "When not logged in" do
it "should not assign the requested role as @role" do
role = Role.find(1)
get :edit, params: { id: role.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "PUT update" do
before(:each) do
@role = Role.find(1)
@attrs = { display_name: 'guest user' }
@invalid_attrs = { name: '' }
end
describe "When logged in as Administrator" do
login_fixture_admin
describe "with valid params" do
it "updates the requested role" do
put :update, params: { id: @role.id, role: @attrs }
end
it "assigns the requested role as @role" do
put :update, params: { id: @role.id, role: @attrs }
expect(assigns(:role)).to eq(@role)
end
it "moves its position when specified" do
put :update, params: { id: @role.id, role: @attrs, move: 'lower' }
expect(response).to redirect_to(roles_url)
end
end
describe "with invalid params" do
it "assigns the requested role as @role" do
put :update, params: { id: @role.id, role: @invalid_attrs }
expect(response).to render_template("edit")
end
end
end
describe "When not logged in" do
describe "with valid params" do
it "updates the requested role" do
put :update, params: { id: @role.id, role: @attrs }
end
it "should be forbidden" do
put :update, params: { id: @role.id, role: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe "with invalid params" do
it "assigns the requested role as @role" do
put :update, params: { id: @role.id, role: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/loc_search_controller_spec.rb | spec/controllers/loc_search_controller_spec.rb | require 'rails_helper'
describe LocSearchController do
fixtures :all
it "should be a kind of enju_loc" do
assert_kind_of Module, EnjuLoc
end
describe "GET index" do
login_fixture_librarian
it "should get index", vcr: true do
get :index, params: { query: 'library' }
expect(assigns(:books)).not_to be_empty
end
it "should be empty if a query is not set", vcr: true do
get :index
expect(assigns(:books)).to be_empty
end
it "should get index with page parameter", vcr: true do
get :index, params: { query: 'library', page: 2 }
expect(assigns(:books)).not_to be_empty
end
end
describe "POST create" do
login_fixture_librarian
it "should create a bibliographic record if lccn is set", vcr: true do
post :create, params: { book: { lccn: '2013385616' } }
expect(assigns(:manifestation).lccn_record.body).to eq '2013385616'
expect(response).to redirect_to manifestation_url(assigns(:manifestation))
end
it "should not create a bibliographic record if lccn is not set", vcr: true do
post :create, params: { book: {} }
expect(assigns(:manifestation)).to be_nil
expect(response).to redirect_to loc_search_index_url
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/inventory_files_controller_spec.rb | spec/controllers/inventory_files_controller_spec.rb | require 'rails_helper'
describe InventoryFilesController do
fixtures :all
describe "GET index" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns all inventory_files as @inventory_files" do
get :index
expect(assigns(:inventory_files)).to eq(InventoryFile.page(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns all inventory_files as @inventory_files" do
get :index
expect(assigns(:inventory_files)).to eq(InventoryFile.page(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns empty as @inventory_files" do
get :index
expect(assigns(:inventory_files)).to be_nil
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "assigns empty as @inventory_files" do
get :index
expect(assigns(:inventory_files)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "GET show" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
end
end
describe "When not logged in" do
it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "GET new" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested inventory_file as @inventory_file" do
get :new
expect(assigns(:inventory_file)).to_not be_valid
expect(response).to be_successful
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "should not assign the requested inventory_file as @inventory_file" do
get :new
expect(assigns(:inventory_file)).to_not be_valid
expect(response).to be_successful
end
end
describe "When logged in as User" do
login_fixture_user
it "should not assign the requested inventory_file as @inventory_file" do
get :new
expect(assigns(:inventory_file)).to be_nil
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested inventory_file as @inventory_file" do
get :new
expect(assigns(:inventory_file)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "POST create" do
describe "When logged in as Librarian" do
login_fixture_librarian
it "should create inventory_file" do
post :create, params: { inventory_file: { shelf_id: 1, attachment: fixture_file_upload("inventory_file_sample.tsv", 'text/csv') } }
expect(assigns(:inventory_file)).to be_valid
expect(assigns(:inventory_file).user.username).to eq @user.username
expect(response).to redirect_to inventory_file_url(assigns(:inventory_file))
end
end
describe "When logged in as User" do
login_fixture_user
it "should be forbidden" do
post :create, params: { inventory_file: { shelf_id: 1, attachment: fixture_file_upload("inventory_file_sample.tsv", 'text/csv') } }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should be redirect to new session url" do
post :create, params: { inventory_file: { shelf_id: 1, attachment: fixture_file_upload("inventory_file_sample.tsv", 'text/csv') } }
expect(response).to redirect_to new_user_session_url
end
end
end
describe "GET edit" do
describe "When logged in as Administrator" do
login_fixture_admin
it "assigns the requested inventory_file as @inventory_file" do
inventory_file = inventory_files(:inventory_file_00001)
get :edit, params: { id: inventory_file.id }
expect(assigns(:inventory_file)).to eq(inventory_file)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "assigns the requested inventory_file as @inventory_file" do
inventory_file = inventory_files(:inventory_file_00001)
get :edit, params: { id: inventory_file.id }
expect(assigns(:inventory_file)).to eq(inventory_file)
end
end
describe "When logged in as User" do
login_fixture_user
it "assigns the requested inventory_file as @inventory_file" do
inventory_file = inventory_files(:inventory_file_00001)
get :edit, params: { id: inventory_file.id }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should not assign the requested inventory_file as @inventory_file" do
inventory_file = inventory_files(:inventory_file_00001)
get :edit, params: { id: inventory_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe "PUT update" do
describe "When logged in as Administrator" do
login_fixture_admin
it "should update inventory_file" do
put :update, params: { id: inventory_files(:inventory_file_00003).id, inventory_file: { note: "test" } }
expect(response).to redirect_to inventory_file_url(assigns(:inventory_file))
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "should update inventory_file" do
put :update, params: { id: inventory_files(:inventory_file_00003).id, inventory_file: { note: "test" } }
expect(response).to redirect_to inventory_file_url(assigns(:inventory_file))
end
end
describe "When logged in as User" do
login_fixture_user
it "should not update inventory_file" do
put :update, params: { id: inventory_files(:inventory_file_00003).id, inventory_file: { note: "test" } }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "should not update inventory_file" do
put :update, params: { id: inventory_files(:inventory_file_00003).id, inventory_file: { note: "test" } }
expect(response).to redirect_to new_user_session_url
end
end
end
describe "DELETE destroy" do
before(:each) do
@inventory_file = inventory_files(:inventory_file_00001)
end
describe "When logged in as Administrator" do
login_fixture_admin
it "destroys the requested inventory_file" do
delete :destroy, params: { id: @inventory_file.id }
end
it "redirects to the inventory_files list" do
delete :destroy, params: { id: @inventory_file.id }
expect(response).to redirect_to(inventory_files_url)
end
end
describe "When logged in as Librarian" do
login_fixture_librarian
it "destroys the requested inventory_file" do
delete :destroy, params: { id: @inventory_file.id }
end
it "redirects to the inventory_files list" do
delete :destroy, params: { id: @inventory_file.id }
expect(response).to redirect_to(inventory_files_url)
end
end
describe "When logged in as User" do
login_fixture_user
it "destroys the requested inventory_file" do
delete :destroy, params: { id: @inventory_file.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @inventory_file.id }
expect(response).to be_forbidden
end
end
describe "When not logged in" do
it "destroys the requested inventory_file" do
delete :destroy, params: { id: @inventory_file.id }
end
it "should be forbidden" do
delete :destroy, params: { id: @inventory_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/manifestation_relationships_controller_spec.rb | spec/controllers/manifestation_relationships_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe ManifestationRelationshipsController do
fixtures :all
disconnect_sunspot
def valid_attributes
@attrs = FactoryBot.attributes_for(:manifestation_relationship)
end
describe 'GET index' do
before(:each) do
FactoryBot.create(:manifestation_relationship)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all manifestation_relationships as @manifestation_relationships' do
get :index
expect(assigns(:manifestation_relationships)).to eq(ManifestationRelationship.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all manifestation_relationships as @manifestation_relationships' do
get :index
expect(assigns(:manifestation_relationships)).to eq(ManifestationRelationship.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all manifestation_relationships as @manifestation_relationships' do
get :index
expect(assigns(:manifestation_relationships)).to eq(ManifestationRelationship.page(1))
end
end
describe 'When not logged in' do
it 'assigns all manifestation_relationships as @manifestation_relationships' do
get :index
expect(assigns(:manifestation_relationships)).to eq(ManifestationRelationship.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :show, params: { id: manifestation_relationship.id }
expect(assigns(:manifestation_relationship)).to eq(manifestation_relationship)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :show, params: { id: manifestation_relationship.id }
expect(assigns(:manifestation_relationship)).to eq(manifestation_relationship)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :show, params: { id: manifestation_relationship.id }
expect(assigns(:manifestation_relationship)).to eq(manifestation_relationship)
end
end
describe 'When not logged in' do
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :show, params: { id: manifestation_relationship.id }
expect(assigns(:manifestation_relationship)).to eq(manifestation_relationship)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
get :new
expect(assigns(:manifestation_relationship)).to be_nil
expect(response).to redirect_to manifestations_url
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested manifestation_relationship as @manifestation_relationship' do
get :new
expect(assigns(:manifestation_relationship)).to be_nil
expect(response).to redirect_to manifestations_url
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested manifestation_relationship as @manifestation_relationship' do
get :new
expect(assigns(:manifestation_relationship)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_relationship as @manifestation_relationship' do
get :new
expect(assigns(:manifestation_relationship)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :edit, params: { id: manifestation_relationship.id }
expect(assigns(:manifestation_relationship)).to eq(manifestation_relationship)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :edit, params: { id: manifestation_relationship.id }
expect(assigns(:manifestation_relationship)).to eq(manifestation_relationship)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :edit, params: { id: manifestation_relationship.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested manifestation_relationship as @manifestation_relationship' do
manifestation_relationship = FactoryBot.create(:manifestation_relationship)
get :edit, params: { id: manifestation_relationship.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = valid_attributes
@invalid_attrs = { parent_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to be_valid
end
it 'redirects to the created manifestation' do
post :create, params: { manifestation_relationship: @attrs }
expect(response).to redirect_to(assigns(:manifestation_relationship))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(assigns(:manifestation_relationship)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to be_valid
end
it 'redirects to the created manifestation' do
post :create, params: { manifestation_relationship: @attrs }
expect(response).to redirect_to(assigns(:manifestation_relationship))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(assigns(:manifestation_relationship)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(assigns(:manifestation_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved manifestation_relationship as @manifestation_relationship' do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(assigns(:manifestation_relationship)).to be_nil
end
it 'should be forbidden' do
post :create, params: { manifestation_relationship: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@manifestation_relationship = FactoryBot.create(:manifestation_relationship)
@attrs = valid_attributes
@invalid_attrs = { parent_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
end
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to eq(@manifestation_relationship)
expect(response).to redirect_to(@manifestation_relationship)
end
it 'moves its position when specified' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs, move: 'lower', manifestation_id: @manifestation_relationship.parent.id }
expect(response).to redirect_to(manifestation_relationships_url(manifestation_id: @manifestation_relationship.parent_id))
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
end
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to eq(@manifestation_relationship)
expect(response).to redirect_to(@manifestation_relationship)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
end
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
expect(assigns(:manifestation_relationship)).to eq(@manifestation_relationship)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested manifestation_relationship as @manifestation_relationship' do
put :update, params: { id: @manifestation_relationship.id, manifestation_relationship: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@manifestation_relationship = FactoryBot.create(:manifestation_relationship)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested manifestation_relationship' do
delete :destroy, params: { id: @manifestation_relationship.id }
end
it 'redirects to the manifestation_relationships list' do
delete :destroy, params: { id: @manifestation_relationship.id }
expect(response).to redirect_to(manifestation_relationships_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested manifestation_relationship' do
delete :destroy, params: { id: @manifestation_relationship.id }
end
it 'redirects to the manifestation_relationships list' do
delete :destroy, params: { id: @manifestation_relationship.id }
expect(response).to redirect_to(manifestation_relationships_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested manifestation_relationship' do
delete :destroy, params: { id: @manifestation_relationship.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_relationship.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested manifestation_relationship' do
delete :destroy, params: { id: @manifestation_relationship.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @manifestation_relationship.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/resource_import_results_controller_spec.rb | spec/controllers/resource_import_results_controller_spec.rb | require 'rails_helper'
describe ResourceImportResultsController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all resource_import_results as @resource_import_results' do
get :index
expect(assigns(:resource_import_results)).to eq(ResourceImportResult.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all resource_import_results as @resource_import_results' do
get :index
expect(assigns(:resource_import_results)).to eq(ResourceImportResult.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns empty as @resource_import_results' do
get :index
expect(assigns(:resource_import_results)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @resource_import_results' do
get :index
expect(assigns(:resource_import_results)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_import_result as @resource_import_result' do
get :show, params: { id: 1 }
expect(assigns(:resource_import_result)).to eq(ResourceImportResult.find(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested resource_import_result as @resource_import_result' do
get :show, params: { id: 1 }
expect(assigns(:resource_import_result)).to eq(ResourceImportResult.find(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested resource_import_result as @resource_import_result' do
get :show, params: { id: 1 }
expect(assigns(:resource_import_result)).to eq(ResourceImportResult.find(1))
end
end
describe 'When not logged in' do
it 'assigns the requested resource_import_result as @resource_import_result' do
get :show, params: { id: 1 }
expect(assigns(:resource_import_result)).to eq(ResourceImportResult.find(1))
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'DELETE destroy' do
before(:each) do
@resource_import_result = resource_import_results(:one)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested resource_import_result' do
delete :destroy, params: { id: @resource_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_import_result.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested resource_import_result' do
delete :destroy, params: { id: @resource_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_import_result.id }
expect(response).to be_forbidden
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested resource_import_result' do
delete :destroy, params: { id: @resource_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_import_result.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested resource_import_result' do
delete :destroy, params: { id: @resource_import_result.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_import_result.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/realizes_controller_spec.rb | spec/controllers/realizes_controller_spec.rb | require 'rails_helper'
require 'sunspot/rails/spec_helper'
describe RealizesController do
fixtures :all
disconnect_sunspot
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all realizes as @realizes' do
get :index
expect(assigns(:realizes)).to eq(Realize.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all realizes as @realizes' do
get :index
expect(assigns(:realizes)).to eq(Realize.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns all realizes as @realizes' do
get :index
expect(assigns(:realizes)).to eq(Realize.page(1))
end
end
describe 'When not logged in' do
it 'assigns all realizes as @realizes' do
get :index
expect(assigns(:realizes)).to eq(Realize.page(1))
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :show, params: { id: realize.id }
expect(assigns(:realize)).to eq(realize)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :show, params: { id: realize.id }
expect(assigns(:realize)).to eq(realize)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :show, params: { id: realize.id }
expect(assigns(:realize)).to eq(realize)
end
end
describe 'When not logged in' do
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :show, params: { id: realize.id }
expect(assigns(:realize)).to eq(realize)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested realize as @realize' do
get :new
expect(assigns(:realize)).not_to be_valid
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested realize as @realize' do
get :new
expect(assigns(:realize)).not_to be_valid
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested realize as @realize' do
get :new
expect(assigns(:realize)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested realize as @realize' do
get :new
expect(assigns(:realize)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :edit, params: { id: realize.id }
expect(assigns(:realize)).to eq(realize)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :edit, params: { id: realize.id }
expect(assigns(:realize)).to eq(realize)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :edit, params: { id: realize.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested realize as @realize' do
realize = FactoryBot.create(:realize)
get :edit, params: { id: realize.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
before(:each) do
@attrs = FactoryBot.attributes_for(:realize)
@invalid_attrs = { expression_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'assigns a newly created realize as @realize' do
post :create, params: { realize: @attrs }
expect(assigns(:realize)).to be_valid
end
it 'redirects to the created realize' do
post :create, params: { realize: @attrs }
expect(response).to redirect_to(realize_url(assigns(:realize)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved realize as @realize' do
post :create, params: { realize: @invalid_attrs }
expect(assigns(:realize)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { realize: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'assigns a newly created realize as @realize' do
post :create, params: { realize: @attrs }
expect(assigns(:realize)).to be_valid
end
it 'redirects to the created realize' do
post :create, params: { realize: @attrs }
expect(response).to redirect_to(realize_url(assigns(:realize)))
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved realize as @realize' do
post :create, params: { realize: @invalid_attrs }
expect(assigns(:realize)).not_to be_valid
end
it "re-renders the 'new' template" do
post :create, params: { realize: @invalid_attrs }
expect(response).to render_template('new')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'assigns a newly created realize as @realize' do
post :create, params: { realize: @attrs }
expect(assigns(:realize)).to be_nil
end
it 'should be forbidden' do
post :create, params: { realize: @attrs }
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved realize as @realize' do
post :create, params: { realize: @invalid_attrs }
expect(assigns(:realize)).to be_nil
end
it 'should be forbidden' do
post :create, params: { realize: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'assigns a newly created realize as @realize' do
post :create, params: { realize: @attrs }
expect(assigns(:realize)).to be_nil
end
it 'should redirect to new_user_session_url' do
post :create, params: { realize: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns a newly created but unsaved realize as @realize' do
post :create, params: { realize: @invalid_attrs }
expect(assigns(:realize)).to be_nil
end
it 'should redirect to new_user_session_url' do
post :create, params: { realize: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'PUT update' do
before(:each) do
@realize = realizes(:realize_00001)
@attrs = FactoryBot.attributes_for(:realize)
@invalid_attrs = { expression_id: '' }
end
describe 'When logged in as Administrator' do
login_fixture_admin
describe 'with valid params' do
it 'updates the requested realize' do
put :update, params: { id: @realize.id, realize: @attrs }
end
it 'assigns the requested realize as @realize' do
put :update, params: { id: @realize.id, realize: @attrs }
expect(assigns(:realize)).to eq(@realize)
expect(response).to redirect_to(@realize)
end
end
describe 'with invalid params' do
it 'assigns the requested realize as @realize' do
put :update, params: { id: @realize.id, realize: @invalid_attrs }
end
it "re-renders the 'edit' template" do
put :update, params: { id: @realize.id, realize: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
describe 'with valid params' do
it 'updates the requested realize' do
put :update, params: { id: @realize.id, realize: @attrs }
end
it 'assigns the requested realize as @realize' do
put :update, params: { id: @realize.id, realize: @attrs }
expect(assigns(:realize)).to eq(@realize)
expect(response).to redirect_to(@realize)
end
it 'moves its position when specified' do
position = @realize.position
put :update, params: { id: @realize.id, expression_id: @realize.expression.id, move: 'lower' }
expect(response).to redirect_to realizes_url(expression_id: @realize.expression_id)
assigns(:realize).reload.position.should eq position + 1
end
end
describe 'with invalid params' do
it 'assigns the realize as @realize' do
put :update, params: { id: @realize.id, realize: @invalid_attrs }
expect(assigns(:realize)).not_to be_valid
end
it "re-renders the 'edit' template" do
put :update, params: { id: @realize.id, realize: @invalid_attrs }
expect(response).to render_template('edit')
end
end
end
describe 'When logged in as User' do
login_fixture_user
describe 'with valid params' do
it 'updates the requested realize' do
put :update, params: { id: @realize.id, realize: @attrs }
end
it 'assigns the requested realize as @realize' do
put :update, params: { id: @realize.id, realize: @attrs }
expect(assigns(:realize)).to eq(@realize)
expect(response).to be_forbidden
end
end
describe 'with invalid params' do
it 'assigns the requested realize as @realize' do
put :update, params: { id: @realize.id, realize: @invalid_attrs }
expect(response).to be_forbidden
end
end
end
describe 'When not logged in' do
describe 'with valid params' do
it 'updates the requested realize' do
put :update, params: { id: @realize.id, realize: @attrs }
end
it 'should be forbidden' do
put :update, params: { id: @realize.id, realize: @attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
describe 'with invalid params' do
it 'assigns the requested realize as @realize' do
put :update, params: { id: @realize.id, realize: @invalid_attrs }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
describe 'DELETE destroy' do
before(:each) do
@realize = FactoryBot.create(:realize)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested realize' do
delete :destroy, params: { id: @realize.id }
end
it 'redirects to the realizes list' do
delete :destroy, params: { id: @realize.id }
expect(response).to redirect_to(realizes_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested realize' do
delete :destroy, params: { id: @realize.id }
end
it 'redirects to the realizes list' do
delete :destroy, params: { id: @realize.id }
expect(response).to redirect_to(realizes_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested realize' do
delete :destroy, params: { id: @realize.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @realize.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested realize' do
delete :destroy, params: { id: @realize.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @realize.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/resource_export_files_controller_spec.rb | spec/controllers/resource_export_files_controller_spec.rb | require 'rails_helper'
describe ResourceExportFilesController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all resource_export_files as @resource_export_files' do
get :index
expect(assigns(:resource_export_files)).to eq(ResourceExportFile.order('id DESC').page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all resource_export_files as @resource_export_files' do
get :index
expect(assigns(:resource_export_files)).to eq(ResourceExportFile.order('id DESC').page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns empty as @resource_export_files' do
get :index
expect(assigns(:resource_export_files)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @resource_export_files' do
get :index
expect(assigns(:resource_export_files)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_export_file as @resource_export_file' do
get :show, params: { id: resource_export_files(:resource_export_file_00003).id }
expect(assigns(:resource_export_file)).to eq(resource_export_files(:resource_export_file_00003))
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested resource_export_file as @resource_export_file' do
get :show, params: { id: resource_export_files(:resource_export_file_00003).id }
expect(assigns(:resource_export_file)).to eq(resource_export_files(:resource_export_file_00003))
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested resource_export_file as @resource_export_file' do
get :show, params: { id: resource_export_files(:resource_export_file_00003).id }
expect(assigns(:resource_export_file)).to eq(resource_export_files(:resource_export_file_00003))
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested resource_export_file as @resource_export_file' do
get :show, params: { id: resource_export_files(:resource_export_file_00003).id }
expect(assigns(:resource_export_file)).to eq(resource_export_files(:resource_export_file_00003))
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_export_file as @resource_export_file' do
get :new
expect(assigns(:resource_export_file)).to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested resource_export_file as @resource_export_file' do
get :new
expect(assigns(:resource_export_file)).to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested resource_export_file as @resource_export_file' do
get :new
expect(assigns(:resource_export_file)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested resource_export_file as @resource_export_file' do
get :new
expect(assigns(:resource_export_file)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should create agent_export_file' do
post :create, params: { resource_export_file: { mode: 'export' } }
expect(assigns(:resource_export_file)).to be_valid
assigns(:resource_export_file).user.username.should eq @user.username
expect(response).to redirect_to resource_export_file_url(assigns(:resource_export_file))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should be forbidden' do
post :create, params: { resource_export_file: { mode: 'export' } }
assigns(:resource_export_file).should be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should be redirected to new session url' do
post :create, params: { resource_export_file: { mode: 'export' } }
assigns(:resource_export_file).should be_nil
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_export_file as @resource_export_file' do
resource_export_file = resource_export_files(:resource_export_file_00001)
get :edit, params: { id: resource_export_file.id }
expect(assigns(:resource_export_file)).to eq(resource_export_file)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested resource_export_file as @resource_export_file' do
resource_export_file = resource_export_files(:resource_export_file_00001)
get :edit, params: { id: resource_export_file.id }
expect(assigns(:resource_export_file)).to eq(resource_export_file)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested resource_export_file as @resource_export_file' do
resource_export_file = resource_export_files(:resource_export_file_00001)
get :edit, params: { id: resource_export_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested resource_export_file as @resource_export_file' do
resource_export_file = resource_export_files(:resource_export_file_00001)
get :edit, params: { id: resource_export_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'PUT update' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'should update resource_export_file' do
put :update, params: { id: resource_export_files(:resource_export_file_00003).id, resource_export_file: { mode: 'export' } }
expect(response).to redirect_to resource_export_file_url(assigns(:resource_export_file))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should update resource_export_file' do
put :update, params: { id: resource_export_files(:resource_export_file_00003).id, resource_export_file: { mode: 'export' } }
expect(response).to redirect_to resource_export_file_url(assigns(:resource_export_file))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not update resource_export_file' do
put :update, params: { id: resource_export_files(:resource_export_file_00003).id, resource_export_file: { mode: 'export' } }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not update resource_export_file' do
put :update, params: { id: resource_export_files(:resource_export_file_00003).id, resource_export_file: { mode: 'export' } }
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'DELETE destroy' do
before(:each) do
@resource_export_file = resource_export_files(:resource_export_file_00001)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested resource_export_file' do
delete :destroy, params: { id: @resource_export_file.id }
end
it 'redirects to the resource_export_files list' do
delete :destroy, params: { id: @resource_export_file.id }
expect(response).to redirect_to(resource_export_files_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested resource_export_file' do
delete :destroy, params: { id: @resource_export_file.id }
end
it 'redirects to the resource_export_files list' do
delete :destroy, params: { id: @resource_export_file.id }
expect(response).to redirect_to(resource_export_files_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested resource_export_file' do
delete :destroy, params: { id: @resource_export_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_export_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested resource_export_file' do
delete :destroy, params: { id: @resource_export_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_export_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/spec/controllers/resource_import_files_controller_spec.rb | spec/controllers/resource_import_files_controller_spec.rb | require 'rails_helper'
describe ResourceImportFilesController do
fixtures :all
describe 'GET index' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns all resource_import_files as @resource_import_files' do
get :index
expect(assigns(:resource_import_files)).to eq(ResourceImportFile.page(1))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns all resource_import_files as @resource_import_files' do
get :index
expect(assigns(:resource_import_files)).to eq(ResourceImportFile.page(1))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns empty as @resource_import_files' do
get :index
expect(assigns(:resource_import_files)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns empty as @resource_import_files' do
get :index
expect(assigns(:resource_import_files)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET show' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_import_file as @resource_import_file' do
get :show, params: { id: resource_import_files(:resource_import_file_00003).id }
expect(assigns(:resource_import_file)).to eq(resource_import_files(:resource_import_file_00003))
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested resource_import_file as @resource_import_file' do
get :show, params: { id: resource_import_files(:resource_import_file_00003).id }
expect(assigns(:resource_import_file)).to eq(resource_import_files(:resource_import_file_00003))
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested resource_import_file as @resource_import_file' do
get :show, params: { id: resource_import_files(:resource_import_file_00003).id }
expect(assigns(:resource_import_file)).to eq(resource_import_files(:resource_import_file_00003))
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'assigns the requested resource_import_file as @resource_import_file' do
get :show, params: { id: resource_import_files(:resource_import_file_00003).id }
expect(assigns(:resource_import_file)).to eq(resource_import_files(:resource_import_file_00003))
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'GET new' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_import_file as @resource_import_file' do
get :new
expect(assigns(:resource_import_file)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should not assign the requested resource_import_file as @resource_import_file' do
get :new
expect(assigns(:resource_import_file)).not_to be_valid
expect(response).to be_successful
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not assign the requested resource_import_file as @resource_import_file' do
get :new
expect(assigns(:resource_import_file)).to be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested resource_import_file as @resource_import_file' do
get :new
expect(assigns(:resource_import_file)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'POST create' do
describe 'When logged in as Librarian' do
before(:each) do
@user = users(:librarian1)
sign_in @user
end
it 'should create resource_import_file' do
post :create, params: { resource_import_file: { resource_import: fixture_file_upload('resource_import_file_sample1.tsv', 'text/csv'), edit_mode: 'create', default_shelf_id: 1 } }
expect(assigns(:resource_import_file)).to be_valid
assigns(:resource_import_file).user.username.should eq @user.username
expect(response).to redirect_to resource_import_file_url(assigns(:resource_import_file))
end
it 'should not create resource_import_file without default_shelf_id' do
post :create, params: { resource_import_file: { resource_import: fixture_file_upload('resource_import_file_sample1.tsv', 'text/csv'), edit_mode: 'create' } }
expect(assigns(:resource_import_file)).not_to be_valid
assigns(:resource_import_file).user.username.should eq @user.username
expect(response).to be_successful
end
end
describe 'When logged in as User' do
before(:each) do
@user = users(:user1)
sign_in @user
end
it 'should be forbidden' do
post :create, params: { resource_import_file: { resource_import: fixture_file_upload('resource_import_file_sample1.tsv', 'text/csv') } }
assigns(:resource_import_file).should be_nil
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should be redirected to new session url' do
post :create, params: { resource_import_file: { resource_import: fixture_file_upload('resource_import_file_sample1.tsv', 'text/csv') } }
assigns(:resource_import_file).should be_nil
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'GET edit' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'assigns the requested resource_import_file as @resource_import_file' do
resource_import_file = resource_import_files(:resource_import_file_00001)
get :edit, params: { id: resource_import_file.id }
expect(assigns(:resource_import_file)).to eq(resource_import_file)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'assigns the requested resource_import_file as @resource_import_file' do
resource_import_file = resource_import_files(:resource_import_file_00001)
get :edit, params: { id: resource_import_file.id }
expect(assigns(:resource_import_file)).to eq(resource_import_file)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'assigns the requested resource_import_file as @resource_import_file' do
resource_import_file = resource_import_files(:resource_import_file_00001)
get :edit, params: { id: resource_import_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not assign the requested resource_import_file as @resource_import_file' do
resource_import_file = resource_import_files(:resource_import_file_00001)
get :edit, params: { id: resource_import_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
describe 'PUT update' do
describe 'When logged in as Administrator' do
login_fixture_admin
it 'should update resource_import_file' do
put :update, params: { id: resource_import_files(:resource_import_file_00003).id, resource_import_file: { mode: 'update' } }
expect(response).to redirect_to resource_import_file_url(assigns(:resource_import_file))
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'should update resource_import_file' do
put :update, params: { id: resource_import_files(:resource_import_file_00003).id, resource_import_file: { mode: 'update' } }
expect(response).to redirect_to resource_import_file_url(assigns(:resource_import_file))
end
end
describe 'When logged in as User' do
login_fixture_user
it 'should not update resource_import_file' do
put :update, params: { id: resource_import_files(:resource_import_file_00003).id, resource_import_file: { mode: 'update' } }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'should not update resource_import_file' do
put :update, params: { id: resource_import_files(:resource_import_file_00003).id, resource_import_file: { mode: 'update' } }
expect(response).to redirect_to new_user_session_url
end
end
end
describe 'DELETE destroy' do
before(:each) do
@resource_import_file = resource_import_files(:resource_import_file_00001)
end
describe 'When logged in as Administrator' do
login_fixture_admin
it 'destroys the requested resource_import_file' do
delete :destroy, params: { id: @resource_import_file.id }
end
it 'redirects to the resource_import_files list' do
delete :destroy, params: { id: @resource_import_file.id }
expect(response).to redirect_to(resource_import_files_url)
end
end
describe 'When logged in as Librarian' do
login_fixture_librarian
it 'destroys the requested resource_import_file' do
delete :destroy, params: { id: @resource_import_file.id }
end
it 'redirects to the resource_import_files list' do
delete :destroy, params: { id: @resource_import_file.id }
expect(response).to redirect_to(resource_import_files_url)
end
end
describe 'When logged in as User' do
login_fixture_user
it 'destroys the requested resource_import_file' do
delete :destroy, params: { id: @resource_import_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_import_file.id }
expect(response).to be_forbidden
end
end
describe 'When not logged in' do
it 'destroys the requested resource_import_file' do
delete :destroy, params: { id: @resource_import_file.id }
end
it 'should be forbidden' do
delete :destroy, params: { id: @resource_import_file.id }
expect(response).to redirect_to(new_user_session_url)
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.