Sha256: 72a1e5e8765c248ba4e4f046f3d84593ff5aadf449d594612b6587d5315f45c4

Contents?: true

Size: 1.77 KB

Versions: 6

Compression:

Stored size: 1.77 KB

Contents

require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES

  class Person
    include DataMapper::Resource
    property :id, Integer, :serial => true
    property :name, String
    property :salary, Integer, :default => 20000
    property :age, Integer
  end

  describe 'Adjust' do

    before :all do
      Person.auto_migrate!(:default)
      Person.create(:name => 'George', :age => 15)
      Person.create(:name => 'Puff',   :age => 18)
      Person.create(:name => 'Danny',  :age => 26)
      Person.create(:name => 'Selma',  :age => 28)
      Person.create(:name => 'John',   :age => 49)
      Person.create(:name => 'Amadeus',:age => 60)
    end

    describe 'Resource#adjust!' do
      it 'should adjust values' do
        repository(:default) do
          p = Person.get(1)
          p.salary.should == 20000
          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|
          @oldies = Person.all(:age.gte => 40)
          @oldies.adjust!({:salary => 5000},true)
          @oldies.each{|p| p.salary.should == 25000}

          Person.get(1).salary.should == 20000

          @children = Person.all(:age.lte => 18)
          @children.adjust!({:salary => -10000},true)
          @children.each{|p| p.salary.should == 10000}
        end
      end

      it 'should load the query if conditions were adjusted' do
        repository(:default) do |repos|
          @specific = Person.all(:salary => 25000)
          @specific.adjust!({:salary => 5000},true)
          @specific.length.should == 2
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dm-adjust-0.9.2 spec/integration/adjust_spec.rb
dm-adjust-0.9.3 spec/integration/adjust_spec.rb
dm-adjust-0.9.4 spec/integration/adjust_spec.rb
dm-adjust-0.9.5 spec/integration/adjust_spec.rb
dm-adjust-0.9.6 spec/integration/adjust_spec.rb
dm-adjust-0.9.7 spec/integration/adjust_spec.rb