push_type_core 0.5.0.alpha.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/fields/push_type/asset_field.rb +5 -1
- data/app/fields/push_type/markdown_field.rb +2 -5
- data/app/fields/push_type/matrix_field.rb +1 -1
- data/app/fields/push_type/node_field.rb +9 -2
- data/app/fields/push_type/repeater_field.rb +1 -1
- data/app/fields/push_type/taxonomy_field.rb +4 -2
- data/lib/push_type/fields/relations.rb +3 -3
- data/lib/push_type/version.rb +1 -1
- data/test/dummy/config/initializers/push_type.rb +1 -1
- data/test/dummy/config/secrets.yml +2 -2
- data/test/dummy/db/schema.rb +1 -1
- data/test/dummy/log/test.log +7124 -2620
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{YfvOcAtfd0a4AoZRwhfEPbutzGvytNV3PLH99tHHVec.cache → M0EVptJKeB1GMjwoMb3w3mgp8VB55MSbItnFhItY4hA.cache} +1 -1
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{-Sjd8yE8radAZWLZz1Hn9eTc5vPZke6_-U1eg-KNjy8.cache → g97nJc5YmnbscVR5pZZoxgfj652ml7dLjUIu0FHDwLA.cache} +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/utXmZy0kE8zUnHIqwtbjUUJlYlFcGDJreK2YPDuR3n8.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{RwmiAHIoiRN917L4TQ8saQaj1DsQgMpS97RYvkK2D5M.cache → vlJujjzOikOTUvCvT3C4o3vK0ySfxbQQ3RBE37vXH0U.cache} +0 -0
- data/test/dummy/tmp/generators/config/initializers/push_type.rb +38 -0
- data/test/dummy/tmp/generators/config/routes.rb +59 -0
- data/test/fields/push_type/asset_field_test.rb +37 -0
- data/test/fields/push_type/date_field_test.rb +14 -0
- data/test/fields/push_type/markdown_field_test.rb +35 -0
- data/test/fields/push_type/matrix_field_test.rb +35 -0
- data/test/fields/push_type/node_field_test.rb +71 -0
- data/test/fields/push_type/number_field_test.rb +13 -0
- data/test/fields/push_type/repeater_field_test.rb +21 -0
- data/test/fields/push_type/select_field_test.rb +40 -0
- data/test/fields/push_type/tag_list_field_test.rb +33 -0
- data/test/fields/push_type/taxonomy_field_test.rb +57 -0
- data/test/fields/push_type/text_field_test.rb +12 -0
- data/test/fields/push_type/time_field_test.rb +15 -0
- data/test/lib/push_type/field_type_test.rb +1 -57
- data/test/test_helper.rb +11 -1
- metadata +66 -42
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/H3MYWnNh74SPmIVutQpgqiLFgQBaPIZ8rUXz8S1IXfQ.cache +0 -1
- data/test/dummy/tmp/generators/app/models/category.rb +0 -6
- data/test/dummy/tmp/generators/app/views/taxonomies/category.html.erb +0 -3
- /data/test/dummy/db/migrate/{20150601132816_create_push_type_users.push_type.rb → 20150716155017_create_push_type_users.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150601132817_create_push_type_nodes.push_type.rb → 20150716155018_create_push_type_nodes.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150601132818_create_push_type_node_hierarchies.push_type.rb → 20150716155019_create_push_type_node_hierarchies.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150601132819_create_push_type_assets.push_type.rb → 20150716155020_create_push_type_assets.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150601132820_create_push_type_taxonomies.push_type.rb → 20150716155021_create_push_type_taxonomies.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150601132821_create_push_type_taxonomy_hierarchies.push_type.rb → 20150716155022_create_push_type_taxonomy_hierarchies.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150601132822_add_field_store_default_values.push_type.rb → 20150716155023_add_field_store_default_values.push_type.rb} +0 -0
- /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{H_FtcM4uZms6K7jOADXRW2-Q5luNbbboPJ8haQyA17A.cache → 0tutfZEltPbqMrjMJpcgLOWDEBEA1_i4wAlgfGmDMaM.cache} +0 -0
- /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{0_aw7up97T_NTvobuzf-o1Xpynz3Eqo7lyRTdE_M3kg.cache → 5hBD45unr3-A8x6pxXjxq708mnY9gJisy1yA5AojZWQ.cache} +0 -0
- /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{khjpnuHaHw24GnTbWlsRS6uIuTqIkrfvc2dY1aZWtpk.cache → DIGO2XX0gV_Ebgs43ap-65y0MyrcySF3iz56xum2NCQ.cache} +0 -0
- /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{I6zXuKkTIFbRK1A1tWK7nMeIhOXwx4iMRyZCdQatqy8.cache → MSjNaQjz3SH1LnDyk7nWta_i3hcCEV9m1eoNFbOXjwI.cache} +0 -0
@@ -1 +1 @@
|
|
1
|
-
I"�file:///Users/aaron/dev/pushcode/push_type/core/test/dummy/app/assets/stylesheets/application.css?type=text/css&pipeline=self&id=
|
1
|
+
I"�file:///Users/aaron/dev/pushcode/push_type/core/test/dummy/app/assets/stylesheets/application.css?type=text/css&pipeline=self&id=dd9845a69e14ddf1cc779356fbe38875287187ccde43267244bf86d041699216:ET
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�file:///Users/aaron/dev/pushcode/push_type/core/test/dummy/app/assets/stylesheets/application.css?type=text/css&id=eb2a858f510f9634745bbb208e039743b45481e89c40e4100d6d48f1caeb3836:ET
|
Binary file
|
@@ -0,0 +1,38 @@
|
|
1
|
+
PushType.setup do |config|
|
2
|
+
|
3
|
+
config.root_nodes = :all
|
4
|
+
|
5
|
+
config.unexposed_nodes = []
|
6
|
+
|
7
|
+
config.home_slug = 'home'
|
8
|
+
|
9
|
+
config.unexposed_taxonomies = []
|
10
|
+
|
11
|
+
config.media_styles = {
|
12
|
+
large: '1024x1024>',
|
13
|
+
medium: '512x512>',
|
14
|
+
small: '256x256>'
|
15
|
+
}
|
16
|
+
|
17
|
+
# Configure the default mailer "from" address
|
18
|
+
config.mailer_sender = 'pushtype@example.com'
|
19
|
+
|
20
|
+
# Dragonfly datastore configuration
|
21
|
+
config.dragonfly_datastore = :file
|
22
|
+
config.dragonfly_datastore_options = {
|
23
|
+
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
|
24
|
+
server_root: Rails.root.join('public')
|
25
|
+
}
|
26
|
+
|
27
|
+
# For S3 storage, remember to add to Gemfile:
|
28
|
+
# gem 'dragonfly-s3_data_store'
|
29
|
+
# config.dragonfly_datastore = :s3
|
30
|
+
# config.dragonfly_datastore_options = {
|
31
|
+
# bucket_name: ENV['S3_BUCKET'],
|
32
|
+
# access_key_id: ENV['S3_ACCESS_KEY_ID'],
|
33
|
+
# secret_access_key: ENV['SECRET_ACCESS_KEY_ID']
|
34
|
+
# }
|
35
|
+
|
36
|
+
# config.dragonfly_secret = '44e1892734ed4d66cc27a4d83f3e09807491a01759063549073bacb407bf3af6'
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
mount_push_type
|
4
|
+
|
5
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
6
|
+
# See how all your routes lay out with "rake routes".
|
7
|
+
|
8
|
+
# You can have the root of your site routed with "root"
|
9
|
+
# root 'welcome#index'
|
10
|
+
|
11
|
+
# Example of regular route:
|
12
|
+
# get 'products/:id' => 'catalog#view'
|
13
|
+
|
14
|
+
# Example of named route that can be invoked with purchase_url(id: product.id)
|
15
|
+
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
16
|
+
|
17
|
+
# Example resource route (maps HTTP verbs to controller actions automatically):
|
18
|
+
# resources :products
|
19
|
+
|
20
|
+
# Example resource route with options:
|
21
|
+
# resources :products do
|
22
|
+
# member do
|
23
|
+
# get 'short'
|
24
|
+
# post 'toggle'
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# collection do
|
28
|
+
# get 'sold'
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Example resource route with sub-resources:
|
33
|
+
# resources :products do
|
34
|
+
# resources :comments, :sales
|
35
|
+
# resource :seller
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Example resource route with more complex sub-resources:
|
39
|
+
# resources :products do
|
40
|
+
# resources :comments
|
41
|
+
# resources :sales do
|
42
|
+
# get 'recent', on: :collection
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# Example resource route with concerns:
|
47
|
+
# concern :toggleable do
|
48
|
+
# post 'toggle'
|
49
|
+
# end
|
50
|
+
# resources :posts, concerns: :toggleable
|
51
|
+
# resources :photos, concerns: :toggleable
|
52
|
+
|
53
|
+
# Example resource route within a namespace:
|
54
|
+
# namespace :admin do
|
55
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
56
|
+
# # (app/controllers/admin/products_controller.rb)
|
57
|
+
# resources :products
|
58
|
+
# end
|
59
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe AssetField do
|
6
|
+
let(:field) { PushType::AssetField.new :foo }
|
7
|
+
|
8
|
+
it { field.json_key.must_equal :foo_id }
|
9
|
+
it { field.template.must_equal 'asset' }
|
10
|
+
it { field.id_attr.must_equal 'foo-asset-modal' }
|
11
|
+
it { field.relation_class.must_equal PushType::Asset }
|
12
|
+
|
13
|
+
describe 'initialized on node' do
|
14
|
+
before do
|
15
|
+
TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
16
|
+
TestPage.field :foo, :asset
|
17
|
+
end
|
18
|
+
after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
19
|
+
|
20
|
+
let(:node) { TestPage.create attrs }
|
21
|
+
let(:attrs) { FactoryGirl.attributes_for(:node) }
|
22
|
+
|
23
|
+
describe 'without asset' do
|
24
|
+
it { node.foo_id.must_be_nil }
|
25
|
+
it { node.foo.must_be_nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'with asset' do
|
29
|
+
let(:attrs) { FactoryGirl.attributes_for(:node).merge(foo_id: asset.id) }
|
30
|
+
let(:asset) { FactoryGirl.create :asset }
|
31
|
+
it { node.foo_id.must_equal asset.id }
|
32
|
+
it { node.foo.must_equal asset }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe DateField do
|
6
|
+
let(:field) { PushType::DateField.new :foo }
|
7
|
+
let(:val) { Date.today.to_s }
|
8
|
+
|
9
|
+
it { field.template.must_equal 'date' }
|
10
|
+
it { field.form_helper.must_equal :date_field }
|
11
|
+
it { field.from_json(val).must_be_instance_of Date }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe MarkdownField do
|
6
|
+
let(:field) { PushType::MarkdownField.new :foo }
|
7
|
+
|
8
|
+
it { field.form_helper.must_equal :text_area }
|
9
|
+
it { field.markdown.must_be_instance_of Redcarpet::Markdown }
|
10
|
+
|
11
|
+
describe 'initialized on node' do
|
12
|
+
before do
|
13
|
+
TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
14
|
+
TestPage.field :foo, :markdown
|
15
|
+
end
|
16
|
+
after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
17
|
+
|
18
|
+
let(:node) { TestPage.create attrs }
|
19
|
+
let(:attrs) { FactoryGirl.attributes_for(:node) }
|
20
|
+
|
21
|
+
describe 'without content' do
|
22
|
+
it { node.foo.must_be_nil }
|
23
|
+
it { node.present!.foo.must_be_nil }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'with content' do
|
27
|
+
let(:attrs) { FactoryGirl.attributes_for(:node).merge(foo: md) }
|
28
|
+
let(:md) { '**foo** *bar*' }
|
29
|
+
it { node.foo.must_equal md }
|
30
|
+
it { node.present!.foo.strip.must_equal '<p><strong>foo</strong> <em>bar</em></p>' }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe MatrixField do
|
6
|
+
let(:field) { PushType::MatrixField.new :foo, opts }
|
7
|
+
let(:val) { [{ key: 1, value: 2 }, { key: 3, value: 4 }] }
|
8
|
+
|
9
|
+
describe 'default' do
|
10
|
+
let(:opts) { {} }
|
11
|
+
it { field.template.must_equal 'matrix' }
|
12
|
+
it { field.multiple?.must_equal true }
|
13
|
+
it { field.param.must_equal foo: [:key, :value] }
|
14
|
+
it { field.mapping.must_equal key: :text_field, value: :text_field }
|
15
|
+
it { field.struct.must_be_instance_of Class }
|
16
|
+
it { field.to_json(val).must_be_instance_of Array }
|
17
|
+
it { field.to_json(val)[0].must_be_instance_of Hash }
|
18
|
+
it { field.from_json(val).must_be_instance_of Array }
|
19
|
+
it { field.from_json(val)[0].must_be_kind_of Object }
|
20
|
+
it { field.from_json(val)[0].key.must_equal 1 }
|
21
|
+
it { field.from_json(val)[0].value.must_equal 2 }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'with options' do
|
25
|
+
let(:opts) { { mapping: [:this, :that, other: :number_field] } }
|
26
|
+
let(:val) { [{ this: 'a', that: 'b', other: '99' }] }
|
27
|
+
|
28
|
+
it { field.mapping.must_equal this: :text_field, that: :text_field, other: :number_field }
|
29
|
+
it { field.from_json(val)[0].this.must_equal 'a' }
|
30
|
+
it { field.from_json(val)[0].that.must_equal 'b' }
|
31
|
+
it { field.from_json(val)[0].other.must_equal '99' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe NodeField do
|
6
|
+
let(:field) { PushType::NodeField.new :foo, opts }
|
7
|
+
|
8
|
+
before do
|
9
|
+
home = TestPage.create FactoryGirl.attributes_for(:node, slug: 'home')
|
10
|
+
TestPage.create FactoryGirl.attributes_for(:node, slug: 'child', parent: home)
|
11
|
+
Page.create FactoryGirl.attributes_for(:node)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'default' do
|
15
|
+
let(:opts) { {} }
|
16
|
+
it { field.json_key.must_equal :foo_id }
|
17
|
+
it { field.field_options.must_equal({}) }
|
18
|
+
it { field.relation_class.must_equal PushType::Node }
|
19
|
+
it { field.relation_root.must_be_instance_of PushType::Node::ActiveRecord_Relation }
|
20
|
+
it { field.relation_tree.size.must_equal 3 }
|
21
|
+
it { field.relation_tree.map { |t| t[:depth] }.max.must_equal 1 }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'with class option' do
|
25
|
+
let(:opts) { { class: :page } }
|
26
|
+
it { field.relation_class.must_equal Page }
|
27
|
+
it { field.relation_root.must_be_instance_of Page::ActiveRecord_Relation }
|
28
|
+
it { field.relation_tree.size.must_equal 1 }
|
29
|
+
it { field.relation_tree.map { |t| t[:depth] }.max.must_equal 0 }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'with named field' do
|
33
|
+
let(:field) { PushType::NodeField.new :test_page }
|
34
|
+
it { field.relation_class.must_equal TestPage }
|
35
|
+
it { field.relation_root.must_be_instance_of TestPage::ActiveRecord_Relation }
|
36
|
+
it { field.relation_tree.size.must_equal 2 }
|
37
|
+
it { field.relation_tree.map { |t| t[:depth] }.max.must_equal 1 }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'with root option' do
|
41
|
+
let(:opts) { { root: 'home/child' } }
|
42
|
+
it { field.relation_root.must_be_instance_of TestPage }
|
43
|
+
it { field.relation_tree.size.must_equal 1 }
|
44
|
+
it { field.relation_tree.map { |t| t[:depth] }.max.must_equal 0 }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'initialized on node' do
|
48
|
+
before do
|
49
|
+
TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
50
|
+
TestPage.field :foo, :node
|
51
|
+
end
|
52
|
+
after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
53
|
+
|
54
|
+
let(:node) { TestPage.create attrs }
|
55
|
+
let(:attrs) { FactoryGirl.attributes_for(:node) }
|
56
|
+
|
57
|
+
describe 'without relation' do
|
58
|
+
it { node.foo_id.must_be_nil }
|
59
|
+
it { node.foo.must_be_nil }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'with relation' do
|
63
|
+
let(:attrs) { FactoryGirl.attributes_for(:node).merge(foo_id: rel.id) }
|
64
|
+
let(:rel) { FactoryGirl.create :node }
|
65
|
+
it { node.foo_id.must_equal rel.id }
|
66
|
+
it { node.foo.must_equal rel }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe NumberField do
|
6
|
+
let(:field) { PushType::NumberField.new :foo }
|
7
|
+
|
8
|
+
it { field.form_helper.must_equal :number_field }
|
9
|
+
it { field.to_json(1).must_equal 1 }
|
10
|
+
it { field.to_json('1').must_equal 1 }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe RepeaterField do
|
6
|
+
let(:field) { PushType::RepeaterField.new :foo }
|
7
|
+
let(:val) { ['a', 'b', 'c'] }
|
8
|
+
|
9
|
+
describe 'default' do
|
10
|
+
it { field.template.must_equal 'repeater' }
|
11
|
+
it { field.multiple?.must_equal true }
|
12
|
+
it { field.param.must_equal foo: [] }
|
13
|
+
it { field.to_json(val).must_be_instance_of Array }
|
14
|
+
it { field.to_json(val)[0].must_equal 'a' }
|
15
|
+
it { field.from_json(val).must_be_instance_of Array }
|
16
|
+
it { field.from_json(val)[0].must_equal 'a' }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe SelectField do
|
6
|
+
let(:field) { PushType::SelectField.new :foo, opts }
|
7
|
+
let(:val) { 'a' }
|
8
|
+
|
9
|
+
describe 'default' do
|
10
|
+
let(:opts) { {} }
|
11
|
+
it { field.template.must_equal 'select' }
|
12
|
+
it { field.multiple?.must_equal false }
|
13
|
+
it { field.param.must_equal :foo }
|
14
|
+
it { field.choices.must_equal [] }
|
15
|
+
it { field.field_options.must_be_instance_of Hash }
|
16
|
+
it { field.field_options.keys.must_include :include_blank }
|
17
|
+
it { field.html_options.keys.must_include :multiple }
|
18
|
+
it { field.to_json(val).must_equal val }
|
19
|
+
it { field.from_json(val).must_equal val }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with options' do
|
23
|
+
let(:opts) { { choices: ['a', 'b'], multiple: true } }
|
24
|
+
let(:val) { ['a', 'b'] }
|
25
|
+
it { field.multiple?.must_equal true }
|
26
|
+
it { field.choices.must_equal ['a', 'b'] }
|
27
|
+
it { field.to_json(val).must_be_instance_of Array }
|
28
|
+
it { field.to_json(val)[0].must_equal 'a' }
|
29
|
+
it { field.from_json(val).must_be_instance_of Array }
|
30
|
+
it { field.from_json(val)[0].must_equal 'a' }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'with choices as proc' do
|
34
|
+
let(:opts) { { choices: -> { [1,2,3] } } }
|
35
|
+
it { field.choices.must_equal [1,2,3] }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe TagListField do
|
6
|
+
let(:field) { PushType::TagListField.new :tags, opts }
|
7
|
+
let(:val) { ['foo', 'bar'] }
|
8
|
+
|
9
|
+
describe 'default' do
|
10
|
+
let(:opts) { {} }
|
11
|
+
it { field.template.must_equal 'tag_list' }
|
12
|
+
it { field.multiple?.must_equal true }
|
13
|
+
it { field.param.must_equal tags: [] }
|
14
|
+
it { field.html_options.keys.must_include :multiple }
|
15
|
+
it { field.html_options.keys.must_include :placeholder }
|
16
|
+
it { field.to_json(val + ['']).must_equal val }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'initialized on node' do
|
20
|
+
before do
|
21
|
+
TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
22
|
+
TestPage.field :tags, :tag_list
|
23
|
+
TestPage.create FactoryGirl.attributes_for(:node, tags: ['foo', 'bar'])
|
24
|
+
TestPage.create FactoryGirl.attributes_for(:node, tags: ['baz', 'bar'])
|
25
|
+
TestPage.create FactoryGirl.attributes_for(:node, tags: ['qux'])
|
26
|
+
end
|
27
|
+
after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
28
|
+
it { TestPage.must_respond_to :all_tags }
|
29
|
+
it { TestPage.all_tags.must_equal ['bar', 'baz', 'foo', 'qux'] }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe TaxonomyField do
|
6
|
+
let(:field) { PushType::TaxonomyField.new :foo, opts }
|
7
|
+
|
8
|
+
before do
|
9
|
+
root = Category.create FactoryGirl.attributes_for(:taxonomy)
|
10
|
+
Category.create FactoryGirl.attributes_for(:taxonomy, parent: root)
|
11
|
+
Category.create FactoryGirl.attributes_for(:taxonomy)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'default' do
|
15
|
+
let(:opts) { {} }
|
16
|
+
it { field.json_key.must_equal :foo_id }
|
17
|
+
it { field.field_options.must_equal({}) }
|
18
|
+
it { field.relation_class.must_equal PushType::Taxonomy }
|
19
|
+
it { field.relation_tree.size.must_equal 3 }
|
20
|
+
it { field.relation_tree.map { |t| t[:depth] }.max.must_equal 1 }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'with class option' do
|
24
|
+
let(:opts) { { class: :category } }
|
25
|
+
it { field.relation_class.must_equal Category }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'with named field' do
|
29
|
+
let(:field) { PushType::TaxonomyField.new :category }
|
30
|
+
it { field.relation_class.must_equal Category }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'initialized on node' do
|
34
|
+
before do
|
35
|
+
TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
36
|
+
TestPage.field :foo, :taxonomy
|
37
|
+
end
|
38
|
+
after { TestPage.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
39
|
+
|
40
|
+
let(:node) { TestPage.create attrs }
|
41
|
+
let(:attrs) { FactoryGirl.attributes_for(:node) }
|
42
|
+
|
43
|
+
describe 'without taxonomy' do
|
44
|
+
it { node.foo_id.must_be_nil }
|
45
|
+
it { node.foo.must_be_nil }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'with taxonomy' do
|
49
|
+
let(:attrs) { FactoryGirl.attributes_for(:node).merge(foo_id: taxonomy.id) }
|
50
|
+
let(:taxonomy) { FactoryGirl.create :taxonomy }
|
51
|
+
it { node.foo_id.must_equal taxonomy.id }
|
52
|
+
it { node.foo.must_equal taxonomy }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module PushType
|
4
|
+
|
5
|
+
describe TimeField do
|
6
|
+
let(:field) { PushType::TimeField.new :foo }
|
7
|
+
let(:val) { '15:00' }
|
8
|
+
|
9
|
+
it { field.template.must_equal 'date' }
|
10
|
+
it { field.form_helper.must_equal :time_field }
|
11
|
+
it { field.from_json(val).must_be_instance_of Time }
|
12
|
+
it { field.from_json(val).hour.must_equal 15 }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -11,6 +11,7 @@ module PushType
|
|
11
11
|
it { field.name.must_equal 'foo' }
|
12
12
|
it { field.param.must_equal :foo }
|
13
13
|
it { field.kind.must_equal 'field' }
|
14
|
+
it { field.json_key.must_equal :foo }
|
14
15
|
it { field.template.must_equal 'default' }
|
15
16
|
it { field.label.must_equal 'Foo' }
|
16
17
|
it { field.html_options.must_equal({}) }
|
@@ -22,68 +23,11 @@ module PushType
|
|
22
23
|
|
23
24
|
describe 'with options' do
|
24
25
|
let(:opts) { { template: 'my_template', label: 'Bar', html_options: { some: 'opts' }, form_helper: :number_field, colspan: 2 } }
|
25
|
-
it { field.name.must_equal 'foo' }
|
26
|
-
it { field.kind.must_equal 'field' }
|
27
26
|
it { field.template.must_equal opts[:template] }
|
28
27
|
it { field.label.must_equal opts[:label] }
|
29
28
|
it { field.html_options.must_equal opts[:html_options] }
|
30
29
|
it { field.form_helper.must_equal opts[:form_helper] }
|
31
30
|
it { field.column_class.must_equal 'medium-6' }
|
32
|
-
it { field.to_json(val).must_equal '1' }
|
33
|
-
it { field.from_json(val).must_equal '1' }
|
34
|
-
end
|
35
|
-
|
36
|
-
describe DateField do
|
37
|
-
let(:field) { PushType::DateField.new :foo }
|
38
|
-
let(:val) { Date.today.to_s }
|
39
|
-
it { field.form_helper.must_equal :date_field }
|
40
|
-
it { field.from_json(val).must_be_instance_of Date }
|
41
|
-
end
|
42
|
-
|
43
|
-
describe NumberField do
|
44
|
-
let(:field) { PushType::NumberField.new :foo }
|
45
|
-
it { field.form_helper.must_equal :number_field }
|
46
|
-
it { field.to_json(val).must_equal 1 }
|
47
|
-
end
|
48
|
-
|
49
|
-
describe TextField do
|
50
|
-
let(:field) { PushType::TextField.new :foo }
|
51
|
-
it { field.form_helper.must_equal :text_area }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe MarkdownField do
|
55
|
-
let(:field) { PushType::MarkdownField.new :foo }
|
56
|
-
it { field.form_helper.must_equal :text_area }
|
57
|
-
it { field.markdown.must_be_instance_of Redcarpet::Markdown }
|
58
|
-
|
59
|
-
describe 'dynamic methods' do
|
60
|
-
before do
|
61
|
-
DatabaseCleaner.clean_with :truncation
|
62
|
-
Page.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
63
|
-
Page.field :body, :markdown
|
64
|
-
end
|
65
|
-
after { Page.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
66
|
-
let(:page) { Page.create FactoryGirl.attributes_for(:node, body: '**foo** *bar*') }
|
67
|
-
it { page.present!.body.strip.must_equal '<p><strong>foo</strong> <em>bar</em></p>' }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe TagListField do
|
72
|
-
let(:field) { PushType::TagListField.new :foo }
|
73
|
-
it { field.template.must_equal 'tag_list' }
|
74
|
-
it { field.html_options[:multiple].must_equal true }
|
75
|
-
it { field.html_options[:placeholder].must_equal 'Tags...' }
|
76
|
-
|
77
|
-
describe 'dynamic methods' do
|
78
|
-
before do
|
79
|
-
DatabaseCleaner.clean_with :truncation
|
80
|
-
Page.instance_variable_set '@fields', ActiveSupport::OrderedHash.new
|
81
|
-
Page.field :tags, :tag_list
|
82
|
-
Page.create FactoryGirl.attributes_for(:node, tags: ['foo', 'bar'])
|
83
|
-
end
|
84
|
-
after { Page.instance_variable_set '@fields', ActiveSupport::OrderedHash.new }
|
85
|
-
it { Page.all_tags.must_equal ['bar', 'foo'] }
|
86
|
-
end
|
87
31
|
end
|
88
32
|
|
89
33
|
end
|
data/test/test_helper.rb
CHANGED
@@ -19,4 +19,14 @@ require 'push_type/testing/factories'
|
|
19
19
|
# Load support files
|
20
20
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
21
21
|
|
22
|
-
DatabaseCleaner.strategy = :deletion
|
22
|
+
DatabaseCleaner.strategy = :deletion
|
23
|
+
|
24
|
+
class Minitest::Spec
|
25
|
+
before :each do
|
26
|
+
DatabaseCleaner.start
|
27
|
+
end
|
28
|
+
|
29
|
+
after :each do
|
30
|
+
DatabaseCleaner.clean
|
31
|
+
end
|
32
|
+
end
|