blacklight-spotlight 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spotlight/reindex_monitor.js +109 -0
  3. data/app/assets/stylesheets/spotlight/_blacklight_configuration.scss +9 -8
  4. data/app/assets/stylesheets/spotlight/_bootstrap_overrides.scss +15 -7
  5. data/app/assets/stylesheets/spotlight/_header.scss +67 -90
  6. data/app/assets/stylesheets/spotlight/_variables.scss +4 -0
  7. data/app/controllers/spotlight/attachments_controller.rb +2 -5
  8. data/app/controllers/spotlight/browse_controller.rb +15 -3
  9. data/app/controllers/spotlight/resources_controller.rb +4 -0
  10. data/app/controllers/spotlight/roles_controller.rb +1 -1
  11. data/app/controllers/spotlight/sites_controller.rb +50 -0
  12. data/app/helpers/spotlight/application_helper.rb +2 -1
  13. data/app/helpers/spotlight/navbar_helper.rb +1 -1
  14. data/app/jobs/spotlight/reindex_job.rb +17 -8
  15. data/app/models/concerns/spotlight/user.rb +8 -4
  16. data/app/models/spotlight/ability.rb +5 -4
  17. data/app/models/spotlight/exhibit.rb +15 -1
  18. data/app/models/spotlight/reindex_progress.rb +107 -0
  19. data/app/models/spotlight/resource.rb +4 -0
  20. data/app/models/spotlight/role.rb +2 -2
  21. data/app/models/spotlight/site.rb +16 -0
  22. data/app/views/devise/mailer/invitation_instructions.html.erb +1 -1
  23. data/app/views/layouts/spotlight/spotlight.html.erb +1 -1
  24. data/app/views/shared/_breadcrumbs.html.erb +1 -1
  25. data/app/views/shared/_exhibit_navbar.html.erb +6 -7
  26. data/app/views/shared/_masthead.html.erb +32 -0
  27. data/app/views/shared/_site_sidebar.html.erb +16 -0
  28. data/app/views/spotlight/about_pages/_sidebar.html.erb +4 -2
  29. data/app/views/spotlight/browse/_search_title.html.erb +1 -1
  30. data/app/views/spotlight/browse/index.html.erb +6 -4
  31. data/app/views/spotlight/browse/show.html.erb +6 -8
  32. data/app/views/spotlight/catalog/_admin_header.html.erb +15 -12
  33. data/app/views/spotlight/catalog/_reindex_progress_panel.html.erb +21 -0
  34. data/app/views/spotlight/exhibits/index.html.erb +4 -2
  35. data/app/views/spotlight/featured_images/_upload_form.html.erb +17 -0
  36. data/app/views/spotlight/home_pages/_empty.html.erb +1 -1
  37. data/app/views/spotlight/metadata_configurations/_metadata_field.html.erb +2 -2
  38. data/app/views/spotlight/metadata_configurations/edit.html.erb +3 -3
  39. data/app/views/spotlight/shared/_configuration_sidebar.html.erb +2 -2
  40. data/app/views/spotlight/shared/_curation_sidebar.html.erb +1 -1
  41. data/app/views/spotlight/sites/_exhibit.html.erb +18 -0
  42. data/app/views/spotlight/sites/edit.html.erb +40 -0
  43. data/app/views/spotlight/sites/edit_exhibits.html.erb +32 -0
  44. data/config/locales/spotlight.en.yml +30 -2
  45. data/config/routes.rb +5 -0
  46. data/db/migrate/20151210073829_create_spotlight_site.rb +9 -0
  47. data/db/migrate/20151211131415_add_site_to_spotlight_exhibits.rb +23 -0
  48. data/db/migrate/20151215141516_change_roles_to_support_polymorphic_associations.rb +40 -0
  49. data/db/migrate/20151215192845_add_index_status_to_resources.rb +6 -0
  50. data/lib/spotlight/controller.rb +18 -7
  51. data/lib/spotlight/engine.rb +37 -35
  52. data/lib/spotlight/version.rb +1 -1
  53. data/spec/controllers/spotlight/contacts_controller_spec.rb +2 -2
  54. data/spec/controllers/spotlight/home_pages_controller_spec.rb +2 -4
  55. data/spec/controllers/spotlight/resources_controller_spec.rb +14 -0
  56. data/spec/controllers/spotlight/roles_controller_spec.rb +1 -1
  57. data/spec/controllers/spotlight/sites_controller_spec.rb +48 -0
  58. data/spec/controllers/spotlight/versions_controller_spec.rb +1 -2
  59. data/spec/factories/roles.rb +1 -1
  60. data/spec/factories/users.rb +3 -3
  61. data/spec/features/add_contacts_spec.rb +2 -2
  62. data/spec/features/browse_category_spec.rb +65 -0
  63. data/spec/features/edit_contact_spec.rb +2 -2
  64. data/spec/features/exhibit_masthead_spec.rb +100 -0
  65. data/spec/features/javascript/reindex_monitor_spec.rb +22 -0
  66. data/spec/features/site_masthead_spec.rb +17 -52
  67. data/spec/helpers/spotlight/application_helper_spec.rb +16 -0
  68. data/spec/lib/spotlight/controller_spec.rb +34 -8
  69. data/spec/models/spotlight/ability_spec.rb +3 -4
  70. data/spec/models/spotlight/exhibit_spec.rb +23 -0
  71. data/spec/models/spotlight/reindex_progress_spec.rb +104 -0
  72. data/spec/models/spotlight/site_spec.rb +9 -0
  73. data/spec/views/shared/_exhibit_navbar.html.erb_spec.rb +3 -9
  74. data/spec/views/shared/_masthead.html.erb_spec.rb +83 -0
  75. data/spec/views/spotlight/browse/show.html.erb_spec.rb +2 -2
  76. data/spec/views/spotlight/catalog/admin.html.erb_spec.rb +1 -0
  77. data/spec/views/spotlight/roles/index.html.erb_spec.rb +1 -1
  78. data/spec/views/spotlight/sites/edit_exhibits.html.erb_spec.rb +29 -0
  79. metadata +33 -14
  80. data/app/views/shared/_exhibit_masthead.html.erb +0 -20
  81. data/app/views/shared/_exhibit_masthead_and_navbar.html.erb +0 -9
  82. data/app/views/shared/_home_sidebar.html.erb +0 -1
  83. data/app/views/spotlight/attachments/_form.html.erb +0 -29
  84. data/app/views/spotlight/attachments/edit.html.erb +0 -6
  85. data/app/views/spotlight/attachments/index.html.erb +0 -31
  86. data/app/views/spotlight/attachments/new.html.erb +0 -5
  87. data/app/views/spotlight/attachments/show.html.erb +0 -19
  88. data/spec/views/shared/_exhibit_masthead.html.erb_spec.rb +0 -70
  89. data/spec/views/shared/_exhibit_masthead_and_navbar.html.erb_spec.rb +0 -36
data/config/routes.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  Spotlight::Engine.routes.draw do
2
2
  devise_for :contact_email, class_name: 'Spotlight::ContactEmail', only: [:confirmations]
3
3
 
4
+ get '/edit' => 'sites#edit', as: :edit_site
5
+ get '/exhibits/edit' => 'sites#edit_exhibits', as: :edit_site_exhibits
6
+ patch '/edit' => 'sites#update', as: :site
7
+
4
8
  resources :exhibits, path: '/', except: [:show] do
5
9
  member do
6
10
  get 'exhibit', to: 'exhibits#show', as: 'get'
@@ -45,6 +49,7 @@ Spotlight::Engine.routes.draw do
45
49
 
46
50
  resources :resources do
47
51
  collection do
52
+ get :monitor
48
53
  post :reindex_all
49
54
  end
50
55
  end
@@ -0,0 +1,9 @@
1
+ class CreateSpotlightSite < ActiveRecord::Migration
2
+ def change
3
+ create_table :spotlight_sites do |t|
4
+ t.string :title
5
+ t.string :subtitle
6
+ t.references :masthead
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ class AddSiteToSpotlightExhibits < ActiveRecord::Migration
2
+ def up
3
+ add_column :spotlight_exhibits, :site_id, :integer
4
+ add_index :spotlight_exhibits, :site_id
5
+
6
+ add_default_site_to_exhibits
7
+ end
8
+
9
+ def down
10
+ remove_column :spotlight_exhibits, :site_id, :integer
11
+ end
12
+
13
+ private
14
+
15
+ def add_default_site_to_exhibits
16
+ Spotlight::Site.reset_column_information
17
+ Spotlight::Exhibit.reset_column_information
18
+
19
+ Spotlight::Exhibit.find_each do |e|
20
+ e.site = Spotlight::Site.instance
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ class ChangeRolesToSupportPolymorphicAssociations < ActiveRecord::Migration
2
+ def up
3
+ add_column :spotlight_roles, :resource_id, :integer
4
+ add_column :spotlight_roles, :resource_type, :string
5
+
6
+ migrate_role_data_to_polymorphic_resource
7
+
8
+ remove_column :spotlight_roles, :exhibit_id
9
+
10
+ add_index :spotlight_roles, [:resource_type, :resource_id, :user_id], unique: true, name: 'index_spotlight_roles_on_resource_and_user_id'
11
+ remove_index :spotlight_roles, [:exhibit_id, :user_id]
12
+ end
13
+
14
+ def down
15
+ add_column :spotlight_roles, :exhibit_id, :integer
16
+ add_index(:spotlight_roles, [:exhibit_id])
17
+
18
+ Spotlight::Role.reset_column_information
19
+
20
+ Spotlight::Role.find_each do |e|
21
+ e.update(exhibit_id: e.resource_id) if e.exhibit_id.nil? && e.resource_type == 'Spotlight::Exhibit'
22
+ end
23
+
24
+ remove_column :spotlight_roles, :resource_id
25
+ remove_column :spotlight_roles, :resource_type
26
+
27
+ add_index :spotlight_roles, [:exhibit_id, :user_id], unique: true
28
+ remove_index :spotlight_roles, name: 'index_spotlight_roles_on_resource_and_user_id'
29
+ end
30
+
31
+ private
32
+
33
+ def migrate_role_data_to_polymorphic_resource
34
+ Spotlight::Role.reset_column_information
35
+
36
+ Spotlight::Role.find_each do |e|
37
+ e.update(resource_id: e.exhibit_id, resource_type: 'Spotlight::Exhibit') unless e.resource_id
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ class AddIndexStatusToResources < ActiveRecord::Migration
2
+ def change
3
+ add_column :spotlight_resources, :index_status, :integer
4
+ add_index :spotlight_resources, :index_status
5
+ end
6
+ end
@@ -7,7 +7,11 @@ module Spotlight
7
7
  include Spotlight::Config
8
8
 
9
9
  included do
10
- helper_method :current_exhibit, :current_masthead, :exhibit_masthead?
10
+ helper_method :current_site, :current_exhibit, :current_masthead, :exhibit_masthead?, :resource_masthead?
11
+ end
12
+
13
+ def current_site
14
+ @current_site ||= Spotlight::Site.instance
11
15
  end
12
16
 
13
17
  def current_exhibit
@@ -15,21 +19,28 @@ module Spotlight
15
19
  end
16
20
 
17
21
  def current_masthead
18
- @masthead ||= begin
19
- current_exhibit.masthead if current_exhibit && current_exhibit.masthead && current_exhibit.masthead.display?
20
- end
22
+ @masthead ||= if resource_masthead?
23
+ # TODO: is there a way to get this generically, instead of requiring controllers
24
+ # to override #current_masthead or set it explicitly?. In the meantime, `nil` is
25
+ # hopefully less confusing than a wrong value.
26
+ nil
27
+ elsif current_exhibit
28
+ current_exhibit.masthead if exhibit_masthead?
29
+ else
30
+ current_site.masthead if current_site.masthead && current_site.masthead.display?
31
+ end
21
32
  end
22
33
 
23
34
  def current_masthead=(masthead)
24
35
  @masthead = masthead
25
36
  end
26
37
 
27
- def default_masthead?
28
- current_exhibit.nil? || current_masthead.nil?
38
+ def resource_masthead?
39
+ false
29
40
  end
30
41
 
31
42
  def exhibit_masthead?
32
- default_masthead? || current_masthead == current_exhibit.masthead
43
+ current_exhibit && current_exhibit.masthead && current_exhibit.masthead.display?
33
44
  end
34
45
 
35
46
  # overwrites Blacklight::Controller#blacklight_config
@@ -59,55 +59,57 @@ module Spotlight
59
59
  Spotlight::Engine.config.default_blacklight_config || catalog_controller.blacklight_config
60
60
  end
61
61
 
62
- Spotlight::Engine.config.user_class = '::User'
62
+ config.user_class = '::User'
63
63
 
64
- Spotlight::Engine.config.catalog_controller_class = '::CatalogController'
65
- Spotlight::Engine.config.default_blacklight_config = nil
64
+ config.catalog_controller_class = '::CatalogController'
65
+ config.default_blacklight_config = nil
66
66
 
67
- Spotlight::Engine.config.exhibit_main_navigation = [:curated_features, :browse, :about]
67
+ config.exhibit_main_navigation = [:curated_features, :browse, :about]
68
68
 
69
- Spotlight::Engine.config.resource_providers = []
70
- Spotlight::Engine.config.new_resource_partials = [] # e.g. "spotlight/resources/bookmarklet"
71
- Spotlight::Engine.config.uploaded_resource_partials = ['spotlight/resources/upload/single_item_form', 'spotlight/resources/upload/multi_item_form']
72
- Spotlight::Engine.config.solr_batch_size = 20
69
+ config.resource_providers = []
70
+ config.new_resource_partials = [] # e.g. "spotlight/resources/bookmarklet"
71
+ config.uploaded_resource_partials = ['spotlight/resources/upload/single_item_form', 'spotlight/resources/upload/multi_item_form']
72
+ config.solr_batch_size = 20
73
+
74
+ Spotlight::Engine.config.reindex_progress_window = 10
73
75
 
74
76
  # Filter resources by exhibit by default
75
- Spotlight::Engine.config.filter_resources_by_exhibit = true
77
+ config.filter_resources_by_exhibit = true
76
78
  # The allowed file extensions for uploading non-repository items.
77
- Spotlight::Engine.config.allowed_upload_extensions = %w(jpg jpeg png)
79
+ config.allowed_upload_extensions = %w(jpg jpeg png)
78
80
 
79
81
  # Suffixes for exhibit-specific solr fields
80
- Spotlight::Engine.config.solr_fields = OpenStruct.new
81
- Spotlight::Engine.config.solr_fields.prefix = ''.freeze
82
- Spotlight::Engine.config.solr_fields.boolean_suffix = '_bsi'.freeze
83
- Spotlight::Engine.config.solr_fields.string_suffix = '_ssim'.freeze
84
- Spotlight::Engine.config.solr_fields.text_suffix = '_tesim'.freeze
82
+ config.solr_fields = OpenStruct.new
83
+ config.solr_fields.prefix = ''.freeze
84
+ config.solr_fields.boolean_suffix = '_bsi'.freeze
85
+ config.solr_fields.string_suffix = '_ssim'.freeze
86
+ config.solr_fields.text_suffix = '_tesim'.freeze
85
87
 
86
88
  # A lambda expression that filters the solr index per exhibit
87
89
  config.exhibit_filter = lambda do |exhibit|
88
90
  { :"#{config.solr_fields.prefix}spotlight_exhibit_slug_#{exhibit.slug}#{config.solr_fields.boolean_suffix}" => true }
89
91
  end
90
92
 
91
- Spotlight::Engine.config.resource_global_id_field = :"#{config.solr_fields.prefix}spotlight_resource_id#{config.solr_fields.string_suffix}"
93
+ config.resource_global_id_field = :"#{config.solr_fields.prefix}spotlight_resource_id#{config.solr_fields.string_suffix}"
92
94
 
93
95
  # The solr field that original (largest) images will be stored.
94
- Spotlight::Engine.config.full_image_field = :full_image_url_ssm
95
- Spotlight::Engine.config.thumbnail_field = :thumbnail_url_ssm
96
- Spotlight::Engine.config.square_image_field = :thumbnail_square_url_ssm
96
+ config.full_image_field = :full_image_url_ssm
97
+ config.thumbnail_field = :thumbnail_url_ssm
98
+ config.square_image_field = :thumbnail_square_url_ssm
97
99
 
98
100
  # Defaults to the blacklight_config.index.title_field:
99
- Spotlight::Engine.config.upload_title_field = nil # OpenStruct.new(...)
101
+ config.upload_title_field = nil # OpenStruct.new(...)
100
102
 
101
- Spotlight::Engine.config.upload_fields = [
103
+ config.upload_fields = [
102
104
  OpenStruct.new(field_name: :spotlight_upload_description_tesim, label: 'Description', form_field_type: :text_area),
103
105
  OpenStruct.new(field_name: :spotlight_upload_attribution_tesim, label: 'Attribution'),
104
106
  OpenStruct.new(field_name: :spotlight_upload_date_tesim, label: 'Date')
105
107
  ]
106
108
 
107
109
  # Configure the CarrierWave file storage mechanism
108
- Spotlight::Engine.config.uploader_storage = :file
109
- Spotlight::Engine.config.featured_image_thumb_size = [400, 300]
110
- Spotlight::Engine.config.featured_image_square_size = [400, 400]
110
+ config.uploader_storage = :file
111
+ config.featured_image_thumb_size = [400, 300]
112
+ config.featured_image_square_size = [400, 400]
111
113
 
112
114
  initializer 'spotlight-assets.initialize' do
113
115
  Rails.application.config.assets.precompile += %w( Jcrop.gif )
@@ -115,7 +117,7 @@ module Spotlight
115
117
 
116
118
  # To present curators with analytics reports on the exhibit dashboard, you need to configure
117
119
  # an Analytics provider. Google Analytics support is provided out-of-the-box.
118
- Spotlight::Engine.config.analytics_provider = nil
120
+ config.analytics_provider = nil
119
121
 
120
122
  initializer 'analytics.initialize' do
121
123
  Spotlight::Engine.config.analytics_provider = Spotlight::Analytics::Ga
@@ -131,21 +133,21 @@ module Spotlight
131
133
  # b) download the pkcs12 key and make it accessible to your application
132
134
  # c) in e.g. an initializer, set these configuration values as appropriate
133
135
  # to your OAuth2 service account and analytics property:
134
- Spotlight::Engine.config.ga_pkcs12_key_path = nil
135
- Spotlight::Engine.config.ga_web_property_id = nil
136
- Spotlight::Engine.config.ga_email = nil
137
- Spotlight::Engine.config.ga_analytics_options = {}
138
- Spotlight::Engine.config.ga_page_analytics_options = Spotlight::Engine.config.ga_analytics_options.merge(limit: 5)
136
+ config.ga_pkcs12_key_path = nil
137
+ config.ga_web_property_id = nil
138
+ config.ga_email = nil
139
+ config.ga_analytics_options = {}
140
+ config.ga_page_analytics_options = config.ga_analytics_options.merge(limit: 5)
139
141
 
140
142
  Blacklight::Engine.config.inject_blacklight_helpers = false
141
143
 
142
144
  # Query parameters for autocomplete requests
143
- Spotlight::Engine.config.autocomplete_search_field = 'autocomplete'
144
- Spotlight::Engine.config.default_autocomplete_params = { qf: 'id^1000 full_title_tesim^100 id_ng full_title_ng',
145
- facet: false,
146
- 'facet.field' => [] }
145
+ config.autocomplete_search_field = 'autocomplete'
146
+ config.default_autocomplete_params = { qf: 'id^1000 full_title_tesim^100 id_ng full_title_ng',
147
+ facet: false,
148
+ 'facet.field' => [] }
147
149
 
148
- Spotlight::Engine.config.default_browse_index_view_type = :gallery
150
+ config.default_browse_index_view_type = :gallery
149
151
 
150
152
  initializer 'blacklight.configuration' do
151
153
  # Field containing the last modified date for a Solr document
@@ -1,4 +1,4 @@
1
1
  #
2
2
  module Spotlight
3
- VERSION = '0.13.0'
3
+ VERSION = '0.14.0'
4
4
  end
@@ -13,8 +13,8 @@ describe Spotlight::ContactsController, type: :controller do
13
13
  end
14
14
 
15
15
  describe 'when signed in as a curator' do
16
- let(:user) { FactoryGirl.create(:exhibit_curator) }
17
- let(:exhibit) { user.roles.first.exhibit }
16
+ let(:user) { FactoryGirl.create(:exhibit_curator, exhibit: exhibit) }
17
+ let(:exhibit) { FactoryGirl.create(:exhibit) }
18
18
  let(:contact) { FactoryGirl.create(:contact, exhibit: exhibit, name: 'Andrew Carnegie') }
19
19
  before { sign_in user }
20
20
 
@@ -9,9 +9,8 @@ describe Spotlight::HomePagesController, type: :controller do
9
9
  it { is_expected.to be_a Spotlight::Catalog::AccessControlsEnforcement }
10
10
 
11
11
  describe 'when signed in as a curator' do
12
- let(:user) { FactoryGirl.create(:exhibit_curator) }
12
+ let(:user) { FactoryGirl.create(:exhibit_curator, exhibit: exhibit) }
13
13
  before do
14
- FactoryGirl.create(:role, exhibit: exhibit, user: user)
15
14
  sign_in user
16
15
  end
17
16
 
@@ -89,8 +88,7 @@ describe Spotlight::HomePagesController, type: :controller do
89
88
  end
90
89
 
91
90
  it 'redirects an authorized user to the signin path' do
92
- user = FactoryGirl.create(:exhibit_curator)
93
- FactoryGirl.create(:role, exhibit: exhibit, user: user)
91
+ user = FactoryGirl.create(:exhibit_curator, exhibit: exhibit)
94
92
  sign_in user
95
93
  get :show, exhibit_id: exhibit
96
94
  expect(response).to be_successful
@@ -12,6 +12,13 @@ describe Spotlight::ResourcesController, type: :controller do
12
12
  end
13
13
  end
14
14
 
15
+ describe 'GET monitor' do
16
+ it 'is not allowed' do
17
+ get :monitor, exhibit_id: exhibit
18
+ expect(response).to redirect_to main_app.new_user_session_path
19
+ end
20
+ end
21
+
15
22
  describe 'POST create' do
16
23
  it 'is not allowed' do
17
24
  post :create, exhibit_id: exhibit
@@ -50,6 +57,13 @@ describe Spotlight::ResourcesController, type: :controller do
50
57
  end
51
58
  end
52
59
 
60
+ describe 'GET monitor' do
61
+ it 'succesfully renders json' do
62
+ get :monitor, exhibit_id: exhibit
63
+ expect(response).to be_success
64
+ end
65
+ end
66
+
53
67
  describe 'POST create' do
54
68
  let(:blacklight_solr) { double }
55
69
  it 'create a resource' do
@@ -105,7 +105,7 @@ describe Spotlight::RolesController, type: :controller do
105
105
  post :invite, exhibit_id: exhibit, user: 'user@example.com', role: 'curator'
106
106
  end.to change { Spotlight::Engine.user_class.count }.by(1)
107
107
  expect(Spotlight::Engine.user_class.last.roles.length).to eq 1
108
- expect(Spotlight::Engine.user_class.last.roles.first.exhibit).to eq exhibit
108
+ expect(Spotlight::Engine.user_class.last.roles.first.resource).to eq exhibit
109
109
  end
110
110
 
111
111
  it 'adds the user to the exhibit via a role' do
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spotlight::SitesController, type: :controller do
4
+ routes { Spotlight::Engine.routes }
5
+
6
+ describe 'when user does not have access' do
7
+ before { sign_in FactoryGirl.create(:exhibit_visitor) }
8
+ describe 'GET edit' do
9
+ it 'denies access' do
10
+ get :edit
11
+ expect(response).to redirect_to main_app.root_path
12
+ end
13
+ end
14
+ end
15
+
16
+ describe 'when user is an admin' do
17
+ let(:admin) { FactoryGirl.create(:site_admin) }
18
+ before { sign_in admin }
19
+
20
+ describe 'GET edit' do
21
+ it 'allows access' do
22
+ get :edit
23
+ expect(response).to be_successful
24
+ end
25
+ end
26
+
27
+ describe 'GET edit_exhibits' do
28
+ it 'allows access' do
29
+ get :edit_exhibits
30
+ expect(response).to be_successful
31
+ end
32
+ end
33
+
34
+ describe 'PATCH update' do
35
+ let!(:exhibit_a) { FactoryGirl.create(:exhibit) }
36
+ let!(:exhibit_b) { FactoryGirl.create(:exhibit) }
37
+
38
+ it 'changes the exhibit order' do
39
+ patch :update, site: { exhibits_attributes: [{ id: exhibit_a.id, weight: 5 }, { id: exhibit_b.id, weight: 2 }] }
40
+
41
+ expect(response).to redirect_to(exhibits_path)
42
+
43
+ expect(Spotlight::Exhibit.all.first).to eq exhibit_b
44
+ expect(exhibit_a.reload.weight).to eq 5
45
+ end
46
+ end
47
+ end
48
+ end
@@ -31,10 +31,9 @@ describe Spotlight::VersionsController, type: :controller do
31
31
 
32
32
  describe 'when logged in as a curator' do
33
33
  let(:exhibit) { FactoryGirl.create(:exhibit) }
34
- let(:user) { FactoryGirl.create(:exhibit_curator) }
34
+ let(:user) { FactoryGirl.create(:exhibit_curator, exhibit: exhibit) }
35
35
  let!(:page) { FactoryGirl.create(:feature_page, exhibit: exhibit) }
36
36
  before do
37
- FactoryGirl.create(:role, exhibit: exhibit, user: user)
38
37
  sign_in user
39
38
  end
40
39
 
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :role, class: Spotlight::Role do
3
- exhibit
3
+ resource { FactoryGirl.build(:exhibit) }
4
4
  role 'curator'
5
5
  user
6
6
  end
@@ -8,18 +8,18 @@ FactoryGirl.define do
8
8
 
9
9
  factory :site_admin do
10
10
  after(:create) do |user, _evaluator|
11
- create_list(:role, 1, user: user, exhibit_id: nil, role: 'admin')
11
+ user.roles.create role: 'admin', resource: Spotlight::Site.instance
12
12
  end
13
13
  end
14
14
 
15
15
  factory :exhibit_admin do
16
16
  after(:create) do |user, evaluator|
17
- create_list(:role, 1, user: user, exhibit: evaluator.exhibit, role: 'admin')
17
+ user.roles.create role: 'admin', resource: evaluator.exhibit
18
18
  end
19
19
  end
20
20
  factory :exhibit_curator do
21
21
  after(:create) do |user, evaluator|
22
- create_list(:role, 1, user: user, exhibit: evaluator.exhibit, role: 'curator')
22
+ user.roles.create role: 'curator', resource: evaluator.exhibit
23
23
  end
24
24
  end
25
25