spec/shared/resource_spec.rb in vj-sdk-0.2.1 vs spec/shared/resource_spec.rb in vj-sdk-0.4.0
- old
+ new
@@ -31,11 +31,14 @@
it "does not set any errors on the object" do
@successful.errors.should be_empty
end
it "gets an ID" do
@successful.id.should be_kind_of(Integer)
- end
+ end
+ it "resets the dirty attributes" do
+ @successful.dirty_attributes.should be_empty
+ end
end
describe "unsuccessfully" do
before(:all) do
@bad_attributes = @klass.gen_attributes.inject({}) do |memo, (key,value)|
memo.merge({key=>(@fixed_attributes.include?(key)? value : "")})
@@ -56,10 +59,13 @@
@fail.errors.should_not be_empty
end
it "does not get an ID" do
@fail.id.should be_nil
end
+ it "does not reset the dirty attributes" do
+ @fail.dirty_attributes.should_not be_empty
+ end
end
end
end
describe "finding a record by ID" do
@@ -73,17 +79,27 @@
attrs = @found.attributes.dup
attrs.delete(:id)
attrs = attrs.reject {|k,v| !v}
attrs.should_not be_empty
end
+
+ it "has no dirty attributes" do
+ @record.dirty_attributes.should be_empty
+ end
end
describe "listing records" do
before(:all) do
@list = @klass.all
end
+ it "returns items with no dirty attributes" do
+ @list.each do |i|
+ i.dirty_attributes.should be_empty
+ end
+ end
+
it "should return a collection object" do
@list.should be_kind_of(Videojuicer::Resource::Collection)
end
describe "with pagination settings" do
@@ -114,9 +130,19 @@
@record.resource_path.should =~ /\/#{@plural_name}\/#{@record.id}\.json$/
end
it "reloads from the remote API successfully" do
@record.reload.should be_true
+ end
+
+ it "resets the dirty attributes when reloaded" do
+ r = @klass.gen
+ r = @klass.get(r.id)
+ dattr = @klass.attributes.select {|a,props| props[:class] == String || props[:class] == Integer }.map {|a| a.first }.first
+ r.send("#{dattr}=", 1)
+ r.attr_dirty?(dattr).should be_true
+ r.reload
+ r.attr_dirty?(dattr).should be_false
end
it "saves successfully" do
saved = @record.save
@record.errors.should == {}
\ No newline at end of file