require 'spec_helper' describe Encore::Entity::Input::ExposedAttributes do shared_examples 'exposability' do before do spawn_object_class! end context 'with attribute name' do it { expect{ entity.assign_attributes(name: 'Art Vandelay') }.to raise_error(Encore::Entity::Input::InvalidAttributeError) } end context 'with column name' do before { entity.assign_attributes fullname: 'Art Vandelay' } it { expect(entity.object.name).to eql 'Art Vandelay' } end end let(:entity) { UserEntity.new } before do spawn_entity :UserEntity do expose :name, as: :fullname end end context 'with ActiveRecord model' do let(:spawn_object_class!) do spawn_model :User run_migration do create_table(:users, force: true) do |t| t.string :name t.timestamps end end end it_has_behavior 'exposability' end context 'with OpenStruct structure' do let(:spawn_object_class!) { spawn_struct :User } it_has_behavior 'exposability' end end