Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rails 5 #1483

Merged
merged 4 commits into from
Aug 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ Metrics/ClassLength:
Exclude:
- 'app/models/spotlight/resource.rb'
- 'lib/generators/spotlight/**/*' # Generators tend to have longer class lengths due to their lengthy public API

Style/PredicateName:
Exclude:
- 'app/models/concerns/spotlight/ar_light.rb'
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ rvm:
- 2.3.1
- 2.2.5

matrix:
include:
- rvm: 2.3.1
env: "RAILS_VERSION=5.0.0"

notifications:
irc: "irc.freenode.org#blacklight"

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ else
end
end
# END ENGINE_CART BLOCK

eval_gemfile File.expand_path('spec/test_app_templates/Gemfile.extra', File.dirname(__FILE__))
3 changes: 1 addition & 2 deletions app/controllers/concerns/spotlight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def exhibit_search_action_url(*args)

def exhibit_search_facet_url(*args)
options = args.extract_options!
options = params.merge(options).except(:exhibit_id, :only_path)

options = params.to_unsafe_h.merge(options).except(:exhibit_id, :only_path)
spotlight.facet_exhibit_catalog_url(current_exhibit, *args, options)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spotlight/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def redirect_to_exhibit_home_without_search_params!
end

def add_breadcrumb_with_search_params
add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), request.fullpath if has_search_parameters?
add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), spotlight.search_exhibit_catalog_path(params.to_unsafe_h) if has_search_parameters?
end

# rubocop:disable Metrics/AbcSize
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/spotlight/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SearchesController < Spotlight::ApplicationController

def create
@search.attributes = search_params
@search.query_params = params.except(:exhibit_id, :search, *blacklisted_search_session_params).reject { |_k, v| v.blank? }
@search.query_params = query_params

if @search.save
redirect_to :back, notice: t(:'helpers.submit.search.created', model: @search.class.model_name.human.downcase)
Expand Down Expand Up @@ -103,6 +103,10 @@ def search_params
)
end

def query_params
params.to_unsafe_h.with_indifferent_access.except(:exhibit_id, :search, *blacklisted_search_session_params).reject { |_k, v| v.blank? }
end

def featured_image_attributes
[:display, :source, :image, :remote_image_url, :document_global_id, :image_crop_x, :image_crop_y, :image_crop_w, :image_crop_h]
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/concerns/spotlight/ar_light.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ module ArLight
##
# Mock activerecord class-level methods
module ClassMethods
def has_attribute?(*_args)
false
end

def columns_hash
{}
end

def base_class
self
end
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/spotlight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module SolrDocument
include GlobalID::Identification

included do
extend ActsAsTaggableOn::Compatibility
extend ActsAsTaggableOn::Taggable

acts_as_taggable
Expand Down
4 changes: 3 additions & 1 deletion app/models/spotlight/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def field_weight(fields, index)
end

def value_to_boolean(v)
if defined? ActiveRecord::Type
if defined? ActiveModel::Type::Boolean
ActiveModel::Type::Boolean.new.cast v
elsif defined? ActiveRecord::Type::Boolean
# Rails 4.2+
ActiveRecord::Type::Boolean.new.type_cast_from_database v
else
Expand Down
13 changes: 12 additions & 1 deletion app/models/spotlight/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ def cast_value
return value unless field

if field.ends_with? Spotlight::Engine.config.solr_fields.boolean_suffix
ActiveRecord::Type::Boolean.new.type_cast_from_database(value)
value_to_boolean(value)
else
value
end
end

def value_to_boolean(v)
if defined? ActiveModel::Type::Boolean
ActiveModel::Type::Boolean.new.cast v
elsif defined? ActiveRecord::Type::Boolean
# Rails 4.2+
ActiveRecord::Type::Boolean.new.type_cast_from_database v
else
ActiveRecord::ConnectionAdapters::Column.value_to_boolean v
end
end
end
end
12 changes: 10 additions & 2 deletions app/models/spotlight/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ def waiting!
end

def enqueued_at
ActiveRecord::Type::DateTime.new.type_cast_from_database(super)
if defined? ActiveModel::Type::DateTime
ActiveModel::Type::DateTime.new.cast(super)
else
ActiveRecord::Type::DateTime.new.type_cast_from_database(super)
end
end

def last_indexed_finished
ActiveRecord::Type::DateTime.new.type_cast_from_database(super)
if defined? ActiveModel::Type::DateTime
ActiveModel::Type::DateTime.new.cast(super)
else
ActiveRecord::Type::DateTime.new.type_cast_from_database(super)
end
end

def document_model
Expand Down
4 changes: 4 additions & 0 deletions app/models/spotlight/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def documents
end
end

def count
documents.size
end

delegate :blacklight_config, to: :exhibit

def display_masthead?
Expand Down
4 changes: 2 additions & 2 deletions app/uploaders/spotlight/attachment_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def store_dir
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
# # ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# "/images/fallback/" + [version_name, 'default.png'].compact.join('_')
# end

# Process files as they are uploaded:
Expand Down
4 changes: 4 additions & 0 deletions app/uploaders/spotlight/avatar_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ class AvatarUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def default_url
ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
end
end
end
4 changes: 4 additions & 0 deletions app/uploaders/spotlight/featured_image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ class FeaturedImageUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def default_url
ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
end
end
end
4 changes: 4 additions & 0 deletions app/uploaders/spotlight/item_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ def extension_white_list
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def default_url
ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
end
end
end
4 changes: 4 additions & 0 deletions app/uploaders/spotlight/masthead_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ class MastheadUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def default_url
ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
end
end
end
2 changes: 1 addition & 1 deletion app/views/spotlight/pages/_view_type_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span class="sr-only"><%= t('blacklight.search.view_title') %></span>
<div class="view-type-group btn-group">
<% views.each do |view, config| %>
<%= link_to url_for(params.merge(:view => view)), :title => t("blacklight.search.view_title.#{view}", default: t("blacklight.search.view.#{view}", default: blacklight_config.view[view].title)), :class => "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if block_document_index_view_type(block) == view}" do %>
<%= link_to url_for(search_state.to_h.merge(view: view)), :title => t("blacklight.search.view_title.#{view}", default: t("blacklight.search.view.#{view}", default: blacklight_config.view[view].title)), :class => "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if block_document_index_view_type(block) == view}" do %>
<%= render_view_type_group_icon view %>
<span class="caption"><%= t("blacklight.search.view.#{view}") %></span>
<% end %>
Expand Down
7 changes: 4 additions & 3 deletions blacklight-spotlight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ these collections.)

s.required_ruby_version = '~> 2.2'

s.add_dependency 'rails', '~> 4.0', '>= 4.2.0'
s.add_dependency 'rails', '>= 4.2.0', '< 6'
s.add_dependency 'blacklight', '~> 6.3'
s.add_dependency 'autoprefixer-rails'
s.add_dependency 'cancancan'
Expand All @@ -28,8 +28,8 @@ these collections.)
s.add_dependency 'carrierwave-crop'
s.add_dependency 'mini_magick'
s.add_dependency 'bootstrap_form', '~> 2.2'
s.add_dependency 'acts-as-taggable-on', '~> 3.5'
s.add_dependency 'friendly_id', '~> 5.1.0'
s.add_dependency 'acts-as-taggable-on', '>= 4.0.0.pre'
s.add_dependency 'friendly_id', '>= 5.2.0.beta.1', '< 6'
s.add_dependency 'breadcrumbs_on_rails', '~> 2.3.0'
s.add_dependency 'social-share-button', '~> 0.3'
s.add_dependency 'blacklight-gallery', '>= 0.3.0'
Expand All @@ -55,6 +55,7 @@ these collections.)
s.add_development_dependency 'rspec-its'
s.add_development_dependency 'rspec-activemodel-mocks'
s.add_development_dependency 'rspec-collection_matchers'
s.add_development_dependency 'rails-controller-testing'
s.add_development_dependency 'capybara', '>= 2.5.0'
s.add_development_dependency 'rubocop', '~> 0.41', '>= 0.41.2'
s.add_development_dependency 'rubocop-rspec'
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/spotlight/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def inject_spotlight_routes
end

def friendly_id
gem 'friendly_id'
gem 'friendly_id', github: 'norman/friendly_id'
generate 'friendly_id'
end

Expand Down Expand Up @@ -119,7 +119,7 @@ def add_mailer_defaults
end

def generate_social_share_button_initializer
gem 'social-share-button'
gem 'social-share-button', github: 'cbeer/social-share-button', branch: 'on_load'
directory 'config'
end

Expand Down
10 changes: 9 additions & 1 deletion lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ module Spotlight
class Engine < ::Rails::Engine
isolate_namespace Spotlight
# Breadcrumbs on rails must be required outside of an initializer or it doesn't get loaded.
require 'breadcrumbs_on_rails'
require 'breadcrumbs_on_rails/breadcrumbs'
require 'breadcrumbs_on_rails/action_controller'

initializer 'breadcrumbs_on_rails.initialize' do
ActiveSupport.on_load(:action_controller) do
include BreadcrumbsOnRails::ActionController
end
end

require 'carrierwave'
require 'carrierwave/crop'
require 'social-share-button'
Expand Down
28 changes: 20 additions & 8 deletions spec/controllers/spotlight/appearances_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@
end

describe 'PATCH update' do
let(:first_nav) { exhibit.main_navigations.first }
let(:last_nav) { exhibit.main_navigations.last }
it 'updates the navigation' do
first_nav = exhibit.main_navigations.first
last_nav = exhibit.main_navigations.last
patch :update, exhibit_id: exhibit, exhibit: {
main_navigations_attributes: [
{ id: first_nav.id, label: 'Some Label', weight: 500 },
{ id: last_nav.id, display: false }
]
}
if Rails::VERSION::MAJOR >= 5
patch :update, params: {
exhibit_id: exhibit,
exhibit: {
main_navigations_attributes: {
0 => { id: first_nav.id, label: 'Some Label', weight: 500 },
1 => { id: last_nav.id, display: false }
}
}
}
else
patch :update, exhibit_id: exhibit, exhibit: {
main_navigations_attributes: [
{ id: first_nav.id, label: 'Some Label', weight: 500 },
{ id: last_nav.id, display: false }
]
}
end
expect(flash[:notice]).to eq 'The exhibit was successfully updated.'
expect(response).to redirect_to edit_exhibit_appearance_path(exhibit)
assigns[:exhibit].tap do |saved|
Expand Down
16 changes: 12 additions & 4 deletions spec/controllers/spotlight/solr_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
doc = arr.first
end

post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit
post_update_with_json_body(exhibit, a: 1)

expect(response).to be_successful
expect(doc).to include 'a' => 1
Expand All @@ -41,7 +41,7 @@
end

it 'raises an error' do
post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit
post_update_with_json_body(exhibit, a: 1)

expect(response.code).to eq '409'
end
Expand All @@ -53,7 +53,7 @@
doc = arr.first
end

post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit
post_update_with_json_body(exhibit, a: 1)

expect(response).to be_successful
expect(doc).to include exhibit.solr_data
Expand All @@ -67,11 +67,19 @@

allow_any_instance_of(SolrDocument).to receive(:to_solr).and_return(b: 1)

post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit
post_update_with_json_body(exhibit, a: 1)

expect(response).to be_successful
expect(doc).to include b: 1
end
end
end

def post_update_with_json_body(exhibit, hash)
if Rails::VERSION::MAJOR >= 5
post :update, body: hash.to_json, params: { exhibit_id: exhibit }, as: :json
else
post :update, hash.to_json, content_type: :json, exhibit_id: exhibit
end
end
end
9 changes: 8 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
ENV['RAILS_ENV'] ||= 'test'

require 'factory_girl'
require 'database_cleaner'
require 'devise'
require 'engine_cart'
EngineCart.load_application!

Internal::Application.config.active_job.queue_adapter = :inline

require 'rails-controller-testing' if Rails::VERSION::MAJOR >= 5
require 'rspec/collection_matchers'
require 'rspec/its'
require 'rspec/rails'
Expand Down Expand Up @@ -47,6 +49,7 @@

RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!

config.use_transactional_fixtures = false

Expand Down Expand Up @@ -88,6 +91,10 @@
config.after(:each, type: :feature) { Warden.test_reset! }
config.include Controllers::EngineHelpers, type: :controller
config.include Capybara::DSL
if Rails::VERSION::MAJOR >= 5
config.include ::Rails.application.routes.url_helpers
config.include ::Rails.application.routes.mounted_helpers
end
config.include Spotlight::TestFeaturesHelpers, type: :feature
end

Expand Down
Loading