Skip to content

Commit

Permalink
Merge pull request #59 from xinranxiao/master
Browse files Browse the repository at this point in the history
Handle Rails 5 #tables deprecation
  • Loading branch information
pboling authored Mar 9, 2017
2 parents 68dca4d + 800bb0b commit a09a04a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gemfile:
- gemfiles/Gemfile.activerecord-4.0.x
- gemfiles/Gemfile.activerecord-4.1.x
- gemfiles/Gemfile.activerecord-4.2.x
- gemfiles/Gemfile.activerecord-5.0.x
matrix:
allow_failures:
- rvm: ruby-head
Expand All @@ -32,6 +33,8 @@ matrix:
gemfile: gemfiles/Gemfile.activerecord-3.2.x
- rvm: jruby-9.0.1.0
gemfile: gemfiles/Gemfile.activerecord-4.0.x
- rvm: jruby-9.0.1.0
gemfile: gemfiles/Gemfile.activerecord-5.0.x
- rvm: jruby-1.7.22
gemfile: gemfiles/Gemfile.activerecord-2.3.x
- rvm: jruby-1.7.22
Expand All @@ -42,6 +45,12 @@ matrix:
gemfile: gemfiles/Gemfile.activerecord-3.2.x
- rvm: jruby-1.7.22
gemfile: gemfiles/Gemfile.activerecord-4.0.x
- rvm: jruby-1.7.22
gemfile: gemfiles/Gemfile.activerecord-4.1.x
- rvm: jruby-1.7.22
gemfile: gemfiles/Gemfile.activerecord-4.2.x
- rvm: jruby-1.7.22
gemfile: gemfiles/Gemfile.activerecord-5.0.x
- rvm: 2.2.3
gemfile: gemfiles/Gemfile.activerecord-2.3.x
- rvm: 2.2.3
Expand All @@ -58,10 +67,16 @@ matrix:
gemfile: gemfiles/Gemfile.activerecord-3.0.x
- rvm: 2.1.7
gemfile: gemfiles/Gemfile.activerecord-3.1.x
- rvm: 2.1.7
gemfile: gemfiles/Gemfile.activerecord-5.0.x
- rvm: 2.0.0
gemfile: gemfiles/Gemfile.activerecord-2.3.x
- rvm: 2.0.0
gemfile: gemfiles/Gemfile.activerecord-4.2.x
- rvm: 2.0.0
gemfile: gemfiles/Gemfile.activerecord-5.0.x
- rvm: 1.9.3
gemfile: gemfiles/Gemfile.activerecord-5.0.x
- rvm: 1.9.3
gemfile: gemfiles/Gemfile.activerecord-4.2.x
- rvm: 1.9.3
Expand Down
14 changes: 14 additions & 0 deletions gemfiles/Gemfile.activerecord-5.0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "http://rubygems.org"

gemspec :path => ".."

gem "activerecord", "~> 5.0.0"
gem "sqlite3", "~> 1.3", :platforms => [:ruby]
gem "activerecord-jdbcsqlite3-adapter", :platforms => [:jruby]
gem "activerecord-mysql2-adapter", :platforms => [:ruby]
gem "activerecord-jdbcmysql-adapter", :platforms => [:jruby]
gem "pg", :platforms => [:ruby_18]
gem "activerecord-jdbcpostgresql-adapter", :platforms => [:jruby]

gem "reek", "~> 3.5.0", :platforms => [:ruby]
gem "roodi", "~> 5.0.0", :platforms => [:ruby]
11 changes: 9 additions & 2 deletions lib/flag_shih_tzu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,15 @@ def check_flag_column(colmn, custom_table_name = table_name)
has_ar = (!!defined?(ActiveRecord) && respond_to?(:descends_from_active_record?))
# Supposedly Rails 2.3 takes care of this, but this precaution
# is needed for backwards compatibility
has_table = has_ar ? connection.tables.include?(custom_table_name) : true
has_table = if has_ar
if ::ActiveRecord::VERSION::MAJOR >= 5
connection.data_sources
else
connection.tables.include?(custom_table_name)
end
else
true
end
if has_table
found_column = columns.detect { |column| column.name == colmn }
# If you have not yet run the migration that adds the 'flags' column
Expand Down Expand Up @@ -578,5 +586,4 @@ def get_bit_for(flag, colmn)
def determine_flag_colmn_for(flag)
self.class.determine_flag_colmn_for(flag)
end

end
2 changes: 2 additions & 0 deletions test/flag_shih_tzu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ def test_should_not_error_out_when_column_is_not_present
def assert_where_value(expected, scope)
actual = if ActiveRecord::VERSION::MAJOR == 2
scope.proxy_options[:conditions]
elsif ActiveRecord::VERSION::MAJOR >= 5
scope.where_clause.ast.children.first.expr
else
scope.where_values.first
end
Expand Down
1 change: 0 additions & 1 deletion test/schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ActiveRecord::Schema.define(:version => 0) do
create_table :spaceships, :force => true do |t|
t.string :type, :null => false, :default => 'Spaceship'
t.integer :flags, :null => false, :default => 0
t.string :incorrect_flags_column, :null => false, :default => ''
end
Expand Down

0 comments on commit a09a04a

Please sign in to comment.