1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
require 'spec_helper'
describe Virtus, '#attributes=' do
shared_examples_for 'mass-assignment' do
it 'allows writing known attributes' do
subject.attributes = { :test => 'Hello World' }
expect(subject.test).to eql('Hello World')
end
it 'skips writing unknown attributes' do
subject.attributes = { :test => 'Hello World', :nothere => 'boom!' }
expect(subject.test).to eql('Hello World')
end
end
context 'with a class' do
let(:model) {
Class.new {
include Virtus
attribute :test, String
}
}
it_behaves_like 'mass-assignment' do
subject { model.new }
end
xit 'raises when attributes is not hash-like object' do
expect { model.new('not a hash, really') }.to raise_error(
NoMethodError, 'Expected "not a hash, really" to respond to #to_hash'
)
end
end
context 'with an instance' do
subject { model.new }
let(:model) { Class.new }
before do
subject.extend(Virtus)
subject.attribute :test, String
end
it_behaves_like 'mass-assignment'
end
end
|