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.2 #256

Merged
merged 4 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ gemfile:
- gemfiles/rails_4_2.gemfile
- gemfiles/rails_5_0.gemfile
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_5_2.gemfile
matrix:
exclude:
- rvm: ruby-2.0.0-p648
gemfile: gemfiles/rails_5_0.gemfile
- rvm: ruby-2.0.0-p648
gemfile: gemfiles/rails_5_1.gemfile
- rvm: ruby-2.0.0-p648
gemfile: gemfiles/rails_5_2.gemfile
- rvm: ruby-2.1.10
gemfile: gemfiles/rails_5_0.gemfile
- rvm: ruby-2.1.10
gemfile: gemfiles/rails_5_1.gemfile
- rvm: ruby-2.1.10
gemfile: gemfiles/rails_5_2.gemfile
- rvm: ruby-2.4.1
gemfile: gemfiles/rails_4_0.gemfile
- rvm: ruby-2.4.1
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ end
appraise "rails-5-1" do
gem "rails", "~> 5.1.0"
end

appraise "rails-5-2" do
gem "rails", "~> 5.2.0"
end
1 change: 1 addition & 0 deletions gemfiles/rails_4_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source "https://rubygems.org"

gem "pry-byebug", platforms: :ruby
gem "rails", "~> 4.0.0"
gem "nokogiri", "~> 1.6.8"

Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_4_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source "https://rubygems.org"

gem "pry-byebug", platforms: :ruby
gem "rails", "~> 4.1.0"
gem "nokogiri", "~> 1.6.8"

Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_4_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source "https://rubygems.org"

gem "pry-byebug", platforms: :ruby
gem "rails", "~> 4.2.0"
gem "nokogiri", "~> 1.6.8"

Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source "https://rubygems.org"

gem "pry-byebug", platforms: :ruby
gem "rails", "~> 5.0.0"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_5_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source "https://rubygems.org"

gem "pry-byebug", platforms: :ruby
gem "rails", "~> 5.1.0"

gemspec path: "../"
8 changes: 8 additions & 0 deletions gemfiles/rails_5_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "pry-byebug", platforms: :ruby
gem "rails", "~> 5.2.0"

gemspec path: "../"
17 changes: 15 additions & 2 deletions lib/dynamoid/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Dirty

module ClassMethods
def from_database(*)
super.tap { |d| d.changed_attributes.clear }
super.tap { |d| d.send(:clear_changes_information) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to have it handle both versions since older versions of rails I don't think will support this so maybe:

d.respond_to?(:clear_changes_information) ? d.clear_changes_information : d.changed_attributes.clear

And similar to below to handle both

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardhsu fixed

end
end

Expand All @@ -28,7 +28,7 @@ def clear_changes
(block_given? ? yield : true).tap do |result|
unless result == false # failed validation; nil is OK.
@previously_changed = previous
changed_attributes.clear
clear_changes_information
end
end
end
Expand All @@ -43,5 +43,18 @@ def write_attribute(name, value)
def attribute_method?(attr)
super || self.class.attributes.has_key?(attr.to_sym)
end

if ActiveModel::VERSION::STRING >= '5.2.0'
# The ActiveModel::Dirty API was changed
# https://github.com/rails/rails/commit/c3675f50d2e59b7fc173d7b332860c4b1a24a726#diff-aaddd42c7feb0834b1b5c66af69814d3
# So we just try to disable new functionality

def mutations_from_database
@mutations_from_database ||= ActiveModel::NullMutationTracker.instance
end

def forget_attribute_assignments
end
end
end
end