rails_attr_enum 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_attr_enum/entry_value.rb +1 -1
- data/lib/rails_attr_enum/version.rb +1 -1
- data/test/dummy/log/test.log +64 -0
- data/test/dummy/spec/json_spec.rb +20 -0
- data/test/dummy/spec/models/user_spec.rb +0 -10
- data/test/dummy/spec/spec_helper.rb +10 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294b0316bab39b37461ec932a8aacf826401f714
|
4
|
+
data.tar.gz: 2d781e84e8ffd18095a210c26fc7a3afecd1083c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59f6044b759d53a721eda593a369c21c7e6507b5869522b0896b2953e84a5f9b9afc328494d28e2bbb32d75af87e733c1fbabbdeff59b5b6159f0b04f15d5eb4
|
7
|
+
data.tar.gz: 8b506c2b581c60cdd6fda0b07e5f148072fd001df4be6f418f26cda960088b4606b0d492a00a28b742f0f13bfcb2ed985941b1412273522cdaadcbd2ce7a74a5
|
@@ -3,7 +3,7 @@ require 'ostruct'
|
|
3
3
|
module RailsAttrEnum
|
4
4
|
## Forwarding class for actual attribute value
|
5
5
|
EntryValue = Struct.new(:model, :attr_name, :enum) do
|
6
|
-
delegate :==, :===, :inspect, to: :value
|
6
|
+
delegate :==, :===, :inspect, :to_json, :as_json, to: :value
|
7
7
|
|
8
8
|
def method_missing(name, *args, &block)
|
9
9
|
default = proc { value.send(name, *args, &block) }
|
data/test/dummy/log/test.log
CHANGED
@@ -266,3 +266,67 @@ Migrating to CreateUsers (20131023212242)
|
|
266
266
|
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
267
267
|
[1m[35m (0.1ms)[0m begin transaction
|
268
268
|
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
269
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.5ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
270
|
+
[1m[35m (0.1ms)[0m begin transaction
|
271
|
+
[1m[36m (0.2ms)[0m [1mrollback transaction[0m
|
272
|
+
[1m[35m (0.1ms)[0m begin transaction
|
273
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
274
|
+
[1m[35m (0.1ms)[0m begin transaction
|
275
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
276
|
+
[1m[35m (0.1ms)[0m begin transaction
|
277
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
278
|
+
[1m[35m (0.1ms)[0m begin transaction
|
279
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
280
|
+
[1m[35m (0.1ms)[0m begin transaction
|
281
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
282
|
+
[1m[35m (0.1ms)[0m begin transaction
|
283
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
284
|
+
[1m[35m (0.1ms)[0m begin transaction
|
285
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
286
|
+
[1m[35m (0.1ms)[0m begin transaction
|
287
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
288
|
+
[1m[35m (0.1ms)[0m begin transaction
|
289
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
290
|
+
[1m[35m (0.1ms)[0m begin transaction
|
291
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
292
|
+
[1m[35m (0.1ms)[0m begin transaction
|
293
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
294
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
295
|
+
[1m[35m (0.1ms)[0m begin transaction
|
296
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
297
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
298
|
+
[1m[35m (0.1ms)[0m begin transaction
|
299
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
300
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
301
|
+
[1m[35m (0.1ms)[0m begin transaction
|
302
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
303
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
304
|
+
[1m[35m (0.1ms)[0m begin transaction
|
305
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
306
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
307
|
+
[1m[35m (0.1ms)[0m begin transaction
|
308
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
309
|
+
[1m[35m (0.1ms)[0m begin transaction
|
310
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
311
|
+
[1m[35m (0.1ms)[0m begin transaction
|
312
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
313
|
+
[1m[35m (0.1ms)[0m begin transaction
|
314
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
315
|
+
[1m[35m (0.1ms)[0m begin transaction
|
316
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
317
|
+
[1m[35m (0.0ms)[0m begin transaction
|
318
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
319
|
+
[1m[35m (0.1ms)[0m begin transaction
|
320
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
321
|
+
[1m[35m (0.1ms)[0m begin transaction
|
322
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
323
|
+
[1m[35m (0.1ms)[0m begin transaction
|
324
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
325
|
+
[1m[35m (0.1ms)[0m begin transaction
|
326
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
327
|
+
[1m[35m (0.1ms)[0m begin transaction
|
328
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
329
|
+
[1m[35m (0.1ms)[0m begin transaction
|
330
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
331
|
+
[1m[35m (0.1ms)[0m begin transaction
|
332
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe 'User#to_json' do
|
5
|
+
before :each do
|
6
|
+
clear_user
|
7
|
+
|
8
|
+
User.class_eval do
|
9
|
+
extend RailsAttrEnum
|
10
|
+
attr_enum :role, :admin, :author, :editor, :user
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'correctly generates the json for the enum attribute' do
|
15
|
+
user = User.new(role: User::Role::AUTHOR)
|
16
|
+
user_json = user.to_json(only: :role)
|
17
|
+
|
18
|
+
expect(user_json).to eq({ role: 1 }.to_json)
|
19
|
+
end
|
20
|
+
end
|
@@ -53,16 +53,6 @@ describe User do
|
|
53
53
|
let(:u_editor) { User.new(role: User::Role::EDITOR) }
|
54
54
|
let(:u_user) { User.new(role: User::Role::USER) }
|
55
55
|
|
56
|
-
def clear_user
|
57
|
-
if User.const_defined?(:Role)
|
58
|
-
User.send(:remove_const, :Role)
|
59
|
-
end
|
60
|
-
|
61
|
-
if User.instance_variable_defined?(:@_attr_enums)
|
62
|
-
User.remove_instance_variable(:@_attr_enums)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
56
|
context 'when passing all symbols' do
|
67
57
|
before :each do
|
68
58
|
clear_user
|
@@ -40,3 +40,13 @@ RSpec.configure do |config|
|
|
40
40
|
# --seed 1234
|
41
41
|
config.order = "random"
|
42
42
|
end
|
43
|
+
|
44
|
+
def clear_user
|
45
|
+
if User.const_defined?(:Role)
|
46
|
+
User.send(:remove_const, :Role)
|
47
|
+
end
|
48
|
+
|
49
|
+
if User.instance_variable_defined?(:@_attr_enums)
|
50
|
+
User.remove_instance_variable(:@_attr_enums)
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_attr_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Fairbank
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- test/dummy/public/favicon.ico
|
95
95
|
- test/dummy/Rakefile
|
96
96
|
- test/dummy/README.rdoc
|
97
|
+
- test/dummy/spec/json_spec.rb
|
97
98
|
- test/dummy/spec/models/user_spec.rb
|
98
99
|
- test/dummy/spec/spec_helper.rb
|
99
100
|
homepage: https://github.com/jfairbank/rails_attr_enum
|
@@ -159,5 +160,6 @@ test_files:
|
|
159
160
|
- test/dummy/public/favicon.ico
|
160
161
|
- test/dummy/Rakefile
|
161
162
|
- test/dummy/README.rdoc
|
163
|
+
- test/dummy/spec/json_spec.rb
|
162
164
|
- test/dummy/spec/models/user_spec.rb
|
163
165
|
- test/dummy/spec/spec_helper.rb
|