activeadmin_polymorphic 0.1.0

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 +7 -0
  2. data/.gitignore +50 -0
  3. data/Gemfile +40 -0
  4. data/Guardfile +8 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +86 -0
  7. data/Rakefile +33 -0
  8. data/activeadmin_polymorphic.gemspec +19 -0
  9. data/app/assets/javascripts/activeadmin_polymorphic.js.coffee +172 -0
  10. data/app/assets/stylesheets/activeadmin_polymorphic.css.sass +25 -0
  11. data/lib/activeadmin_polymorphic/engine.rb +5 -0
  12. data/lib/activeadmin_polymorphic/form_builder.rb +124 -0
  13. data/lib/activeadmin_polymorphic/version.rb +3 -0
  14. data/lib/activeadmin_polymorphic.rb +5 -0
  15. data/spec/rails_helper.rb +154 -0
  16. data/spec/spec_helper.rb +17 -0
  17. data/spec/support/deferred_garbage_collection.rb +19 -0
  18. data/spec/support/detect_rails_version.rb +26 -0
  19. data/spec/support/integration_example_group.rb +31 -0
  20. data/spec/support/jslint.yml +80 -0
  21. data/spec/support/rails_template.rb +104 -0
  22. data/spec/support/rails_template_with_data.rb +59 -0
  23. data/spec/support/templates/cucumber.rb +24 -0
  24. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  25. data/spec/support/templates/en.yml +8 -0
  26. data/spec/support/templates/policies/active_admin/comment_policy.rb +9 -0
  27. data/spec/support/templates/policies/active_admin/page_policy.rb +18 -0
  28. data/spec/support/templates/policies/application_policy.rb +45 -0
  29. data/spec/support/templates/policies/category_policy.rb +7 -0
  30. data/spec/support/templates/policies/post_policy.rb +15 -0
  31. data/spec/support/templates/policies/store_policy.rb +11 -0
  32. data/spec/support/templates/policies/user_policy.rb +11 -0
  33. data/spec/support/templates/post_decorator.rb +11 -0
  34. data/spec/unit/form_builder_spec.rb +121 -0
  35. data/tasks/test.rake +83 -0
  36. metadata +102 -0
@@ -0,0 +1,121 @@
1
+ require 'rails_helper'
2
+ require 'rspec/mocks'
3
+
4
+ describe ActiveadminPolymorphic::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: ActiveadminPolymorphic::FormBuilder do |f|
77
+ section = f.object.sections.build
78
+ section.sectionable = Image.new
79
+ f.polymorphic_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
+ ".polymorphic_has_many_container > fieldset > ol > li > a.button.polymorphic_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: ActiveadminPolymorphic::FormBuilder do |f|
105
+ section = f.object.sections.build
106
+ section.sectionable = Image.new
107
+ f.polymorphic_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('.polymorphic_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,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin_polymorphic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Petr Sergeev
8
+ - Sindre Moen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This gem extends formtastic's form builder to support polymoprhic has
15
+ many relations in your forms
16
+ email:
17
+ - peter@hyper.no
18
+ - sindre@hyper.no
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".gitignore"
24
+ - Gemfile
25
+ - Guardfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - activeadmin_polymorphic.gemspec
30
+ - app/assets/javascripts/activeadmin_polymorphic.js.coffee
31
+ - app/assets/stylesheets/activeadmin_polymorphic.css.sass
32
+ - lib/activeadmin_polymorphic.rb
33
+ - lib/activeadmin_polymorphic/engine.rb
34
+ - lib/activeadmin_polymorphic/form_builder.rb
35
+ - lib/activeadmin_polymorphic/version.rb
36
+ - spec/rails_helper.rb
37
+ - spec/spec_helper.rb
38
+ - spec/support/deferred_garbage_collection.rb
39
+ - spec/support/detect_rails_version.rb
40
+ - spec/support/integration_example_group.rb
41
+ - spec/support/jslint.yml
42
+ - spec/support/rails_template.rb
43
+ - spec/support/rails_template_with_data.rb
44
+ - spec/support/templates/cucumber.rb
45
+ - spec/support/templates/cucumber_with_reloading.rb
46
+ - spec/support/templates/en.yml
47
+ - spec/support/templates/policies/active_admin/comment_policy.rb
48
+ - spec/support/templates/policies/active_admin/page_policy.rb
49
+ - spec/support/templates/policies/application_policy.rb
50
+ - spec/support/templates/policies/category_policy.rb
51
+ - spec/support/templates/policies/post_policy.rb
52
+ - spec/support/templates/policies/store_policy.rb
53
+ - spec/support/templates/policies/user_policy.rb
54
+ - spec/support/templates/post_decorator.rb
55
+ - spec/unit/form_builder_spec.rb
56
+ - tasks/test.rake
57
+ homepage: https://github.com/hyperoslo/activeadmin-polymorphic
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: HasMany polymoprhic support for active admin.
81
+ test_files:
82
+ - spec/rails_helper.rb
83
+ - spec/spec_helper.rb
84
+ - spec/support/deferred_garbage_collection.rb
85
+ - spec/support/detect_rails_version.rb
86
+ - spec/support/integration_example_group.rb
87
+ - spec/support/jslint.yml
88
+ - spec/support/rails_template.rb
89
+ - spec/support/rails_template_with_data.rb
90
+ - spec/support/templates/cucumber.rb
91
+ - spec/support/templates/cucumber_with_reloading.rb
92
+ - spec/support/templates/en.yml
93
+ - spec/support/templates/policies/active_admin/comment_policy.rb
94
+ - spec/support/templates/policies/active_admin/page_policy.rb
95
+ - spec/support/templates/policies/application_policy.rb
96
+ - spec/support/templates/policies/category_policy.rb
97
+ - spec/support/templates/policies/post_policy.rb
98
+ - spec/support/templates/policies/store_policy.rb
99
+ - spec/support/templates/policies/user_policy.rb
100
+ - spec/support/templates/post_decorator.rb
101
+ - spec/unit/form_builder_spec.rb
102
+ has_rdoc: