spec/models/journey/resource_spec.rb in embark-journey-0.0.12 vs spec/models/journey/resource_spec.rb in embark-journey-0.0.13
- old
+ new
@@ -53,10 +53,49 @@
expect(r.status).to eq 'Inactive'
end
end
end
+
+ describe '::EnumSets' do
+ let(:klass) do
+ Class.new(Journey::Resource) do
+ self.element_name = 'fault'
+ end
+ end
+
+ describe '.enum_set' do
+ let(:asset_types) { %w[ABM ATM] }
+
+ before do
+ klass.enum_set :asset_type, asset_types
+ end
+
+ it 'stores the collection' do
+ expect(klass::ASSET_TYPES).to eq(asset_types)
+ expect(klass.new.asset_type_values).to eq(asset_types)
+ end
+
+ it 'gets and sets enumerated attributes' do
+ r = klass.create(name: 'X')
+ expect(r).to be_persisted
+ r.asset_type = ['ATM']
+ r.save
+ r = klass.find(r.id)
+ expect(r.asset_type).to eq(['ATM'])
+ end
+
+ it 'remembers enum values' do
+ r = klass.create(name: 'X', asset_type: ['ATM', 'ABM'])
+ expect(r).to be_persisted
+ r = klass.find(r.id)
+ expect(r.asset_type).to eq ['ATM', 'ABM']
+ end
+
+ end
+ end
+
describe '::Queries' do
describe '.where' do
it 'returns matching objects, sorted by attribute' do
klass.all.each(&:destroy)
@@ -179,6 +218,7 @@
it 'returns 0 for no matching objects' do
count = klass.count(query: { name: SecureRandom.uuid })
expect(count).to eq(0)
end
end
+
end