rails_attr_enum 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'User::Role.label_value_pairs' do
4
+ let(:enum) { User::Role }
5
+
6
+ before { default_user_roles }
7
+
8
+ let :all_pairs do
9
+ [[enum::ADMIN_LABEL, enum::ADMIN],
10
+ [enum::EDITOR_LABEL, enum::EDITOR],
11
+ [enum::AUTHOR_LABEL, enum::AUTHOR],
12
+ [enum::USER_LABEL, enum::USER]]
13
+ end
14
+
15
+ context 'with no arguments' do
16
+ subject { enum.label_value_pairs }
17
+
18
+ it { should have(4).items }
19
+ it { should eq(all_pairs) }
20
+ end
21
+
22
+ context 'with one argument' do
23
+ subject { enum.label_value_pairs(:editor) }
24
+
25
+ it { should have(1).item }
26
+ it { should eq([[enum::EDITOR_LABEL, enum::EDITOR]]) }
27
+ end
28
+
29
+ context 'with more than one argument' do
30
+ subject { enum.label_value_pairs(:author, :editor, :admin) }
31
+
32
+ it { should have(3).items }
33
+
34
+ it {
35
+ should eq [[enum::ADMIN_LABEL, enum::ADMIN],
36
+ [enum::EDITOR_LABEL, enum::EDITOR],
37
+ [enum::AUTHOR_LABEL, enum::AUTHOR]]
38
+ }
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ describe 'User::Role' do
2
+ context 'with mapped entries method' do
3
+ let(:enum) { User::Role }
4
+
5
+ before { default_user_roles }
6
+
7
+ describe '.keys' do
8
+ it 'returns all the keys' do
9
+ expect(enum.keys).to eq [:admin, :editor, :author, :user]
10
+ end
11
+ end
12
+
13
+ describe '.values' do
14
+ it 'returns all the values' do
15
+ expect(enum.values).to eq [0, 1, 2, 3]
16
+ end
17
+ end
18
+
19
+ describe '.labels' do
20
+ it 'returns all the labels' do
21
+ expect(enum.labels).to eq %w(Admin Editor Author User)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,15 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe User do
4
- before :all do
3
+ describe 'Role enum for User' do
4
+ before :each do
5
+ # Ensure default enum set up
6
+ default_user_roles
7
+
5
8
  # Create test users
6
- create(:user, :role_admin)
7
- 2.times { create(:user, :role_editor) }
8
- 5.times { create(:user, :role_author) }
9
- 20.times { create(:user, :role_user) }
10
- end
9
+ # Having issues with FactoryGirl and changing the role enum values
10
+ # between tests
11
+ # create(:user, :role_admin)
12
+ # 2.times { create(:user, :role_editor) }
13
+ # 5.times { create(:user, :role_author) }
14
+ # 20.times { create(:user, :role_user) }
11
15
 
12
- before { default_user_roles }
16
+ User.create(role: User::Role::ADMIN)
17
+ 2.times { User.create(role: User::Role::EDITOR) }
18
+ 5.times { User.create(role: User::Role::AUTHOR) }
19
+ 20.times { User.create(role: User::Role::USER) }
20
+ end
13
21
 
14
22
  it 'adds the scope methods for each possible enum value' do
15
23
  scopes = [:role_admin, :role_editor, :role_admin, :role_user]
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_attr_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Fairbank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Create enums for Rails model attributes like enums in C languages
@@ -100,6 +100,8 @@ files:
100
100
  - test/dummy/rspec
101
101
  - test/dummy/spec/factories/users.rb
102
102
  - test/dummy/spec/json_spec.rb
103
+ - test/dummy/spec/label_value_pairs_spec.rb
104
+ - test/dummy/spec/mapped_entries_methods_spec.rb
103
105
  - test/dummy/spec/models/user_enum_scope_spec.rb
104
106
  - test/dummy/spec/models/user_enum_spec.rb
105
107
  - test/dummy/spec/spec_helper.rb
@@ -114,12 +116,12 @@ require_paths:
114
116
  - lib
115
117
  required_ruby_version: !ruby/object:Gem::Requirement
116
118
  requirements:
117
- - - ! '>='
119
+ - - '>='
118
120
  - !ruby/object:Gem::Version
119
121
  version: '0'
120
122
  required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  requirements:
122
- - - ! '>='
124
+ - - '>='
123
125
  - !ruby/object:Gem::Version
124
126
  version: '0'
125
127
  requirements: []
@@ -172,6 +174,8 @@ test_files:
172
174
  - test/dummy/rspec
173
175
  - test/dummy/spec/factories/users.rb
174
176
  - test/dummy/spec/json_spec.rb
177
+ - test/dummy/spec/label_value_pairs_spec.rb
178
+ - test/dummy/spec/mapped_entries_methods_spec.rb
175
179
  - test/dummy/spec/models/user_enum_scope_spec.rb
176
180
  - test/dummy/spec/models/user_enum_spec.rb
177
181
  - test/dummy/spec/spec_helper.rb