spec/acfs/model/attributes_spec.rb in acfs-0.32.1.1.b275 vs spec/acfs/model/attributes_spec.rb in acfs-0.32.1.1.b276

- old
+ new

@@ -39,39 +39,42 @@ describe '#write_attributes' do before do model.attribute :name, :string, default: 'John' model.attribute :age, :integer, default: 25 + model.send :define_method, :name= do |name| + write_attribute :name, "The Great #{name}" + end end let(:args) { [params] } let(:params){ {name: 'James'} } let(:m) { model.new } let(:action) { lambda{ m.write_attributes *args } } subject { action } it 'should update attributes' do should change(m, :attributes) - .from({'name' => 'John', 'age' => 25}) - .to({'name' => 'James', 'age' => 25}) + .from({'name' => 'The Great John', 'age' => 25}) + .to({'name' => 'The Great James', 'age' => 25}) end context 'without non-hash params' do let(:params) { 'James' } it { should_not change(m, :attributes) } its(:call) { should eq false } end context 'with unknown attributes' do - let(:params) { {name: 'James', born_at: Time.now} } + let(:params) { {name: 'James', born_at: 'today'} } it { should_not raise_error } - it 'should update known attributes' do + it 'should update known attributes and store unknown' do should change(m, :attributes) - .from({'name' => 'John', 'age' => 25}) - .to({'name' => 'James', 'age' => 25}) + .from({'name' => 'The Great John', 'age' => 25}) + .to({'name' => 'The Great James', 'age' => 25, 'born_at' => 'today'}) end context 'with unknown: :raise option' do let(:args) { [params, {unknown: :raise}] } @@ -92,17 +95,10 @@ end it 'should return default value' do expect(model.new.name).to be == 'John' end - - it 'should return matching ivar\'s value' do - o = model.new - o.instance_variable_set :@name, 'Johannes' - - expect(o.name).to be == 'Johannes' - end end describe '#_setter_' do before do model.attribute :name, :string, default: 'John' @@ -112,16 +108,9 @@ it 'should set value' do o = model.new o.name = 'Paul' expect(o.name).to be == 'Paul' - end - - it 'should set instance var' do - o = model.new - o.name = 'Paul' - - expect(o.instance_variable_get(:@name)).to be == 'Paul' end it 'should update attributes hash' do o = model.new o.name = 'Johannes'