Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Dirty model integration"

  • Loading branch information...
commit c1889eff9164893a03d4ef64c820d8ec08e39790 1 parent 23786e2
@jeremy jeremy authored
View
2  CHANGELOG.md
@@ -9,8 +9,6 @@
* Railtie enables configuration and dev reloading of observers just like
ActiveRecord when using ARes with Rails. ARes also now runs ActiveSupport
load hooks for `:active_resource`. ([#109], [Ches Martin])
-* Integrates ActiveModel::Dirty so that only changed attributes are persisted
- on saves.
### Fixes ###
View
35 lib/active_resource/base.rb
@@ -601,8 +601,8 @@ def connection(refresh = false)
end
def headers
- Thread.current["active.resource.headers.#{self.object_id}"] ||= {}
-
+ Thread.current["active.resource.headers.#{self.object_id}"] ||= {}
+
if superclass != Object && superclass.headers
Thread.current["active.resource.headers.#{self.object_id}"] = superclass.headers.merge(Thread.current["active.resource.headers.#{self.object_id}"])
else
@@ -1221,10 +1221,7 @@ def dup
# my_company.save # sends PUT /companies/1 (update)
def save
run_callbacks :save do
- (new? ? create : update).tap do |result|
- @previously_changed = changes
- @changed_attributes.clear
- end
+ new? ? create : update
end
end
@@ -1426,10 +1423,8 @@ def connection(refresh = false)
# Update the resource on the remote service.
def update
run_callbacks :update do
- if changed_attributes.present?
- connection.put(element_path(prefix_options), encode(only: changed_attributes.keys), self.class.headers).tap do |response|
- load_attributes_from_response(response)
- end
+ connection.put(element_path(prefix_options), encode, self.class.headers).tap do |response|
+ load_attributes_from_response(response)
end
end
end
@@ -1542,12 +1537,7 @@ def method_missing(method_symbol, *arguments) #:nodoc:
if method_name =~ /(=|\?)$/
case $1
when "="
- field = $`
- value = arguments.first
-
- self.class.define_attribute_methods field
- send("#{field}_will_change!") unless attributes[field] == value
- attributes[field] = value
+ attributes[$`] = arguments.first
when "?"
attributes[$`]
end
@@ -1558,18 +1548,6 @@ def method_missing(method_symbol, *arguments) #:nodoc:
super
end
end
-
- # ActiveModel::Dirty expects an attribute method that returns the value of a named attribute.
- # Raise NoMethodError if the named attribute does not exist in order to preserve behavior expected by #clone.
- def attribute(name)
- key = name.to_s
-
- if attributes.has_key?(key)
- attributes[key]
- else
- raise NoMethodError
- end
- end
end
class Base
@@ -1581,7 +1559,6 @@ class Base
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
include ActiveResource::Reflection
- include ActiveModel::Dirty
end
ActiveSupport.run_load_hooks(:active_resource, Base)
View
111 test/cases/base/dirty_test.rb
@@ -1,111 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/hash/conversions'
-require "fixtures/person"
-require "fixtures/street_address"
-
-########################################################################
-# Testing the schema of your Active Resource models
-########################################################################
-class DirtyTest < ActiveModel::TestCase
- def setup
- @person = Person.new
- end
-
- def teardown
- Person.schema = nil # hack to stop test bleedthrough...
- end
-
- test "setting attribute will result in change" do
- assert !@person.changed?
- assert !@person.name_changed?
- @person.name = "Ringo"
- assert @person.changed?
- assert @person.name_changed?
- end
-
- test "list of changed attribute keys" do
- assert_equal [], @person.changed
- @person.name = "Paul"
- assert_equal ['name'], @person.changed
- end
-
- test "changes to attribute values" do
- assert !@person.changes['name']
- @person.name = "John"
- assert_equal [nil, "John"], @person.changes['name']
- end
-
- test "changes accessible through both strings and symbols" do
- @person.name = "David"
- assert_not_nil @person.changes[:name]
- assert_not_nil @person.changes['name']
- end
-
- test "attribute mutation" do
- @person.name = "Yam"
- @person.instance_variable_get(:@changed_attributes).clear
- assert !@person.name_changed?
- @person.name.replace("Hadad")
- assert !@person.name_changed?
- @person.name_will_change!
- @person.name.replace("Baal")
- assert @person.name_changed?
- end
-
- test "resetting attribute" do
- @person.name = "Bob"
- @person.reset_name!
- assert_nil @person.name
- assert !@person.name_changed?
- end
-
- test "setting color to same value should not result in change being recorded" do
- @person.stubs(:create).returns(true)
- @person.color = "red"
- assert @person.color_changed?
- @person.save
- assert !@person.color_changed?
- assert !@person.changed?
- @person.color = "red"
- assert !@person.color_changed?
- assert !@person.changed?
- end
-
- test "saving should reset model's changed status" do
- @person.stubs(:create).returns(true)
- @person.name = "Alf"
- assert @person.changed?
- @person.save
- assert !@person.changed?
- assert !@person.name_changed?
- end
-
- test "saving should preserve previous changes" do
- @person.stubs(:create).returns(true)
- @person.name = "Jericho Cane"
- @person.save
- assert_equal [nil, "Jericho Cane"], @person.previous_changes['name']
- end
-
- test "previous value is preserved when changed after save" do
- @person.stubs(:create).returns(true)
- assert_equal({}, @person.changed_attributes)
- @person.name = "Paul"
- assert_equal({ "name" => nil }, @person.changed_attributes)
-
- @person.save
-
- @person.name = "John"
- assert_equal({ "name" => "Paul" }, @person.changed_attributes)
- end
-
- test "changing the same attribute multiple times retains the correct original value" do
- @person.stubs(:create).returns(true)
- @person.name = "Otto"
- @person.save
- @person.name = "DudeFella ManGuy"
- @person.name = "Mr. Manfredgensonton"
- assert_equal ["Otto", "Mr. Manfredgensonton"], @person.name_change
- assert_equal @person.name_was, "Otto"
- end
-end
View
19 test/cases/base_test.rb
@@ -909,26 +909,9 @@ def test_update_conflict
mock.get "/people/2.json", {}, @david
mock.put "/people/2.json", @default_request_headers, nil, 409
end
- assert_raise(ActiveResource::ResourceConflict) do
- person = Person.find(2)
- person.name = 'new name'
- person.save
- end
- end
-
- def test_update_with_no_changes_does_nothing
- matz = Person.find(:first)
- matz.class.connection.expects(:put).never
- matz.save
+ assert_raise(ActiveResource::ResourceConflict) { Person.find(2).save }
end
- def test_update_with_changes_only_puts_changed_attributes
- matz = Person.find(:first)
- matz.name = 'Rick'
- resp = ActiveResource::Response.new(@matz, 200)
- matz.class.connection.expects(:put).with("/people/#{matz.id}.json", matz.encode(:only => :name), {}).returns(resp)
- matz.save
- end
######
# update_attribute(s)(!)
View
1  test/cases/observing_test.rb
@@ -43,7 +43,6 @@ def test_create_fires_save_and_create_notifications
def test_update_fires_save_and_update_notifications
person = Person.find(1)
- person.name = 'new name'
person.save
assert_equal [:before_save, :before_update, :after_update, :after_save], self.history
end
Please sign in to comment.
Something went wrong with that request. Please try again.