push_type_core 0.6.0 → 0.7.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/fields/push_type/boolean_field.rb +12 -0
  3. data/app/fields/push_type/matrix_field.rb +13 -3
  4. data/app/fields/push_type/relation_field.rb +12 -6
  5. data/app/fields/push_type/select_field.rb +1 -1
  6. data/lib/push_type/core/engine.rb +4 -0
  7. data/lib/push_type/core.rb +2 -0
  8. data/lib/push_type/core_ext/to_bool.rb +25 -0
  9. data/lib/push_type/field_type.rb +1 -0
  10. data/lib/push_type/primitives/boolean_type.rb +12 -0
  11. data/lib/push_type/version.rb +1 -1
  12. data/test/dummy/config/initializers/push_type.rb +1 -1
  13. data/test/dummy/config/secrets.yml +2 -2
  14. data/test/dummy/db/migrate/{20151108150752_create_push_type_users.push_type.rb → 20160108132348_create_push_type_users.push_type.rb} +0 -0
  15. data/test/dummy/db/migrate/{20151108150753_create_push_type_nodes.push_type.rb → 20160108132349_create_push_type_nodes.push_type.rb} +0 -0
  16. data/test/dummy/db/migrate/{20151108150754_create_push_type_node_hierarchies.push_type.rb → 20160108132350_create_push_type_node_hierarchies.push_type.rb} +0 -0
  17. data/test/dummy/db/migrate/{20151108150755_create_push_type_assets.push_type.rb → 20160108132351_create_push_type_assets.push_type.rb} +0 -0
  18. data/test/dummy/db/migrate/{20151108150756_create_push_type_taxonomies.push_type.rb → 20160108132352_create_push_type_taxonomies.push_type.rb} +0 -0
  19. data/test/dummy/db/migrate/{20151108150757_create_push_type_taxonomy_hierarchies.push_type.rb → 20160108132353_create_push_type_taxonomy_hierarchies.push_type.rb} +0 -0
  20. data/test/dummy/db/migrate/{20151108150758_add_field_store_default_values.push_type.rb → 20160108132354_add_field_store_default_values.push_type.rb} +0 -0
  21. data/test/dummy/db/schema.rb +1 -1
  22. data/test/dummy/log/test.log +9084 -14616
  23. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/0ANSDcZJu9gPyqtYPIW729qm1kriQ29Vn9LU8T2SGQU.cache +0 -0
  24. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{tlOpTnaa_t4XAbGrJuMXP6N7RwkbFqu0Q3NnnTJGR_o.cache → 8FGH_ku24FOYEa6ACm3vyk_rZwODpSzv3MjZU4irm7M.cache} +0 -0
  25. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/_d65qW7wxRtKVSYpmfSenECz5QUWVI9pppUgV7TA1Rk.cache +0 -0
  26. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{ICYfNnwyQOM4ypAd7cL9ig1weq-ynnC7JO__sNCZo98.cache → o8jETQIOAUNl34ED3ZTGdlVAlYRSl8zt6mfx4Wr1_Hs.cache} +0 -0
  27. data/test/fields/push_type/boolean_field_test.rb +21 -0
  28. data/test/fields/push_type/matrix_field_test.rb +8 -2
  29. data/test/fields/push_type/relation_field_test.rb +12 -0
  30. data/test/lib/push_type/core_exts_test.rb +31 -0
  31. data/test/lib/push_type/primitives_test.rb +13 -0
  32. metadata +31 -30
  33. data/app/fields/push_type/node_field.rb +0 -27
  34. data/app/fields/push_type/taxonomy_field.rb +0 -21
  35. data/test/fields/push_type/node_field_test.rb +0 -48
  36. data/test/fields/push_type/taxonomy_field_test.rb +0 -48
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module PushType
4
+ class BooleanFieldTest < ActiveSupport::TestCase
5
+
6
+ class TestPage < PushType::Node
7
+ field :foo, :boolean
8
+ end
9
+
10
+ let(:node) { TestPage.create FactoryGirl.attributes_for(:node, foo: '1') }
11
+ let(:field) { node.fields[:foo] }
12
+
13
+ it { field.json_primitive.must_equal :boolean }
14
+ it { field.form_helper.must_equal :check_box }
15
+ it { field.json_value.must_equal true }
16
+ it { field.value.must_equal true }
17
+
18
+ it { node.foo.must_equal true }
19
+
20
+ end
21
+ end
@@ -4,13 +4,14 @@ module PushType
4
4
  class MatrixFieldTest < ActiveSupport::TestCase
5
5
 
6
6
  class TestPage < PushType::Node
7
- field :foo, :matrix do
7
+ field :foo, :matrix, grid: false do
8
8
  field :key, :string
9
9
  field :val, :text
10
10
  end
11
+ field :bar, :matrix, class: :location
11
12
  end
12
13
 
13
- let(:node) { TestPage.create FactoryGirl.attributes_for(:node, foo: val) }
14
+ let(:node) { TestPage.create FactoryGirl.attributes_for(:node, foo: val, bar: [1]) }
14
15
  let(:val) { [{ key: 'a', val: 'b' }, { key: 'x', val: 'y' }] }
15
16
  let(:field) { node.fields[:foo] }
16
17
 
@@ -23,5 +24,10 @@ module PushType
23
24
  it { field.value[0].key.must_equal 'a' }
24
25
  it { field.value[1].val.must_equal 'y' }
25
26
 
27
+ it { node.bar.first.must_be_instance_of Location }
28
+ it { node.bar.first.class.ancestors.must_include PushType::Structure }
29
+ it { node.fields[:bar].grid?.must_equal true }
30
+ it { node.fields[:foo].grid?.must_equal false }
31
+
26
32
  end
27
33
  end
@@ -6,6 +6,8 @@ module PushType
6
6
  class TestPage < PushType::Node
7
7
  field :page_id, :relation
8
8
  field :bar_ids, :relation, to: 'push_type/node', multiple: true
9
+ field :baz_ids, :relation, to: :page, scope: -> { order(created_at: :desc).all }
10
+ field :qux_ids, :relation, to: :page, scope: -> { all.hash_tree }
9
11
  end
10
12
 
11
13
  before do
@@ -17,6 +19,8 @@ module PushType
17
19
  let(:rel) { @pages.first }
18
20
  let(:foo) { node.fields[:page_id] }
19
21
  let(:bar) { node.fields[:bar_ids] }
22
+ let(:baz) { node.fields[:baz_ids] }
23
+ let(:qux) { node.fields[:qux_ids] }
20
24
 
21
25
  it { foo.json_primitive.must_equal :string }
22
26
  it { foo.template.must_equal 'relation' }
@@ -29,6 +33,7 @@ module PushType
29
33
  it { foo.choices.map { |c| c[:value] }.must_include rel.id }
30
34
  it { foo.relation_name.must_equal 'page' }
31
35
  it { foo.relation_class.must_equal Page }
36
+ it { foo.relation_items.must_be_kind_of ActiveRecord::Relation }
32
37
 
33
38
  it { bar.json_primitive.must_equal :array }
34
39
  it { bar.must_be :multiple? }
@@ -38,6 +43,13 @@ module PushType
38
43
  it { bar.json_value.must_equal @bars.map(&:id) }
39
44
  it { bar.value.must_equal @bars.map(&:id) }
40
45
  it { bar.choices.size.must_equal 7 }
46
+ it { bar.relation_items.must_be_kind_of ActiveRecord::Relation }
47
+
48
+ it { baz.relation_class.must_equal Page }
49
+ it { baz.choices.size.must_equal 4 }
50
+ it { baz.relation_items.must_be_kind_of ActiveRecord::Relation }
51
+ it { qux.choices.size.must_equal 4 }
52
+ it { qux.relation_items.must_be_kind_of Hash }
41
53
 
42
54
  it { node.page_id.must_equal rel.id }
43
55
  it { node.page.must_equal rel }
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ module PushType
4
+ class CoreExtTest < ActiveSupport::TestCase
5
+
6
+ describe 'to_bool' do
7
+ # Strings
8
+ it { ''.to_bool.must_equal false }
9
+ it { '0'.to_bool.must_equal false }
10
+ it { 'no'.to_bool.must_equal false }
11
+ it { 'false'.to_bool.must_equal false }
12
+ it { '1'.to_bool.must_equal true }
13
+ it { 'anything else'.to_bool.must_equal true }
14
+
15
+ # Fixnums
16
+ it { 0.to_bool.must_equal false }
17
+ it { 1.to_bool.must_equal true }
18
+ it { 1234.to_bool.must_equal true }
19
+
20
+ # Booleans
21
+ it { false.to_i.must_equal 0 }
22
+ it { false.to_bool.must_equal false }
23
+ it { true.to_i.must_equal 1 }
24
+ it { true.to_bool.must_equal true }
25
+
26
+ # Nils
27
+ it { nil.to_bool.must_equal false }
28
+ end
29
+
30
+ end
31
+ end
@@ -18,6 +18,19 @@ module PushType
18
18
  it { primitive.to_json(val).must_equal ['a', 'b', 'c'] }
19
19
  end
20
20
 
21
+ describe 'BooleanType' do
22
+ let(:primitive) { PushType::Primitives::BooleanType }
23
+
24
+ it { primitive.to_json(nil).must_equal nil }
25
+ it { primitive.to_json(false).must_equal false }
26
+ it { primitive.to_json(0).must_equal false }
27
+ it { primitive.to_json('').must_equal false }
28
+ it { primitive.to_json('false').must_equal false }
29
+ it { primitive.to_json(true).must_equal true }
30
+ it { primitive.to_json(1).must_equal true }
31
+ it { primitive.to_json('true').must_equal true }
32
+ end
33
+
21
34
  describe 'NumberType' do
22
35
  let(:primitive) { PushType::Primitives::NumberType }
23
36
  let(:val) { '123.45' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push_type_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Russell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 5.2.0
47
+ version: 6.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 5.2.0
54
+ version: 6.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: dragonfly
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -155,10 +155,10 @@ files:
155
155
  - app/controllers/nodes_front_end_controller.rb
156
156
  - app/controllers/taxonomies_front_end_controller.rb
157
157
  - app/fields/push_type/asset_field.rb
158
+ - app/fields/push_type/boolean_field.rb
158
159
  - app/fields/push_type/date_field.rb
159
160
  - app/fields/push_type/markdown_field.rb
160
161
  - app/fields/push_type/matrix_field.rb
161
- - app/fields/push_type/node_field.rb
162
162
  - app/fields/push_type/number_field.rb
163
163
  - app/fields/push_type/relation_field.rb
164
164
  - app/fields/push_type/repeater_field.rb
@@ -166,7 +166,6 @@ files:
166
166
  - app/fields/push_type/string_field.rb
167
167
  - app/fields/push_type/structure_field.rb
168
168
  - app/fields/push_type/tag_list_field.rb
169
- - app/fields/push_type/taxonomy_field.rb
170
169
  - app/fields/push_type/text_field.rb
171
170
  - app/fields/push_type/time_field.rb
172
171
  - app/helpers/push_type/application_helper.rb
@@ -219,6 +218,7 @@ files:
219
218
  - lib/push_type/config.rb
220
219
  - lib/push_type/core.rb
221
220
  - lib/push_type/core/engine.rb
221
+ - lib/push_type/core_ext/to_bool.rb
222
222
  - lib/push_type/field_type.rb
223
223
  - lib/push_type/menu_builder.rb
224
224
  - lib/push_type/menu_builder/dsl/menu.rb
@@ -230,6 +230,7 @@ files:
230
230
  - lib/push_type/presenter.rb
231
231
  - lib/push_type/primitives/array_type.rb
232
232
  - lib/push_type/primitives/base.rb
233
+ - lib/push_type/primitives/boolean_type.rb
233
234
  - lib/push_type/primitives/number_type.rb
234
235
  - lib/push_type/primitives/object_type.rb
235
236
  - lib/push_type/primitives/string_type.rb
@@ -279,13 +280,13 @@ files:
279
280
  - test/dummy/config/locales/en.yml
280
281
  - test/dummy/config/routes.rb
281
282
  - test/dummy/config/secrets.yml
282
- - test/dummy/db/migrate/20151108150752_create_push_type_users.push_type.rb
283
- - test/dummy/db/migrate/20151108150753_create_push_type_nodes.push_type.rb
284
- - test/dummy/db/migrate/20151108150754_create_push_type_node_hierarchies.push_type.rb
285
- - test/dummy/db/migrate/20151108150755_create_push_type_assets.push_type.rb
286
- - test/dummy/db/migrate/20151108150756_create_push_type_taxonomies.push_type.rb
287
- - test/dummy/db/migrate/20151108150757_create_push_type_taxonomy_hierarchies.push_type.rb
288
- - test/dummy/db/migrate/20151108150758_add_field_store_default_values.push_type.rb
283
+ - test/dummy/db/migrate/20160108132348_create_push_type_users.push_type.rb
284
+ - test/dummy/db/migrate/20160108132349_create_push_type_nodes.push_type.rb
285
+ - test/dummy/db/migrate/20160108132350_create_push_type_node_hierarchies.push_type.rb
286
+ - test/dummy/db/migrate/20160108132351_create_push_type_assets.push_type.rb
287
+ - test/dummy/db/migrate/20160108132352_create_push_type_taxonomies.push_type.rb
288
+ - test/dummy/db/migrate/20160108132353_create_push_type_taxonomy_hierarchies.push_type.rb
289
+ - test/dummy/db/migrate/20160108132354_add_field_store_default_values.push_type.rb
289
290
  - test/dummy/db/schema.rb
290
291
  - test/dummy/db/seeds.rb
291
292
  - test/dummy/log/test.log
@@ -297,18 +298,18 @@ files:
297
298
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/0ANSDcZJu9gPyqtYPIW729qm1kriQ29Vn9LU8T2SGQU.cache
298
299
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/3T6ioyhwSsEzte_a9viHBvfmuKgORQ019srIEoUYkVs.cache
299
300
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache
300
- - test/dummy/tmp/cache/assets/test/sprockets/v3.0/ICYfNnwyQOM4ypAd7cL9ig1weq-ynnC7JO__sNCZo98.cache
301
+ - test/dummy/tmp/cache/assets/test/sprockets/v3.0/8FGH_ku24FOYEa6ACm3vyk_rZwODpSzv3MjZU4irm7M.cache
301
302
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/IYzwMwq7DWWSuojH6oXsrP__pcD7O8TQieMFSzQiwnc.cache
302
303
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache
303
304
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/_d65qW7wxRtKVSYpmfSenECz5QUWVI9pppUgV7TA1Rk.cache
304
- - test/dummy/tmp/cache/assets/test/sprockets/v3.0/tlOpTnaa_t4XAbGrJuMXP6N7RwkbFqu0Q3NnnTJGR_o.cache
305
+ - test/dummy/tmp/cache/assets/test/sprockets/v3.0/o8jETQIOAUNl34ED3ZTGdlVAlYRSl8zt6mfx4Wr1_Hs.cache
305
306
  - test/dummy/tmp/generators/app/models/category.rb
306
307
  - test/dummy/tmp/generators/app/views/taxonomies/category.html.erb
307
308
  - test/fields/push_type/asset_field_test.rb
309
+ - test/fields/push_type/boolean_field_test.rb
308
310
  - test/fields/push_type/date_field_test.rb
309
311
  - test/fields/push_type/markdown_field_test.rb
310
312
  - test/fields/push_type/matrix_field_test.rb
311
- - test/fields/push_type/node_field_test.rb
312
313
  - test/fields/push_type/number_field_test.rb
313
314
  - test/fields/push_type/relation_field_test.rb
314
315
  - test/fields/push_type/repeater_field_test.rb
@@ -316,7 +317,6 @@ files:
316
317
  - test/fields/push_type/string_field_test.rb
317
318
  - test/fields/push_type/structure_field_test.rb
318
319
  - test/fields/push_type/tag_list_field_test.rb
319
- - test/fields/push_type/taxonomy_field_test.rb
320
320
  - test/fields/push_type/text_field_test.rb
321
321
  - test/fields/push_type/time_field_test.rb
322
322
  - test/files/audio.m3u
@@ -329,6 +329,7 @@ files:
329
329
  - test/lib/generators/push_type/presenter_generator_test.rb
330
330
  - test/lib/generators/push_type/structure_generator_test.rb
331
331
  - test/lib/generators/push_type/taxonomy_generator_test.rb
332
+ - test/lib/push_type/core_exts_test.rb
332
333
  - test/lib/push_type/core_test.rb
333
334
  - test/lib/push_type/field_type_test.rb
334
335
  - test/lib/push_type/menu_builder/menu_dsl_test.rb
@@ -366,9 +367,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
366
367
  version: '0'
367
368
  required_rubygems_version: !ruby/object:Gem::Requirement
368
369
  requirements:
369
- - - ">="
370
+ - - ">"
370
371
  - !ruby/object:Gem::Version
371
- version: '0'
372
+ version: 1.3.1
372
373
  requirements: []
373
374
  rubyforge_project:
374
375
  rubygems_version: 2.4.2
@@ -411,13 +412,13 @@ test_files:
411
412
  - test/dummy/config/routes.rb
412
413
  - test/dummy/config/secrets.yml
413
414
  - test/dummy/config.ru
414
- - test/dummy/db/migrate/20151108150752_create_push_type_users.push_type.rb
415
- - test/dummy/db/migrate/20151108150753_create_push_type_nodes.push_type.rb
416
- - test/dummy/db/migrate/20151108150754_create_push_type_node_hierarchies.push_type.rb
417
- - test/dummy/db/migrate/20151108150755_create_push_type_assets.push_type.rb
418
- - test/dummy/db/migrate/20151108150756_create_push_type_taxonomies.push_type.rb
419
- - test/dummy/db/migrate/20151108150757_create_push_type_taxonomy_hierarchies.push_type.rb
420
- - test/dummy/db/migrate/20151108150758_add_field_store_default_values.push_type.rb
415
+ - test/dummy/db/migrate/20160108132348_create_push_type_users.push_type.rb
416
+ - test/dummy/db/migrate/20160108132349_create_push_type_nodes.push_type.rb
417
+ - test/dummy/db/migrate/20160108132350_create_push_type_node_hierarchies.push_type.rb
418
+ - test/dummy/db/migrate/20160108132351_create_push_type_assets.push_type.rb
419
+ - test/dummy/db/migrate/20160108132352_create_push_type_taxonomies.push_type.rb
420
+ - test/dummy/db/migrate/20160108132353_create_push_type_taxonomy_hierarchies.push_type.rb
421
+ - test/dummy/db/migrate/20160108132354_add_field_store_default_values.push_type.rb
421
422
  - test/dummy/db/schema.rb
422
423
  - test/dummy/db/seeds.rb
423
424
  - test/dummy/log/test.log
@@ -431,18 +432,18 @@ test_files:
431
432
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/0ANSDcZJu9gPyqtYPIW729qm1kriQ29Vn9LU8T2SGQU.cache
432
433
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/3T6ioyhwSsEzte_a9viHBvfmuKgORQ019srIEoUYkVs.cache
433
434
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache
435
+ - test/dummy/tmp/cache/assets/test/sprockets/v3.0/8FGH_ku24FOYEa6ACm3vyk_rZwODpSzv3MjZU4irm7M.cache
434
436
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/_d65qW7wxRtKVSYpmfSenECz5QUWVI9pppUgV7TA1Rk.cache
435
- - test/dummy/tmp/cache/assets/test/sprockets/v3.0/ICYfNnwyQOM4ypAd7cL9ig1weq-ynnC7JO__sNCZo98.cache
436
437
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/IYzwMwq7DWWSuojH6oXsrP__pcD7O8TQieMFSzQiwnc.cache
438
+ - test/dummy/tmp/cache/assets/test/sprockets/v3.0/o8jETQIOAUNl34ED3ZTGdlVAlYRSl8zt6mfx4Wr1_Hs.cache
437
439
  - test/dummy/tmp/cache/assets/test/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache
438
- - test/dummy/tmp/cache/assets/test/sprockets/v3.0/tlOpTnaa_t4XAbGrJuMXP6N7RwkbFqu0Q3NnnTJGR_o.cache
439
440
  - test/dummy/tmp/generators/app/models/category.rb
440
441
  - test/dummy/tmp/generators/app/views/taxonomies/category.html.erb
441
442
  - test/fields/push_type/asset_field_test.rb
443
+ - test/fields/push_type/boolean_field_test.rb
442
444
  - test/fields/push_type/date_field_test.rb
443
445
  - test/fields/push_type/markdown_field_test.rb
444
446
  - test/fields/push_type/matrix_field_test.rb
445
- - test/fields/push_type/node_field_test.rb
446
447
  - test/fields/push_type/number_field_test.rb
447
448
  - test/fields/push_type/relation_field_test.rb
448
449
  - test/fields/push_type/repeater_field_test.rb
@@ -450,7 +451,6 @@ test_files:
450
451
  - test/fields/push_type/string_field_test.rb
451
452
  - test/fields/push_type/structure_field_test.rb
452
453
  - test/fields/push_type/tag_list_field_test.rb
453
- - test/fields/push_type/taxonomy_field_test.rb
454
454
  - test/fields/push_type/text_field_test.rb
455
455
  - test/fields/push_type/time_field_test.rb
456
456
  - test/files/audio.m3u
@@ -463,6 +463,7 @@ test_files:
463
463
  - test/lib/generators/push_type/presenter_generator_test.rb
464
464
  - test/lib/generators/push_type/structure_generator_test.rb
465
465
  - test/lib/generators/push_type/taxonomy_generator_test.rb
466
+ - test/lib/push_type/core_exts_test.rb
466
467
  - test/lib/push_type/core_test.rb
467
468
  - test/lib/push_type/field_type_test.rb
468
469
  - test/lib/push_type/menu_builder/menu_dsl_test.rb
@@ -1,27 +0,0 @@
1
- module PushType
2
- class NodeField < RelationField
3
-
4
- options template: 'relation', root: '/'
5
-
6
- def relation_class
7
- super
8
- rescue NameError
9
- PushType::Node
10
- end
11
-
12
- def relation_root
13
- root = relation_class.not_trash
14
- root = root.find_by_path(@opts[:root].split('/')) unless @opts[:root] == '/'
15
- root or raise "Cannot find root node at path '#{ @opts[:root] }'"
16
- end
17
-
18
- on_instance do |object, field|
19
- object.class_eval do
20
- define_method(field.relation_name.to_sym) do
21
- field.relation_class.not_trash.find field.json_value unless field.json_value.blank?
22
- end unless method_defined?(field.relation_name.to_sym)
23
- end
24
- end
25
-
26
- end
27
- end
@@ -1,21 +0,0 @@
1
- module PushType
2
- class TaxonomyField < RelationField
3
-
4
- options template: 'relation'
5
-
6
- def relation_class
7
- super
8
- rescue NameError
9
- PushType::Taxonomy
10
- end
11
-
12
- on_instance do |object, field|
13
- object.class_eval do
14
- define_method(field.relation_name.to_sym) do
15
- field.relation_class.find field.json_value unless field.json_value.blank?
16
- end unless method_defined?(field.relation_name.to_sym)
17
- end
18
- end
19
-
20
- end
21
- end
@@ -1,48 +0,0 @@
1
- require 'test_helper'
2
-
3
- module PushType
4
- class NodeFieldTest < ActiveSupport::TestCase
5
-
6
- class TestPage < PushType::Node
7
- field :page_id, :node
8
- field :bar_ids, :node, multiple: true, to: 'page', root: 'foo-bar'
9
- end
10
-
11
- before do
12
- root = Page.create FactoryGirl.attributes_for(:node, slug: 'foo-bar')
13
- @pages = 4.times.map { Page.create FactoryGirl.attributes_for(:node) }
14
- @bars = 2.times.map { Page.create FactoryGirl.attributes_for(:node, parent_id: root.id) }
15
- end
16
-
17
- let(:node) { TestPage.create FactoryGirl.attributes_for(:node, page_id: rel.id, bar_ids: @bars.map(&:id)) }
18
- let(:rel) { @pages.first }
19
- let(:foo) { node.fields[:page_id] }
20
- let(:bar) { node.fields[:bar_ids] }
21
-
22
- it { foo.json_primitive.must_equal :string }
23
- it { foo.template.must_equal 'relation' }
24
- it { foo.wont_be :multiple? }
25
- it { foo.label.must_equal 'Page' }
26
- it { foo.html_options.keys.must_include :multiple }
27
- it { foo.json_value.must_equal rel.id }
28
- it { foo.value.must_equal rel.id }
29
- it { foo.choices.size.must_equal 7 }
30
- it { foo.choices.map { |c| c[:value] }.must_include rel.id }
31
- it { foo.relation_name.must_equal 'page' }
32
- it { foo.relation_class.must_equal Page }
33
-
34
- it { bar.json_primitive.must_equal :array }
35
- it { bar.must_be :multiple? }
36
- it { bar.label.must_equal 'Bars' }
37
- it { bar.json_value.must_equal @bars.map(&:id) }
38
- it { bar.value.must_equal @bars.map(&:id) }
39
- it { bar.choices.size.must_equal 3 }
40
- it { bar.relation_name.must_equal 'bars' }
41
-
42
- it { node.page_id.must_equal rel.id }
43
- it { node.page.must_equal rel }
44
- it { node.bar_ids.must_equal @bars.map(&:id) }
45
- it { node.bars.sort.must_equal @bars.sort }
46
-
47
- end
48
- end