Skip to content

Commit

Permalink
all tests running with rails 3.1.0.rc6
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Mack committed Aug 18, 2011
1 parent 28bf955 commit 0ff2323
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion couch_potato.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|

s.add_dependency 'json'
s.add_dependency 'couchrest', '>=1.0.1'
s.add_dependency 'activemodel'
s.add_dependency 'activemodel', ">=3.1.0.rc6"

s.add_development_dependency 'rspec', '>=2.0'
s.add_development_dependency 'timecop'
Expand Down
5 changes: 3 additions & 2 deletions lib/couch_potato/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ def update_document(document, validate)

def valid_document?(document)
errors = document.errors.errors.dup
errors.instance_variable_set("@messages", errors.messages.dup) if errors.respond_to?(:messages)
document.valid?
errors.each_pair do |k, v|
v.each {|message| document.errors.add(k, message)}
errors.each do |k, v|
document.errors.add(k, v)
end
document.errors.empty?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/couch_potato/persistence/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def json_create(json)
instance = self.new
instance._id = json[:_id] || json['_id']
instance._rev = json[:_rev] || json['_rev']
instance._document = HashWithIndifferentAccess.new(json)
instance._document = json #HashWithIndifferentAccess.new(json)
instance
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,22 @@ def check_name
it "should keep error messages set in custom before_validation filters" do
user = ValidatedUser.new(:name => "john")
user.valid?.should == false
user.errors.on(:name).should == "should be Paul"
user.errors[:name].should == ["should be Paul"]
end

it "should combine the errors from validations and callbacks" do
user = ValidatedUser.new(:name => nil)
user.valid?.should == false
user.errors.on(:name).any? {|msg| msg =~ /can't be (empty|blank)/ }.should == true
user.errors.on(:name).any? {|msg| msg == "should be Paul" }.should == true
user.errors.on(:name).size.should == 2
user.errors[:name].any? {|msg| msg =~ /can't be (empty|blank)/ }.should == true
user.errors[:name].any? {|msg| msg == "should be Paul" }.should == true
user.errors[:name].size.should == 2
end

it "should clear the errors on subsequent calls to valid?" do
user = ValidatedUser.new(:name => nil)
user.valid?.should == false
user.name = 'Paul'
user.valid?.should == true
user.errors.on(:name).should == nil
user.errors[:name].should == []
end
end
14 changes: 7 additions & 7 deletions spec/unit/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def set_errors
it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
spock = Vulcan.new(:name => 'spock')
@db.save_document(spock)
spock.errors.on(:validation).should == 'failed'
spock.errors[:validation].should == ['failed']
end

it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
Expand All @@ -182,14 +182,14 @@ def set_errors
spock.new?.should == false
spock.name = "spock's father"
@db.save_document(spock)
spock.errors.on(:validation).should == 'failed'
spock.errors[:validation].should == ['failed']
end

it "should keep errors generated from normal validations together with errors set in normal validations" do
spock = Vulcan.new
@db.save_document(spock)
spock.errors.on(:validation).should == 'failed'
spock.errors.on(:name).should =~ /can't be (empty|blank)/
spock.errors[:validation].should == ['failed']
spock.errors[:name].first.should =~ /can't be (empty|blank)/
end

it "should clear errors on subsequent, valid saves when creating" do
Expand All @@ -198,7 +198,7 @@ def set_errors

spock.name = 'Spock'
@db.save_document(spock)
spock.errors.on(:name).should == nil
spock.errors[:name].should == []
end

it "should clear errors on subsequent, valid saves when updating" do
Expand All @@ -207,11 +207,11 @@ def set_errors

spock.name = nil
@db.save_document(spock)
spock.errors.on(:name).should =~ /can't be (empty|blank)/
spock.errors[:name].first.should =~ /can't be (empty|blank)/

spock.name = 'Spock'
@db.save_document(spock)
spock.errors.on(:name).should == nil
spock.errors[:name].should == []
end

end
Expand Down

0 comments on commit 0ff2323

Please sign in to comment.