Sha256: 5ede366c6ace1249283391c79f6ff20b9717017ef173e90409492ecce6e9b2dd

Contents?: true

Size: 1.9 KB

Versions: 4

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'
require 'kangaroo/model/base'

module Kangaroo
  module Model
    describe Attributes do
      before :all do
        @klass = Class.new(Kangaroo::Model::Base)
        @klass.define_multiple_accessors :a, :b
      end

      before :each do
        @klass.stub!(:default_attributes).and_return({})
      end

      it 'stores the attribute names' do
        @klass.attribute_names.should == ['a', 'b']
      end

      it 'allows to read attributes via read_attribute' do
        @object = @klass.new :a => 'one'
        @object.read_attribute(:a).should == 'one'
      end

      it 'allows to read attributes via getters' do
        @object = @klass.new :a => 'one'
        @object.a.should == 'one'
      end

      it 'allows to write attributes via write_attribute' do
        @object = @klass.new :a => 'one'
        @object.write_attribute :a, 'two'
        @object.a.should == 'two'
      end

      it 'allows to write attributes via setters' do
        @object = @klass.new :a => 'one'
        @object.a = 'two'
        @object.a.should == 'two'
      end

      it 'allows to mass assign attributes via #attributes=' do
        @object = @klass.new
        @object.attributes = {:a => 'one'}
        @object.a.should == 'one'
      end

      it 'allows to read all attributes via #attributes' do
        @object = @klass.new :a => 'one'
        @object.attributes['a'].should == 'one'
      end

      describe 'ActiveModel::Dirty behavior' do
        it 'marks changed attributes and stores old value' do
          @object = @klass.new :a => 'one'
          @object.a = 'two'
          @object.should be_changed
          @object.a_was.should == 'one'
          @object.should be_a_changed
        end

        it 'marks initial values as changed' do
          @object = @klass.new :a => 'one'
          @object.should be_changed
          @object.should be_a_changed
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kangaroo-0.0.3 spec/model/attributes_spec.rb
kangaroo-0.0.2 spec/model/attributes_spec.rb
kangaroo-0.0.1.pre2 spec/model/attributes_spec.rb
kangaroo-0.0.1.pre spec/model/attributes_spec.rb