Skip to content

Commit

Permalink
Add Rails 5.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored and cbeer committed May 17, 2017
1 parent f6e5abc commit 0152557
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 30 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Expand Up @@ -5,16 +5,16 @@ notifications:
email: false

rvm:
- 2.3.1
- 2.4.1

matrix:
include:
- rvm: 2.3.3
env: "RAILS_VERSION=4.2.8"
- rvm: 2.2.6
env: "RAILS_VERSION=5.0.2"
- rvm: 2.2.7
env: "RAILS_VERSION=5.0.3"
- rvm: 2.3.4
env: "RAILS_VERSION=5.1.1"
- rvm: jruby-9.1.7.0
env: "RAILS_VERSION=5.0.2 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
env: "RAILS_VERSION=5.0.3 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
allow_failures:
- rvm: jruby-9.1.7.0
fast_finish: true
Expand All @@ -24,7 +24,7 @@ before_install:
- gem install bundler

env:
- "RAILS_VERSION=5.0.2"
- "RAILS_VERSION=5.1.1"

notifications:
irc: "irc.freenode.org#blacklight"
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20140202020201_create_searches.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class CreateSearches < ActiveRecord::Migration
class CreateSearches < ActiveRecord::Migration[4.2]
def self.up
create_table :searches do |t|
t.binary :query_params
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20140202020202_create_bookmarks.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class CreateBookmarks < ActiveRecord::Migration
class CreateBookmarks < ActiveRecord::Migration[4.2]
def self.up
create_table :bookmarks do |t|
t.integer :user_id, index: true, null: false
Expand Down
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class AddPolymorphicTypeToBookmarks < ActiveRecord::Migration
class AddPolymorphicTypeToBookmarks < ActiveRecord::Migration[4.2]
def change
add_column(:bookmarks, :document_type, :string) unless Bookmark.connection.column_exists? :bookmarks, :document_type

Expand Down
21 changes: 16 additions & 5 deletions lib/generators/blacklight/assets_generator.rb
Expand Up @@ -8,23 +8,34 @@ def assets

return if has_blacklight_assets?

contents = "\n//\n// Required by Blacklight\n"
contents += "//= require jquery\n" if rails_5_1?
contents += "//= require blacklight/blacklight\n"

marker = if turbolinks?
'//= require turbolinks'
elsif rails_5_1?
'//= require rails-ujs'
else
'//= require jquery_ujs'
end

insert_into_file "app/assets/javascripts/application.js", :after => marker do
<<-EOF
//
// Required by Blacklight
//= require blacklight/blacklight
EOF
contents
end
end

# This is not a default in Rails 5.1
def add_jquery
gem 'jquery-rails' if rails_5_1?
end

private

def rails_5_1?
Rails.version =~ /5\.1/
end

def turbolinks?
@turbolinks ||= IO.read("app/assets/javascripts/application.js").include?('turbolinks')
end
Expand Down
Expand Up @@ -5,7 +5,7 @@ class AlternateController < CatalogController
end

def xyz *args
view_context.image_tag "asdfg"
view_context.tag "img"
end

helper_method :xyz
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/blacklight/user_generator.rb
Expand Up @@ -20,7 +20,7 @@ def generate_devise_assets
return unless options[:devise]

gem "devise"
gem "devise-guests", "~> 0.5"
gem "devise-guests", "~> 0.6"

Bundler.with_clean_env do
run "bundle install"
Expand Down
20 changes: 14 additions & 6 deletions spec/helpers/catalog_helper_spec.rb
Expand Up @@ -131,15 +131,19 @@ def render_grouped_response?

describe "rss_feed_link_tag" do
context "when an alternate scope is passed in" do
subject(:tag) { helper.rss_feed_link_tag(route_set: my_engine) }

let(:my_engine) { double("Engine") }
let(:query_params) { { controller: 'catalog', action: 'index' } }
let(:config) { Blacklight::Configuration.new }
let(:search_state) { Blacklight::SearchState.new(query_params, config, controller) }

it "calls url_for on the engine scope" do
before do
allow(helper).to receive(:search_state).and_return search_state
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
tag = helper.rss_feed_link_tag(route_set: my_engine)
end

it "calls url_for on the engine scope" do
expect(my_engine).to receive(:url_for).and_return('/rss-path')
expect(tag).to match /title="RSS for results"/
expect(tag).to match /rel="alternate"/
expect(tag).to match %r{type="application/rss\+xml"}
Expand All @@ -149,15 +153,19 @@ def render_grouped_response?

describe "atom_feed_link_tag" do
context "when an alternate scope is passed in" do
subject(:tag) { helper.atom_feed_link_tag(route_set: my_engine) }

let(:my_engine) { double("Engine") }
let(:query_params) { { controller: 'catalog', action: 'index' } }
let(:config) { Blacklight::Configuration.new }
let(:search_state) { Blacklight::SearchState.new(query_params, config, controller) }

it "calls url_for on the engine scope" do
before do
allow(helper).to receive(:search_state).and_return search_state
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
tag = helper.atom_feed_link_tag(route_set: my_engine)
end

it "calls url_for on the engine scope" do
expect(my_engine).to receive(:url_for).and_return('/atom-path')
expect(tag).to match /title="Atom for results"/
expect(tag).to match /rel="alternate"/
expect(tag).to match %r{type="application/atom\+xml"}
Expand Down
14 changes: 9 additions & 5 deletions spec/helpers/url_helper_spec.rb
Expand Up @@ -127,14 +127,18 @@

context "when an alternate scope is passed in" do
let(:my_engine) { double("Engine") }
subject(:tag) { helper.link_back_to_catalog(route_set: my_engine) }

it "calls url_for on the engine scope" do
before do
allow(helper).to receive(:current_search_session).and_return double(:query_params => query_params)
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
tag = helper.link_back_to_catalog(route_set: my_engine)
end

it "calls url_for on the engine scope" do
expect(my_engine).to receive(:url_for)
.with(q:"query", f: "facets", controller: "catalog")
.and_return('link-url')
expect(tag).to match /Back to Search/
expect(tag).to match /q=query/
expect(tag).to match /f=facets/
expect(tag).to match /link-url/
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/test_app_templates/Gemfile.extra
@@ -1,4 +1,4 @@
if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\./ || ENV['RAILS_VERSION'] == 'edge'
gem 'rails-controller-testing'
gem 'deprecation'
end
2 changes: 1 addition & 1 deletion spec/views/catalog/_facets.html.erb_spec.rb
Expand Up @@ -6,7 +6,7 @@
before do
allow(view).to receive_messages(blacklight_config: blacklight_config)
allow(view).to receive(:search_action_path) do |*args|
search_catalog_url *args
'/catalog'
end
end

Expand Down

0 comments on commit 0152557

Please sign in to comment.