activeadmin-magicfields 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/Gemfile +42 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.md +160 -0
- data/Rakefile +33 -0
- data/activeadmin-magicfields.gemspec +23 -0
- data/app/assets/javascripts/activeadmin-magicfields.js.coffee +101 -0
- data/app/assets/stylesheets/activeadmin-magicfields.css.scss +53 -0
- data/lib/activeadmin-magicfields.rb +18 -0
- data/lib/activeadmin-magicfields/engine.rb +12 -0
- data/lib/activeadmin-magicfields/form_builder.rb +175 -0
- data/lib/activeadmin-magicfields/paperclip.rb +2 -0
- data/lib/activeadmin-magicfields/version.rb +3 -0
- data/lib/app/admin/part.rb +29 -0
- data/lib/app/admin/part_object.rb +26 -0
- data/lib/app/models/field/checkbox.rb +12 -0
- data/lib/app/models/field/image.rb +35 -0
- data/lib/app/models/field/repeater.rb +19 -0
- data/lib/app/models/field/text.rb +14 -0
- data/lib/app/models/field/textarea.rb +14 -0
- data/lib/app/models/field_template.rb +5 -0
- data/lib/app/models/part.rb +6 -0
- data/lib/app/models/part_object.rb +11 -0
- data/lib/app/models/part_object_field.rb +13 -0
- data/lib/app/models/repeater_part_object.rb +6 -0
- data/lib/app/views/admin/field_inputs/_checkbox.html.erb +1 -0
- data/lib/app/views/admin/field_inputs/_image.html.erb +4 -0
- data/lib/app/views/admin/field_inputs/_product.html.erb +1 -0
- data/lib/app/views/admin/field_inputs/_repeater.html.erb +3 -0
- data/lib/app/views/admin/field_inputs/_site_page.html.erb +1 -0
- data/lib/app/views/admin/field_inputs/_text.html.erb +1 -0
- data/lib/app/views/admin/field_inputs/_textarea.html.erb +8 -0
- data/lib/app/views/admin/part_objects/_part_object.html.erb +53 -0
- data/lib/app/views/admin/parts/_part.html.erb +11 -0
- data/lib/app/views/admin/parts/_part_old.arb +32 -0
- data/lib/generators/activeadmin-magicfields/install/install_generator.rb +33 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_field_checkbox.rb +10 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_field_image.rb +10 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_field_repeater.rb +9 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_field_templates.rb +14 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_field_text.rb +10 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_field_textarea.rb +12 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_part_object_fields.rb +10 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_part_objects.rb +13 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_parts.rb +9 -0
- data/lib/generators/activeadmin-magicfields/install/templates/create_repeater_part_objects.rb +10 -0
- data/spec/rails_helper.rb +154 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/deferred_garbage_collection.rb +19 -0
- data/spec/support/detect_rails_version.rb +26 -0
- data/spec/support/integration_example_group.rb +31 -0
- data/spec/support/jslint.yml +80 -0
- data/spec/support/rails_template.rb +104 -0
- data/spec/support/rails_template_with_data.rb +59 -0
- data/spec/support/templates/cucumber.rb +24 -0
- data/spec/support/templates/cucumber_with_reloading.rb +5 -0
- data/spec/support/templates/en.yml +8 -0
- data/spec/support/templates/policies/active_admin/comment_policy.rb +9 -0
- data/spec/support/templates/policies/active_admin/page_policy.rb +18 -0
- data/spec/support/templates/policies/application_policy.rb +45 -0
- data/spec/support/templates/policies/category_policy.rb +7 -0
- data/spec/support/templates/policies/post_policy.rb +15 -0
- data/spec/support/templates/policies/store_policy.rb +11 -0
- data/spec/support/templates/policies/user_policy.rb +11 -0
- data/spec/support/templates/post_decorator.rb +11 -0
- data/spec/unit/form_builder_spec.rb +121 -0
- data/tasks/test.rake +83 -0
- metadata +175 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'rspec/mocks'
|
3
|
+
|
4
|
+
describe ActiveadminMagicfields::FormBuilder do
|
5
|
+
|
6
|
+
# Setup an ActionView::Base object which can be used for
|
7
|
+
# generating the form for.
|
8
|
+
let(:helpers) do
|
9
|
+
view = action_view
|
10
|
+
def view.articles_path
|
11
|
+
"/articles"
|
12
|
+
end
|
13
|
+
|
14
|
+
def view.protect_against_forgery?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def view.url_for(*args)
|
19
|
+
if args.first == {action: "index"}
|
20
|
+
articles_path
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def view.a_helper_method
|
27
|
+
"A Helper Method"
|
28
|
+
end
|
29
|
+
|
30
|
+
view
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_form(options = {}, form_object = Article.new, &block)
|
34
|
+
options = {url: helpers.articles_path}.merge(options)
|
35
|
+
|
36
|
+
form = render_arbre_component({form_object: form_object, form_options: options, form_block: block}, helpers) do
|
37
|
+
active_admin_form_for(assigns[:form_object], assigns[:form_options], &assigns[:form_block])
|
38
|
+
end.to_s
|
39
|
+
|
40
|
+
Capybara.string(form)
|
41
|
+
end
|
42
|
+
|
43
|
+
context "in general" do
|
44
|
+
context "it without custom settings" do
|
45
|
+
let :body do
|
46
|
+
build_form do |f|
|
47
|
+
f.inputs do
|
48
|
+
f.input :title
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should generate a fieldset with a inputs class" do
|
54
|
+
expect(body).to have_selector("fieldset.inputs")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "it with custom settings" do
|
59
|
+
let :body do
|
60
|
+
build_form do |f|
|
61
|
+
f.inputs class: "custom_class" do
|
62
|
+
f.input :title
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should generate a fieldset with a inputs and custom class" do
|
68
|
+
expect(body).to have_selector("fieldset.inputs.custom_class")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with polymorphic has many inputs" do
|
74
|
+
describe "with simple block" do
|
75
|
+
let :body do
|
76
|
+
build_form builder: ActiveadminMagicfields::FormBuilder do |f|
|
77
|
+
section = f.object.sections.build
|
78
|
+
section.sectionable = Image.new
|
79
|
+
f.magicfields_has_many :sections, :sectionable, types: [Image, Text]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should render add section new button" do
|
84
|
+
with_translation activerecord: {models: {section: {one: "Section", other: "Sections"}}} do
|
85
|
+
expect(body).to have_selector("a", text: "Add New Section")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should render the nested form" do
|
90
|
+
expect(body).to have_selector("input[name='article[sections_attributes][0][sectionable_id]']")
|
91
|
+
expect(body).to have_selector("input[name='article[sections_attributes][0][sectionable_type]']")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should add a link to remove new nested records" do
|
95
|
+
expect(body).to have_selector(
|
96
|
+
".magicfields_has_many_container > fieldset > ol > li > a.button.magicfields_has_many_remove[href='#']", text: "Remove"
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "sortable" do
|
102
|
+
context "with new section" do
|
103
|
+
let :body do
|
104
|
+
build_form builder: ActiveadminMagicfields::FormBuilder do |f|
|
105
|
+
section = f.object.sections.build
|
106
|
+
section.sectionable = Image.new
|
107
|
+
f.magicfields_has_many :sections, :sectionable, types: [Image, Text], sortable: :position
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it "shows the nested fields for unsaved records" do
|
112
|
+
expect(body).to have_selector("input[name='article[sections_attributes][0][position]']")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "shows the nested fields for unsaved records" do
|
116
|
+
expect(body).to have_selector('.magicfields_has_many_container[data-sortable=position]')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
desc "Creates a test rails app for the specs to run against"
|
2
|
+
task :setup, :parallel do |t, args|
|
3
|
+
require 'rails/version'
|
4
|
+
if File.exists? dir = "spec/rails/rails-#{Rails::VERSION::STRING}"
|
5
|
+
puts "test app #{dir} already exists; skipping"
|
6
|
+
else
|
7
|
+
system("mkdir spec/rails") unless File.exists?("spec/rails")
|
8
|
+
system "#{'INSTALL_PARALLEL=yes' if args[:parallel]} bundle exec rails new #{dir} -m spec/support/rails_template.rb --skip-bundle"
|
9
|
+
Rake::Task['parallel:after_setup_hook'].invoke if args[:parallel]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run the full suite using 1 core"
|
14
|
+
task test: ['spec:unit', 'spec:integration', 'cucumber', 'cucumber:class_reloading']
|
15
|
+
|
16
|
+
require 'coveralls/rake/task'
|
17
|
+
Coveralls::RakeTask.new
|
18
|
+
task test_with_coveralls: [:test, 'coveralls:push']
|
19
|
+
|
20
|
+
namespace :test do
|
21
|
+
|
22
|
+
def run_tests_against(*versions)
|
23
|
+
current_version = detect_rails_version if File.exists?("Gemfile.lock")
|
24
|
+
|
25
|
+
versions.each do |version|
|
26
|
+
puts
|
27
|
+
puts "== Using Rails #{version}"
|
28
|
+
|
29
|
+
cmd "./script/use_rails #{version}"
|
30
|
+
cmd "bundle exec rspec spec"
|
31
|
+
cmd "bundle exec cucumber features"
|
32
|
+
cmd "bundle exec cucumber -p class-reloading features"
|
33
|
+
end
|
34
|
+
|
35
|
+
cmd "./script/use_rails #{current_version}" if current_version
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Run the full suite against the important versions of rails"
|
39
|
+
task :major_supported_rails do
|
40
|
+
run_tests_against *TRAVIS_RAILS_VERSIONS
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Alias for major_supported_rails"
|
44
|
+
task :all => :major_supported_rails
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
require 'rspec/core/rake_task'
|
49
|
+
|
50
|
+
RSpec::Core::RakeTask.new(:spec)
|
51
|
+
|
52
|
+
namespace :spec do
|
53
|
+
|
54
|
+
desc "Run the unit specs"
|
55
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
56
|
+
t.pattern = "spec/unit/**/*_spec.rb"
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Run the integration specs"
|
60
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
61
|
+
t.pattern = "spec/integration/**/*_spec.rb"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
require 'cucumber/rake/task'
|
68
|
+
|
69
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
70
|
+
t.profile = 'default'
|
71
|
+
end
|
72
|
+
|
73
|
+
namespace :cucumber do
|
74
|
+
|
75
|
+
Cucumber::Rake::Task.new(:wip, "Run the cucumber scenarios with the @wip tag") do |t|
|
76
|
+
t.profile = 'wip'
|
77
|
+
end
|
78
|
+
|
79
|
+
Cucumber::Rake::Task.new(:class_reloading, "Run the cucumber scenarios that test reloading") do |t|
|
80
|
+
t.profile = 'class-reloading'
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeadmin-magicfields
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Silvain Toromanoff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeadmin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: inherited_resources
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: paperclip
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem extends formtastic's form builder to support custom sections
|
56
|
+
and fields in your forms
|
57
|
+
email:
|
58
|
+
- silvain@agencyleroy.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- Guardfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- activeadmin-magicfields.gemspec
|
70
|
+
- app/assets/javascripts/activeadmin-magicfields.js.coffee
|
71
|
+
- app/assets/stylesheets/activeadmin-magicfields.css.scss
|
72
|
+
- lib/activeadmin-magicfields.rb
|
73
|
+
- lib/activeadmin-magicfields/engine.rb
|
74
|
+
- lib/activeadmin-magicfields/form_builder.rb
|
75
|
+
- lib/activeadmin-magicfields/paperclip.rb
|
76
|
+
- lib/activeadmin-magicfields/version.rb
|
77
|
+
- lib/app/admin/part.rb
|
78
|
+
- lib/app/admin/part_object.rb
|
79
|
+
- lib/app/models/field/checkbox.rb
|
80
|
+
- lib/app/models/field/image.rb
|
81
|
+
- lib/app/models/field/repeater.rb
|
82
|
+
- lib/app/models/field/text.rb
|
83
|
+
- lib/app/models/field/textarea.rb
|
84
|
+
- lib/app/models/field_template.rb
|
85
|
+
- lib/app/models/part.rb
|
86
|
+
- lib/app/models/part_object.rb
|
87
|
+
- lib/app/models/part_object_field.rb
|
88
|
+
- lib/app/models/repeater_part_object.rb
|
89
|
+
- lib/app/views/admin/field_inputs/_checkbox.html.erb
|
90
|
+
- lib/app/views/admin/field_inputs/_image.html.erb
|
91
|
+
- lib/app/views/admin/field_inputs/_product.html.erb
|
92
|
+
- lib/app/views/admin/field_inputs/_repeater.html.erb
|
93
|
+
- lib/app/views/admin/field_inputs/_site_page.html.erb
|
94
|
+
- lib/app/views/admin/field_inputs/_text.html.erb
|
95
|
+
- lib/app/views/admin/field_inputs/_textarea.html.erb
|
96
|
+
- lib/app/views/admin/part_objects/_part_object.html.erb
|
97
|
+
- lib/app/views/admin/parts/_part.html.erb
|
98
|
+
- lib/app/views/admin/parts/_part_old.arb
|
99
|
+
- lib/generators/activeadmin-magicfields/install/install_generator.rb
|
100
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_field_checkbox.rb
|
101
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_field_image.rb
|
102
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_field_repeater.rb
|
103
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_field_templates.rb
|
104
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_field_text.rb
|
105
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_field_textarea.rb
|
106
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_part_object_fields.rb
|
107
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_part_objects.rb
|
108
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_parts.rb
|
109
|
+
- lib/generators/activeadmin-magicfields/install/templates/create_repeater_part_objects.rb
|
110
|
+
- spec/rails_helper.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/support/deferred_garbage_collection.rb
|
113
|
+
- spec/support/detect_rails_version.rb
|
114
|
+
- spec/support/integration_example_group.rb
|
115
|
+
- spec/support/jslint.yml
|
116
|
+
- spec/support/rails_template.rb
|
117
|
+
- spec/support/rails_template_with_data.rb
|
118
|
+
- spec/support/templates/cucumber.rb
|
119
|
+
- spec/support/templates/cucumber_with_reloading.rb
|
120
|
+
- spec/support/templates/en.yml
|
121
|
+
- spec/support/templates/policies/active_admin/comment_policy.rb
|
122
|
+
- spec/support/templates/policies/active_admin/page_policy.rb
|
123
|
+
- spec/support/templates/policies/application_policy.rb
|
124
|
+
- spec/support/templates/policies/category_policy.rb
|
125
|
+
- spec/support/templates/policies/post_policy.rb
|
126
|
+
- spec/support/templates/policies/store_policy.rb
|
127
|
+
- spec/support/templates/policies/user_policy.rb
|
128
|
+
- spec/support/templates/post_decorator.rb
|
129
|
+
- spec/unit/form_builder_spec.rb
|
130
|
+
- tasks/test.rake
|
131
|
+
homepage: ''
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.2.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Custom fields and sections for active admin.
|
155
|
+
test_files:
|
156
|
+
- spec/rails_helper.rb
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
- spec/support/deferred_garbage_collection.rb
|
159
|
+
- spec/support/detect_rails_version.rb
|
160
|
+
- spec/support/integration_example_group.rb
|
161
|
+
- spec/support/jslint.yml
|
162
|
+
- spec/support/rails_template.rb
|
163
|
+
- spec/support/rails_template_with_data.rb
|
164
|
+
- spec/support/templates/cucumber.rb
|
165
|
+
- spec/support/templates/cucumber_with_reloading.rb
|
166
|
+
- spec/support/templates/en.yml
|
167
|
+
- spec/support/templates/policies/active_admin/comment_policy.rb
|
168
|
+
- spec/support/templates/policies/active_admin/page_policy.rb
|
169
|
+
- spec/support/templates/policies/application_policy.rb
|
170
|
+
- spec/support/templates/policies/category_policy.rb
|
171
|
+
- spec/support/templates/policies/post_policy.rb
|
172
|
+
- spec/support/templates/policies/store_policy.rb
|
173
|
+
- spec/support/templates/policies/user_policy.rb
|
174
|
+
- spec/support/templates/post_decorator.rb
|
175
|
+
- spec/unit/form_builder_spec.rb
|