enju_seed 0.4.0.rc.2 → 0.5.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/controllers/profiles_controller.rb +3 -3
  4. data/app/controllers/roles_controller.rb +1 -1
  5. data/app/models/concerns/enju_seed/enju_user.rb +4 -14
  6. data/app/models/profile.rb +10 -12
  7. data/app/models/role.rb +2 -2
  8. data/app/models/user_has_role.rb +17 -6
  9. data/app/views/roles/_form.html.erb +1 -1
  10. data/db/migrate/041_create_roles.rb +1 -1
  11. data/db/migrate/20100606065209_create_user_has_roles.rb +1 -1
  12. data/db/migrate/20130221154434_add_additional_attributes_to_user.rb +2 -1
  13. data/db/migrate/20140122054321_create_profiles.rb +1 -1
  14. data/db/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +1 -1
  15. data/db/migrate/20140811031145_add_expired_at_to_profile.rb +1 -1
  16. data/db/migrate/20141003181336_add_full_name_transcription_to_profile.rb +1 -1
  17. data/db/migrate/20141003182825_add_date_of_birth_to_profile.rb +1 -1
  18. data/lib/enju_seed/engine.rb +0 -1
  19. data/lib/enju_seed/version.rb +1 -1
  20. data/lib/tasks/enju_seed_tasks.rake +0 -19
  21. data/spec/controllers/my_accounts_controller_spec.rb +0 -12
  22. data/spec/controllers/profiles_controller_spec.rb +20 -15
  23. data/spec/dummy/app/models/user.rb +1 -1
  24. data/spec/dummy/db/migrate/059_create_libraries.rb +2 -1
  25. data/spec/dummy/db/migrate/069_create_shelves.rb +2 -1
  26. data/spec/dummy/db/migrate/077_create_user_groups.rb +2 -1
  27. data/spec/dummy/db/migrate/080_create_library_groups.rb +1 -1
  28. data/spec/dummy/db/migrate/120_create_baskets.rb +1 -1
  29. data/spec/dummy/db/migrate/124_create_bookstores.rb +2 -1
  30. data/spec/dummy/db/migrate/130_create_request_status_types.rb +1 -1
  31. data/spec/dummy/db/migrate/131_create_request_types.rb +1 -1
  32. data/spec/dummy/db/migrate/20081006090811_create_subscriptions.rb +2 -1
  33. data/spec/dummy/db/migrate/20081006093246_create_subscribes.rb +1 -1
  34. data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +1 -1
  35. data/spec/dummy/db/migrate/20100211105551_add_admin_networks_to_library_group.rb +1 -1
  36. data/spec/dummy/db/migrate/20100314190054_add_opening_hour_to_library.rb +1 -1
  37. data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +1 -1
  38. data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +1 -1
  39. data/spec/dummy/db/migrate/20120105074911_add_isil_to_library.rb +1 -1
  40. data/spec/dummy/db/migrate/20120129014038_create_budget_types.rb +1 -1
  41. data/spec/dummy/db/migrate/20120319173203_create_accepts.rb +1 -1
  42. data/spec/dummy/db/migrate/20120510140958_add_closed_to_shelf.rb +1 -1
  43. data/spec/dummy/db/migrate/20130412083556_add_latitude_and_longitude_to_library.rb +1 -1
  44. data/spec/dummy/db/migrate/20140110122216_create_user_import_files.rb +1 -1
  45. data/spec/dummy/db/migrate/20140110131010_create_user_import_results.rb +1 -1
  46. data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +6 -2
  47. data/spec/dummy/db/migrate/20140628072217_add_user_encoding_to_user_import_file.rb +1 -1
  48. data/spec/dummy/db/migrate/20140709113413_create_user_export_files.rb +1 -1
  49. data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +6 -2
  50. data/spec/dummy/db/migrate/20140720170714_add_default_library_id_to_user_import_file.rb +1 -1
  51. data/spec/dummy/db/migrate/20140720170735_add_default_user_group_id_to_user_import_file.rb +1 -1
  52. data/spec/dummy/db/migrate/20140821151023_create_colors.rb +1 -1
  53. data/spec/dummy/db/migrate/20150221063719_add_settings_to_library_group.rb +1 -1
  54. data/spec/dummy/db/migrate/20150506105356_add_error_message_to_user_import_result.rb +1 -1
  55. data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +1 -1
  56. data/spec/dummy/db/migrate/20160610093229_add_html_snippet_to_library_group.rb +1 -1
  57. data/spec/dummy/db/migrate/20160627232219_add_most_recent_to_user_import_file_transitions.rb +1 -1
  58. data/spec/dummy/db/migrate/20160627232316_add_most_recent_to_user_export_file_transitions.rb +1 -1
  59. data/spec/dummy/db/migrate/20160813191647_add_max_number_of_results_to_library_group.rb +1 -1
  60. data/spec/dummy/db/migrate/20160813191733_add_family_name_first_to_library_group.rb +1 -1
  61. data/spec/dummy/db/migrate/20160813192542_add_pub_year_facet_range_interval_to_library_group.rb +1 -1
  62. data/spec/dummy/db/migrate/20160813203039_add_user_id_to_library_group.rb +1 -1
  63. data/spec/dummy/db/migrate/20170305064014_add_csv_charset_conversion_to_library_group.rb +1 -1
  64. data/spec/dummy/db/migrate/20171014084528_add_header_logo_to_library_group.rb +1 -1
  65. data/spec/dummy/db/migrate/20171126133835_rename_login_banner_to_old_login_banner.rb +1 -1
  66. data/spec/dummy/db/migrate/20171126135238_add_foreign_key_to_library_group_id_on_library.rb +1 -1
  67. data/spec/dummy/db/migrate/20180102162311_add_header_logo_meta_to_library_group.rb +1 -1
  68. data/spec/dummy/db/migrate/20180107160726_add_constraints_to_most_recent_for_user_import_file_transitions.rb +1 -1
  69. data/spec/dummy/db/migrate/20180107160740_add_constraints_to_most_recent_for_user_export_file_transitions.rb +1 -1
  70. data/spec/dummy/db/schema.rb +101 -100
  71. data/spec/factories/profile.rb +0 -2
  72. data/spec/factories/user.rb +25 -31
  73. data/spec/fixtures/profiles.yml +7 -14
  74. data/spec/fixtures/roles.yml +1 -1
  75. data/spec/fixtures/user_has_roles.yml +5 -5
  76. data/spec/fixtures/users.yml +7 -0
  77. data/spec/models/profile_spec.rb +7 -7
  78. data/spec/models/role_spec.rb +1 -1
  79. data/spec/models/user_has_role_spec.rb +5 -5
  80. data/spec/models/user_spec.rb +6 -1
  81. metadata +11 -57
  82. data/spec/dummy/app/assets/config/manifest.js +0 -3
  83. data/spec/dummy/db/migrate/20191216131755_add_email_to_library_group.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77bf05eb53d054c79b891f6970a7e80277be554a4f4ce49588cc7836a2506f8a
4
- data.tar.gz: 2b925b9a23968bd6a08ba40214e09523902e470da8ccc3e7ad5c43e3b5843134
3
+ metadata.gz: 6a25e3af94b4a4a12b8c78cb2a39f93d3b4d2d3994c716a062e2ac270c31786a
4
+ data.tar.gz: 2009ab77aa47750523a85de373b75db1409dfa3c73e89cef9fd31eb6d2b90bf5
5
5
  SHA512:
6
- metadata.gz: fc7a73ccff4bf3621c210082b8856b633655e794f5c6efd04153d62e28cf88ae6522d0e428e1c8d8f6a626c5f9e5613dbf3c6e3e0719470201bd0e2e541bb4ad
7
- data.tar.gz: d9d5d19fa8b23b459b14964e3bc68de2094931faa5b41bdcffba4bd835e49f64f3295d7374f8320e2ede400f78a29a2303f026e6b8929b20971a93ae53c0ae26
6
+ metadata.gz: fc80f7da0b4c02c70d5d223922c7a700a9aceb2a44141851d4c60a30eaf3dc48ae209eae26e13f517109dcb0d0f738841beb8e1dfd7283f626baf93958ee533d
7
+ data.tar.gz: 98489cd55753b5d2e4d5e02b0ed28cdb611db7028b70f1eadfb039e99c3cca9820d9b4ec3268e5a614839fe6d37c05e6cf8c2c7e5c9f5ca6b950bffb8c84afcc
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # EnjuSeed
2
- [![CircleCI](https://circleci.com/gh/next-l/enju_seed/tree/2.x.svg?style=svg)](https://circleci.com/gh/next-l/enju_seed/tree/2.x)
3
- [![Coverage Status](https://coveralls.io/repos/github/next-l/enju_seed/badge.svg?branch=2.x)](https://coveralls.io/github/next-l/enju_seed?branch=2.x)
2
+ [![CircleCI](https://circleci.com/gh/next-l/enju_seed/tree/master.svg?style=svg)](https://circleci.com/gh/next-l/enju_seed/tree/master)
3
+ [![Coverage Status](https://coveralls.io/repos/github/next-l/enju_seed/badge.svg?branch=master)](https://coveralls.io/github/next-l/enju_seed?branch=master)
4
4
 
5
5
  This project rocks and uses MIT-LICENSE.
6
6
 
@@ -8,7 +8,7 @@ class ProfilesController < ApplicationController
8
8
  # GET /profiles.json
9
9
  def index
10
10
  if params[:username].present?
11
- profile = User.find_by(username: params[:username]).try(:profile)
11
+ profile = User.where(username: params[:username]).first.try(:profile)
12
12
  if profile
13
13
  redirect_to profile
14
14
  return
@@ -116,7 +116,7 @@ class ProfilesController < ApplicationController
116
116
  respond_to do |format|
117
117
  if @profile.save
118
118
  if @profile.user
119
- @profile.user.role = Role.find_by(name: 'User')
119
+ @profile.user.role = Role.where(name: 'User').first
120
120
  flash[:temporary_password] = password
121
121
  end
122
122
  format.html { redirect_to @profile, notice: t('controller.successfully_created', model: t('activerecord.models.profile')) }
@@ -132,7 +132,7 @@ class ProfilesController < ApplicationController
132
132
  # PUT /profiles/1
133
133
  # PUT /profiles/1.json
134
134
  def update
135
- @profile.update(profile_update_params)
135
+ @profile.update_attributes(profile_update_params)
136
136
  if @profile.user
137
137
  if @profile.user.auto_generated_password == "1"
138
138
  password = @profile.user.set_auto_generated_password
@@ -35,7 +35,7 @@ class RolesController < ApplicationController
35
35
  end
36
36
 
37
37
  respond_to do |format|
38
- if @role.update(role_params)
38
+ if @role.update_attributes(role_params)
39
39
  format.html { redirect_to @role, notice: t('controller.successfully_updated', model: t('activerecord.models.role')) }
40
40
  format.json { head :no_content }
41
41
  else
@@ -6,7 +6,7 @@ module EnjuSeed
6
6
  scope :administrators, -> { joins(:role).where('roles.name = ?', 'Administrator') }
7
7
  scope :librarians, -> { joins(:role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
8
8
  scope :suspended, -> { where('locked_at IS NOT NULL') }
9
- has_one :profile, dependent: :nullify
9
+ belongs_to :profile
10
10
  if defined?(EnjuBiblio)
11
11
  has_many :import_requests
12
12
  has_many :picture_files, as: :picture_attachable, dependent: :destroy
@@ -19,6 +19,7 @@ module EnjuSeed
19
19
  with: /\A[0-9A-Za-z][0-9A-Za-z_\-]*[0-9A-Za-z]\z/
20
20
  }
21
21
  validates :email, format: Devise::email_regexp, allow_blank: true, uniqueness: true
22
+ validates :profile_id, uniqueness: true
22
23
  validates_date :expired_at, allow_blank: true
23
24
 
24
25
  with_options if: :password_required? do |v|
@@ -29,7 +30,6 @@ module EnjuSeed
29
30
  end
30
31
 
31
32
  before_validation :set_lock_information
32
- before_destroy :check_role_before_destroy
33
33
  before_save :check_expiration
34
34
  after_create :set_confirmation
35
35
 
@@ -172,16 +172,6 @@ module EnjuSeed
172
172
  end
173
173
  end
174
174
 
175
- # ユーザの削除前に、管理者ユーザが不在にならないかどうかをチェックします。
176
- # @return [Object]
177
- def check_role_before_destroy
178
- if has_role?('Administrator')
179
- if Role.find_by(name: 'Administrator').users.count == 1
180
- raise username + 'This is the last administrator in this system.'
181
- end
182
- end
183
- end
184
-
185
175
  # ユーザに自動生成されたパスワードを設定します。
186
176
  # @return [String]
187
177
  def set_auto_generated_password
@@ -209,7 +199,7 @@ module EnjuSeed
209
199
  # @return [Boolean]
210
200
  def last_librarian?
211
201
  if has_role?('Librarian')
212
- role = Role.find_by(name: 'Librarian')
202
+ role = Role.where(name: 'Librarian').first
213
203
  return true if role.users.count == 1
214
204
  false
215
205
  end
@@ -244,7 +234,7 @@ module EnjuSeed
244
234
 
245
235
  # 最後の管理者を削除しようとした
246
236
  if has_role?('Administrator')
247
- if Role.find_by(name: 'Administrator').users.count == 1
237
+ if Role.where(name: 'Administrator').first.users.count == 1
248
238
  errors[:base] << I18n.t('user.last_administrator')
249
239
  end
250
240
  end
@@ -1,7 +1,7 @@
1
- class Profile < ApplicationRecord
1
+ class Profile < ActiveRecord::Base
2
2
  scope :administrators, -> { joins(user: :role).where('roles.name = ?', 'Administrator') }
3
3
  scope :librarians, -> { joins(user: :role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
4
- belongs_to :user, dependent: :destroy, optional: true
4
+ has_one :user, dependent: :destroy
5
5
  belongs_to :library
6
6
  belongs_to :user_group
7
7
  belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id' #, validate: true
@@ -10,10 +10,8 @@ class Profile < ApplicationRecord
10
10
  accepts_nested_attributes_for :identities, allow_destroy: true, reject_if: :all_blank
11
11
 
12
12
  validates_associated :user_group, :library
13
- validates :user, uniqueness: true, associated: true, allow_blank: true
14
13
  validates_presence_of :user_group, :library, :locale #, :user_number
15
14
  validates :user_number, uniqueness: true, format: { with: /\A[0-9A-Za-z_]+\z/ }, allow_blank: true
16
- validates :user_id, uniqueness: true, allow_blank: true
17
15
  validates :birth_date, format: { with: /\A\d{4}-\d{1,2}-\d{1,2}\z/ }, allow_blank: true
18
16
 
19
17
  strip_attributes only: :user_number
@@ -50,7 +48,7 @@ class Profile < ApplicationRecord
50
48
  # 既定のユーザ権限を設定します。
51
49
  # @return [void]
52
50
  def set_role_and_agent
53
- self.required_role = Role.find_by(name: 'Librarian') unless required_role
51
+ self.required_role = Role.where(name: 'Librarian').first unless required_role
54
52
  self.locale = I18n.default_locale.to_s unless locale
55
53
  end
56
54
 
@@ -77,18 +75,18 @@ end
77
75
  #
78
76
  # Table name: profiles
79
77
  #
80
- # id :bigint not null, primary key
81
- # user_id :bigint
82
- # user_group_id :bigint
83
- # library_id :bigint
78
+ # id :integer not null, primary key
79
+ # user_id :integer
80
+ # user_group_id :integer
81
+ # library_id :integer
84
82
  # locale :string
85
83
  # user_number :string
86
84
  # full_name :text
87
85
  # note :text
88
86
  # keyword_list :text
89
- # required_role_id :bigint
90
- # created_at :datetime not null
91
- # updated_at :datetime not null
87
+ # required_role_id :integer
88
+ # created_at :datetime
89
+ # updated_at :datetime
92
90
  # checkout_icalendar_token :string
93
91
  # save_checkout_history :boolean default(FALSE), not null
94
92
  # expired_at :datetime
data/app/models/role.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Role < ApplicationRecord
1
+ class Role < ActiveRecord::Base
2
2
  include MasterModel
3
3
  validates :name, presence: true, format: { with: /\A[A-Za-z][a-z_,]*[a-z]\z/ }
4
4
  has_many :user_has_roles
@@ -22,7 +22,7 @@ end
22
22
  #
23
23
  # Table name: roles
24
24
  #
25
- # id :bigint not null, primary key
25
+ # id :integer not null, primary key
26
26
  # name :string not null
27
27
  # display_name :string
28
28
  # note :text
@@ -1,16 +1,27 @@
1
- class UserHasRole < ApplicationRecord
1
+ class UserHasRole < ActiveRecord::Base
2
2
  belongs_to :user
3
3
  belongs_to :role
4
4
  accepts_nested_attributes_for :role
5
+
6
+ before_destroy :check_role_before_destroy
7
+
8
+ # ユーザの削除前に、管理者ユーザが不在にならないかどうかをチェックします。
9
+ # @return [Object]
10
+ def check_role_before_destroy
11
+ return unless user.has_role?('Administrator')
12
+ if UserHasRole.where(role: Role.find_by(name: 'Administrator')).count == 1
13
+ raise user.username + ': This is the last administrator in this system.'
14
+ end
15
+ end
5
16
  end
6
17
 
7
18
  # == Schema Information
8
19
  #
9
20
  # Table name: user_has_roles
10
21
  #
11
- # id :bigint not null, primary key
12
- # user_id :bigint not null
13
- # role_id :bigint not null
14
- # created_at :datetime not null
15
- # updated_at :datetime not null
22
+ # id :integer not null, primary key
23
+ # user_id :integer not null
24
+ # role_id :integer not null
25
+ # created_at :datetime
26
+ # updated_at :datetime
16
27
  #
@@ -3,7 +3,7 @@
3
3
 
4
4
  <div class="field">
5
5
  <%= f.label :name %><br />
6
- <%= f.text_field :name, required: true %>
6
+ <%= f.text_field :name %>
7
7
  </div>
8
8
  <div class="field">
9
9
  <%= f.label :display_name %><br />
@@ -1,4 +1,4 @@
1
- class CreateRoles < ActiveRecord::Migration[5.2]
1
+ class CreateRoles < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table "roles" do |t|
4
4
  t.column :name, :string, null: false
@@ -1,4 +1,4 @@
1
- class CreateUserHasRoles < ActiveRecord::Migration[5.2]
1
+ class CreateUserHasRoles < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :user_has_roles do |t|
4
4
  t.references :user, index: true, foreign_key: true, null: false
@@ -1,6 +1,7 @@
1
- class AddAdditionalAttributesToUser < ActiveRecord::Migration[5.2]
1
+ class AddAdditionalAttributesToUser < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :users, :username, :string
4
+ add_column :users, :deleted_at, :datetime
4
5
  add_column :users, :expired_at, :datetime
5
6
 
6
7
  add_column :users, :failed_attempts, :integer, default: 0
@@ -1,4 +1,4 @@
1
- class CreateProfiles < ActiveRecord::Migration[5.2]
1
+ class CreateProfiles < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :profiles do |t|
4
4
  t.references :user, index: true, foreign_key: true
@@ -1,4 +1,4 @@
1
- class DropEmailUniqueConstraintEnjuLeafRc10 < ActiveRecord::Migration[5.2]
1
+ class DropEmailUniqueConstraintEnjuLeafRc10 < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  remove_index :users, :email
4
4
  add_index :users, :email
@@ -1,4 +1,4 @@
1
- class AddExpiredAtToProfile < ActiveRecord::Migration[5.2]
1
+ class AddExpiredAtToProfile < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :profiles, :expired_at, :datetime
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddFullNameTranscriptionToProfile < ActiveRecord::Migration[5.2]
1
+ class AddFullNameTranscriptionToProfile < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :profiles, :full_name_transcription, :text
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddDateOfBirthToProfile < ActiveRecord::Migration[5.2]
1
+ class AddDateOfBirthToProfile < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :profiles, :date_of_birth, :datetime
4
4
  end
@@ -13,7 +13,6 @@ require 'rails_autolink'
13
13
  require 'browser'
14
14
  require 'simple_form'
15
15
  require 'validates_timeliness'
16
- require 'paperclip'
17
16
  require 'json_translate'
18
17
 
19
18
  module EnjuSeed
@@ -1,3 +1,3 @@
1
1
  module EnjuSeed
2
- VERSION = "0.4.0.rc.2".freeze
2
+ VERSION = "0.5.0.beta.1"
3
3
  end
@@ -5,23 +5,4 @@ namespace :enju_seed do
5
5
  ActiveRecord::FixtureSet.create_fixtures('db/fixtures/enju_seed', File.basename(file, '.*'))
6
6
  end
7
7
  end
8
-
9
- desc "upgrade enju_seed to enju_leaf 2.0"
10
- task upgrade: :environment do
11
- sql = 'UPDATE users SET profile_id = profiles.id FROM profiles WHERE profiles.user_id = users.id;'
12
- ActiveRecord::Base.connection.execute(sql)
13
-
14
- class_names = [
15
- Role
16
- ]
17
- class_names.each do |klass|
18
- klass.find_each do |record|
19
- I18n.available_locales.each do |locale|
20
- next unless record.respond_to?("display_name_#{locale}")
21
- record.update("display_name_#{locale}": YAML.safe_load(record[:display_name])[locale.to_s])
22
- end
23
- end
24
- end
25
- puts 'enju_seed: The upgrade completed successfully.'
26
- end
27
8
  end
@@ -27,9 +27,7 @@ describe MyAccountsController do
27
27
  describe "GET edit" do
28
28
  describe "When logged in as Administrator" do
29
29
  before(:each) do
30
- profile = FactoryBot.create(:profile)
31
30
  @user = FactoryBot.create(:admin)
32
- @user.profile = profile
33
31
  sign_in @user
34
32
  end
35
33
 
@@ -41,9 +39,7 @@ describe MyAccountsController do
41
39
 
42
40
  describe "When logged in as Librarian" do
43
41
  before(:each) do
44
- profile = FactoryBot.create(:profile)
45
42
  @user = FactoryBot.create(:librarian)
46
- @user.profile = profile
47
43
  sign_in @user
48
44
  end
49
45
 
@@ -55,9 +51,7 @@ describe MyAccountsController do
55
51
 
56
52
  describe "When logged in as User" do
57
53
  before(:each) do
58
- profile = FactoryBot.create(:profile)
59
54
  @user = FactoryBot.create(:user)
60
- @user.profile = profile
61
55
  sign_in @user
62
56
  end
63
57
 
@@ -86,9 +80,7 @@ describe MyAccountsController do
86
80
 
87
81
  describe "When logged in as Administrator" do
88
82
  before(:each) do
89
- profile = FactoryBot.create(:profile)
90
83
  @user = FactoryBot.create(:admin, password: 'password', password_confirmation: 'password')
91
- @user.profile = profile
92
84
  sign_in @user
93
85
  end
94
86
 
@@ -134,9 +126,7 @@ describe MyAccountsController do
134
126
 
135
127
  describe "When logged in as Librarian" do
136
128
  before(:each) do
137
- profile = FactoryBot.create(:profile)
138
129
  @user = FactoryBot.create(:librarian, password: 'password', password_confirmation: 'password')
139
- @user.profile = profile
140
130
  sign_in @user
141
131
  end
142
132
 
@@ -177,9 +167,7 @@ describe MyAccountsController do
177
167
 
178
168
  describe "When logged in as User" do
179
169
  before(:each) do
180
- profile = FactoryBot.create(:profile)
181
170
  @user = FactoryBot.create(:user, password: 'password', password_confirmation: 'password')
182
- @user.profile = profile
183
171
  sign_in @user
184
172
  end
185
173
 
@@ -71,10 +71,10 @@ describe ProfilesController do
71
71
  assigns(:profile).should eq(profiles(:admin))
72
72
  end
73
73
  it "assigns the another requested user as @profile" do
74
- admin_profile = FactoryBot.create :admin_profile
75
- get :show, params: { id: admin_profile.id }
74
+ admin = FactoryBot.create(:admin).profile
75
+ get :show, params: { id: admin.id }
76
76
  expect(response).not_to be_forbidden
77
- expect(assigns(:profile)).to eq admin_profile
77
+ expect(assigns(:profile)).to eq admin
78
78
  end
79
79
  end
80
80
 
@@ -85,16 +85,20 @@ describe ProfilesController do
85
85
  get :show, params: { id: profiles(:librarian1).id }
86
86
  assigns(:profile).should eq(profiles(:librarian1))
87
87
  end
88
+
88
89
  it "should not assign the requested user as @admin" do
89
- admin = FactoryBot.create(:admin_profile)
90
- get :show, params: { id: admin.id }
90
+ admin = FactoryBot.create(:admin)
91
+ admin.profile.update(required_role: Role.find_by(name: 'Administrator'))
92
+ get :show, params: { id: admin.profile.id }
91
93
  response.should be_forbidden
92
94
  end
95
+
93
96
  it "should assign the requested user as @librarian" do
94
- librarian = FactoryBot.create(:librarian_profile)
95
- get :show, params: { id: librarian.id }
97
+ librarian = FactoryBot.create(:librarian)
98
+ librarian.profile.update(required_role: Role.find_by(name: 'Librarian'))
99
+ get :show, params: { id: librarian.profile.id }
96
100
  response.should_not be_forbidden
97
- assigns(:profile).should eq librarian
101
+ assigns(:profile).should eq librarian.profile
98
102
  end
99
103
  end
100
104
 
@@ -185,23 +189,24 @@ describe ProfilesController do
185
189
  assigns(:profile).should eq(profile)
186
190
  end
187
191
  it "should not get edit page for admin required user" do
188
- admin = FactoryBot.create(:admin_profile)
192
+ admin = FactoryBot.create(:admin).profile
189
193
  get :edit, params: { id: admin.id }
190
194
  response.should be_forbidden
191
195
  # assigns(:profile).should_not eq(admin)
192
196
  end
193
197
  it "should get edit page for other librarian user" do
194
- librarian = FactoryBot.create(:librarian_profile)
198
+ librarian = FactoryBot.create(:librarian).profile
195
199
  get :edit, params: { id: librarian.id }
196
200
  response.should_not be_forbidden
197
201
  assigns(:profile).should eq librarian
198
202
  end
199
203
 
200
204
  it "should get edit page for other librarian user" do
201
- admin = FactoryBot.create(:admin_profile, required_role_id: Role.where(name: 'Librarian').first.id)
202
- get :edit, params: { id: admin.id }
205
+ admin = FactoryBot.create(:admin)
206
+ admin.profile.update(required_role: Role.find_by(name: 'Librarian'))
207
+ get :edit, params: { id: admin.profile.id }
203
208
  response.should be_forbidden
204
- assigns(:profile).should eq admin
209
+ assigns(:profile).should eq admin.profile
205
210
  end
206
211
  end
207
212
 
@@ -551,8 +556,8 @@ describe ProfilesController do
551
556
  end
552
557
 
553
558
  it "should not be able to delete other librarian user" do
554
- librarian = FactoryBot.create(:librarian_profile)
555
- delete :destroy, params: { id: librarian.id }
559
+ librarian = FactoryBot.create(:librarian)
560
+ delete :destroy, params: { id: librarian.profile.id }
556
561
  response.should be_forbidden
557
562
  end
558
563
  end