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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9801e3908003e982b471d4af5ddbd4e589eb128
4
- data.tar.gz: e0ad1758a752118f79a55e87a6d2b8a44f03cc8e
3
+ metadata.gz: 294b0316bab39b37461ec932a8aacf826401f714
4
+ data.tar.gz: 2d781e84e8ffd18095a210c26fc7a3afecd1083c
5
5
  SHA512:
6
- metadata.gz: de99edcb330ea895b1b5fa548d0291cb4b71ef742a6aa84066fb02f150b3a9286c8eb8ce8cde65e53cd2a66a6e55944ea44b2d5524c0c31211ec220fed70592b
7
- data.tar.gz: 8ddb3ae5b3cbf6bf8cc0561b405aff12000c035bd24f713ae4cf13b0fba5f5db2498d498994ea085d747e87a24828c6ef9be06e14993953858b2e7abee029aaf
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) }
@@ -1,3 +1,3 @@
1
1
  module RailsAttrEnum
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -266,3 +266,67 @@ Migrating to CreateUsers (20131023212242)
266
266
   (0.1ms) rollback transaction
267
267
   (0.1ms) begin transaction
268
268
   (0.1ms) rollback transaction
269
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
270
+  (0.1ms) begin transaction
271
+  (0.2ms) rollback transaction
272
+  (0.1ms) begin transaction
273
+  (0.1ms) rollback transaction
274
+  (0.1ms) begin transaction
275
+  (0.1ms) rollback transaction
276
+  (0.1ms) begin transaction
277
+  (0.1ms) rollback transaction
278
+  (0.1ms) begin transaction
279
+  (0.1ms) rollback transaction
280
+  (0.1ms) begin transaction
281
+  (0.1ms) rollback transaction
282
+  (0.1ms) begin transaction
283
+  (0.1ms) rollback transaction
284
+  (0.1ms) begin transaction
285
+  (0.1ms) rollback transaction
286
+  (0.1ms) begin transaction
287
+  (0.1ms) rollback transaction
288
+  (0.1ms) begin transaction
289
+  (0.1ms) rollback transaction
290
+  (0.1ms) begin transaction
291
+  (0.1ms) rollback transaction
292
+  (0.1ms) begin transaction
293
+  (0.1ms) rollback transaction
294
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
295
+  (0.1ms) begin transaction
296
+  (0.1ms) rollback transaction
297
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
298
+  (0.1ms) begin transaction
299
+  (0.1ms) rollback transaction
300
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
301
+  (0.1ms) begin transaction
302
+  (0.1ms) rollback transaction
303
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
304
+  (0.1ms) begin transaction
305
+  (0.1ms) rollback transaction
306
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
307
+  (0.1ms) begin transaction
308
+  (0.1ms) rollback transaction
309
+  (0.1ms) begin transaction
310
+  (0.1ms) rollback transaction
311
+  (0.1ms) begin transaction
312
+  (0.1ms) rollback transaction
313
+  (0.1ms) begin transaction
314
+  (0.1ms) rollback transaction
315
+  (0.1ms) begin transaction
316
+  (0.1ms) rollback transaction
317
+  (0.0ms) begin transaction
318
+  (0.1ms) rollback transaction
319
+  (0.1ms) begin transaction
320
+  (0.1ms) rollback transaction
321
+  (0.1ms) begin transaction
322
+  (0.1ms) rollback transaction
323
+  (0.1ms) begin transaction
324
+  (0.1ms) rollback transaction
325
+  (0.1ms) begin transaction
326
+  (0.1ms) rollback transaction
327
+  (0.1ms) begin transaction
328
+  (0.1ms) rollback transaction
329
+  (0.1ms) begin transaction
330
+  (0.1ms) rollback transaction
331
+  (0.1ms) begin transaction
332
+  (0.1ms) rollback transaction
@@ -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
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