spec/integration/adjust_spec.rb in dm-adjust-0.9.11 vs spec/integration/adjust_spec.rb in dm-adjust-0.10.0
- old
+ new
@@ -1,16 +1,15 @@
-require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require 'spec_helper'
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
class Person
include DataMapper::Resource
- property :id, Integer, :serial => true
- property :name, String
+ property :id, Serial
+ property :name, String
property :salary, Integer, :default => 20000
- property :age, Integer
+ property :age, Integer
end
describe 'Adjust' do
before do
@@ -23,20 +22,20 @@
Person.create(:name => 'Amadeus',:age => 60)
end
describe 'Model#adjust!' do
it 'should adjust values' do
- repository(:default) do
+ DataMapper.repository(:default) do
Person.adjust!({:salary => 1000},true)
Person.all.each{|p| p.salary.should == 21000}
end
end
end
describe 'Collection#adjust!' do
it 'should adjust values' do
- repository(:default) do |repos|
+ DataMapper.repository(:default) do |repos|
@oldies = Person.all(:age.gte => 40)
@oldies.adjust!({:salary => 5000},true)
@oldies.each{|p| p.salary.should == 25000}
Person.get(1).salary.should == 20000
@@ -46,20 +45,31 @@
@children.each{|p| p.salary.should == 10000}
end
end
it 'should load the query if conditions were adjusted' do
- repository(:default) do |repos|
+ DataMapper.repository(:default) do |repos|
@specific = Person.all(:salary => 20000)
@specific.adjust!({:salary => 5000},true)
- @specific.length.should == 6
+
+ # Both of these are seemingly equal
+ # puts @specific.query.inspect
+ # puts Person.all(:salary => 25000).query.inspect
+ #<DataMapper::Query @repository=:default @model=Person @fields=[#<Property:Person:id>, #<Property:Person:name>, #<Property:Person:salary>, #<Property:Person:age>] @links=[] @conditions=[[:eql, #<Property:Person:salary>, 25000]] @order=[#<DataMapper::Query::Direction #<Property:Person:id> asc>] @limit=nil @offset=0 @reload=false @unique=false>
+ #<DataMapper::Query @repository=:default @model=Person @fields=[#<Property:Person:id>, #<Property:Person:name>, #<Property:Person:salary>, #<Property:Person:age>] @links=[] @conditions=[[:eql, #<Property:Person:salary>, 25000]] @order=[#<DataMapper::Query::Direction #<Property:Person:id> asc>] @limit=nil @offset=0 @reload=false @unique=false>
+ # puts @specific.all.length # is 0
+ # puts Person.all(@specific.query.relative({})).length # 0
+ # puts Person.all(:salary => 25000).length # 6 !
+
+ Person.all(:salary => 25000).length.should == 6
+ @specific.all.length.should == 6
end
end
end
describe 'Resource#adjust' do
it 'should adjust the value' do
- repository(:default) do |repos|
+ DataMapper.repository(:default) do |repos|
p = Person.get(1)
p.salary.should == 20000
p.adjust!({:salary => 1000},true)
p.salary.should == 21000
end