Skip to content

Commit

Permalink
Remove ActiveRecord patch
Browse files Browse the repository at this point in the history
Patching ActiveRecord is dangerous. Furthermore, query optimization is
out of scope of this gem.
This fixes Travis builds for Rails 4.0 and 4.1.
  • Loading branch information
ledermann committed Apr 12, 2015
1 parent 43d5a88 commit 94e7be3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 20 deletions.
13 changes: 0 additions & 13 deletions lib/rails-settings/setting_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,5 @@ def _set_value(name, v)
def _target_class
target_type.constantize
end

# Patch ActiveRecord to save serialized attributes only if they are changed
if ActiveRecord::VERSION::MAJOR < 4
# https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L70
def update(*)
super(changed) if changed?
end
else
# https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L73
def update_record(*)
super(keys_for_partial_write) if changed?
end
end
end
end
7 changes: 0 additions & 7 deletions spec/queries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,5 @@
user.settings(:dashboard).update_attributes! :foo => 'bar'
}.to perform_queries(1)
end

it "should not touch database if there are no changes made" do
expect {
user.settings(:dashboard).update_attributes :theme => 'pink'
user.settings(:calendar).update_attributes :scope => 'all'
}.to perform_queries(0)
end
end
end

0 comments on commit 94e7be3

Please sign in to comment.