spec/mongoid/enum_spec.rb in mongoid-enum-i18n-0.5.0 vs spec/mongoid/enum_spec.rb in mongoid-enum-i18n-0.8.1
- old
+ new
@@ -1,7 +1,8 @@
require 'spec_helper'
+# Test Class
class User
include Mongoid::Document
include Mongoid::Enum
enum :status, [:awaiting_approval, :approved, :banned]
@@ -9,10 +10,13 @@
default: [],
multiple: true,
required: false
end
+class Admin < User
+end
+
describe Mongoid::Enum do
let(:klass) { User }
let(:instance) { User.new }
let(:alias_name) { :status }
let(:field_name) { alias_name.to_sym }
@@ -75,11 +79,11 @@
it 'is set to the values' do
expect(klass::STATUS).to eq values
end
end
- describe 'accessors'do
+ describe 'accessors' do
context 'when singular' do
describe 'setter' do
it 'accepts strings' do
instance.status = 'banned'
expect(instance.status).to eq :banned
@@ -133,24 +137,25 @@
instance.roles << :author
expect(instance.roles).to eq [:author]
end
it 'accepts arrays of strings' do
- instance.roles = %w( author editor )
+ instance.roles = %w(author editor)
instance.save
puts instance.errors.full_messages
instance.reload
expect(instance.roles).to include(:author)
expect(instance.roles).to include(:editor)
end
- it 'accepts arrays of symbols' do
+ it 'accepts arrays of symbols' do
instance.roles = [:author, :editor]
expect(instance.roles).to include(:author)
expect(instance.roles).to include(:editor)
end
end
+
describe '{{value}}!' do
context 'when field is nil' do
it 'creates an array containing the value' do
instance.roles = nil
instance.save
@@ -264,8 +269,17 @@
end
it 'should have a helper to translate the values' do
expect(User.status_values)
.to eq([['Awaiting Approval', :awaiting_approval]])
+ end
+
+ it 'should use class where it was coded into' do
+ expect(Admin.status_values)
+ .to eq([['Awaiting Approval', :awaiting_approval]])
+ end
+
+ it 'should use class where it was coded into' do
+ expect(Admin.new.status_i18n).to eq('Awaiting Approval')
end
end
end