Permalink
Browse files

use new_without_change_tracking constructor when objects are coming o…

…ut of the database
  • Loading branch information...
1 parent e3bce77 commit e091b9b6f3df08eea2cf18ddcd4da18f3b4ed8fb @jamesgolick committed Jan 3, 2010
Showing with 9 additions and 13 deletions.
  1. +2 −1 lib/friendly/translator.rb
  2. +7 −12 spec/unit/translator_spec.rb
@@ -12,7 +12,8 @@ def initialize(serializer = JSON, time = Time)
def to_object(klass, record)
record.delete(:added_id)
attributes = serializer.parse(record.delete(:attributes))
- klass.new attributes.merge(record).merge(:new_record => false)
+ attributes.merge!(record).merge!(:new_record => false)
+ klass.new_without_change_tracking attributes
end
def to_record(document)
@@ -16,20 +16,15 @@
:created_at => @time,
:updated_at => @time,
:attributes => "THE JSON"}
- @klass = FakeDocument
- @doc = @translator.to_object(@klass, @row)
+ @doc = stub
+ @klass = stub
+ @klass.stubs(:new_without_change_tracking).
+ with(:updated_at => @time, :new_record => false,
+ :name => "Stewie", :created_at => @time).returns(@doc)
end
- it "creates a klass with the attributes from the json" do
- @doc.name.should == "Stewie"
- end
-
- it "sets updated_at" do
- @doc.updated_at.should == @time
- end
-
- it "sets new_record to false" do
- @doc.new_record.should be_false
+ it "creates a new object without change tracking" do
+ @translator.to_object(@klass, @row).should == @doc
end
end

0 comments on commit e091b9b

Please sign in to comment.