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,11 @@
|
|
1
|
+
class PartObject < ActiveRecord::Base
|
2
|
+
|
3
|
+
has_many :part_object_fields, class_name: "PartObjectField", foreign_key: "part_object_id", dependent: :destroy
|
4
|
+
# belongs_to :base_model, inverse_of: :part_objects, foreign_key: "base_model_id"
|
5
|
+
belongs_to :part
|
6
|
+
|
7
|
+
accepts_nested_attributes_for :part_object_fields, allow_destroy: true
|
8
|
+
|
9
|
+
scope :by_position, -> { order('position ASC') }
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class PartObjectField < ActiveRecord::Base
|
2
|
+
|
3
|
+
belongs_to :part_object, class_name: "PartObject", foreign_key: "part_object_id"
|
4
|
+
belongs_to :fieldable, polymorphic: true, dependent: :destroy
|
5
|
+
|
6
|
+
validates :fieldable, presence: true
|
7
|
+
accepts_nested_attributes_for :fieldable, allow_destroy: true
|
8
|
+
|
9
|
+
def build_fieldable(attributes, options = {})
|
10
|
+
self.fieldable = fieldable_type.constantize.new(attributes, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class RepeaterPartObject < ActiveRecord::Base
|
2
|
+
belongs_to :part_object, dependent: :destroy
|
3
|
+
belongs_to :field_repeater, class_name: "Field::Repeater", inverse_of: "repeater_part_objects", foreign_key: "field_repeater_id"
|
4
|
+
|
5
|
+
accepts_nested_attributes_for :part_object, allow_destroy: true
|
6
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= builder.input field_template.field_type, label: field_template.title, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<%= builder.input :image, as: :file, label: field_template.title, required: field_template.is_required, :hint => ( (builder.object.new_record? || builder.object.image_file_name.nil?) ? content_tag(:span, "No previous image") : ("current image:<br/>").html_safe + image_tag(builder.object.image.url(:thumb)) ), input_html: {value: builder.object.image_file_name, name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
|
2
|
+
<% if ( !builder.object.new_record? and !builder.object.image_file_name.nil? and !field_template.is_required ) %>
|
3
|
+
<%= builder.input :delete_image, as: :boolean, label: "Delete Image", input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[delete_image]" } %>
|
4
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= builder.input :product_id, as: :select, multiselect: false, collection: Spree::Product.all, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[product_id]" } %>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<%= semantic_fields_for "", builder.object, builder: ActiveadminMagicfields::FormBuilder do |r| %>
|
2
|
+
<% r.sections_has_many :parts, collection: Part.includes(:field_templates).all, part_objects: r.object.part_objects, sortable: :position, form_prefix: form_prefix + builder.object_name.sub('part[', '[') %>
|
3
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= builder.input :site_page_id, as: :select, multiselect: false, collection: SitePage.all, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[site_page_id]" } %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= builder.input field_template.field_type, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= builder.input field_template.field_type, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
|
2
|
+
|
3
|
+
<%# To make the textarea a Wysiwyg field, add to your gemfile
|
4
|
+
gem 'activeadmin-dragonfly', github: 'stefanoverna/activeadmin-dragonfly'
|
5
|
+
gem 'activeadmin-wysihtml5', github: 'silvaire/activeadmin-wysihtml5'
|
6
|
+
and replace the above line by the commented one below
|
7
|
+
%>
|
8
|
+
<%#= builder.input field_template.field_type, as: :wysihtml5, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<% if !part_object.new_record? or request.xhr?.blank? %>
|
2
|
+
<fieldset class="jsonb">
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
|
6
|
+
<%= semantic_fields_for part, namespace: 'part_form' do |r| %>
|
7
|
+
<%= r.semantic_fields_for "part_objects_attributes", part_object, index: (part_object.id || DateTime.now.strftime('%Q')) do |f| %>
|
8
|
+
<h3 class="section-title"><%= part.name %></h3>
|
9
|
+
<%= f.input :position, as: :hidden, input_html: {value: (part_object.position || 9999), name: form_prefix + f.object_name.sub('part[', '[') + "[#{f.index}][position]" } %>
|
10
|
+
<%= f.input :part_id, as: :hidden, input_html: {value: part.id, name: form_prefix + f.object_name.sub('part[', '[') + "[#{f.index}][part_id]" } %>
|
11
|
+
<% if part_object.part_object_fields.blank? %>
|
12
|
+
<% part.field_templates.by_position.each_with_index do |field_template, ix| %>
|
13
|
+
<%= f.semantic_fields_for "part_object_fields_attributes", part_object.part_object_fields.build, index: ix do |part_object_field| %>
|
14
|
+
|
15
|
+
<% field_object = Field.const_get(field_template.field_type.classify).new %>
|
16
|
+
<%= part_object_field.input :fieldable_type, as: :hidden, input_html: {value: "Field::" + field_template.field_type.classify, name: form_prefix + part_object_field.object_name.sub('part[', '[') + "[#{ix}][fieldable_type]"} %>
|
17
|
+
<%= part_object_field.semantic_fields_for "fieldable_attributes", field_object do |field| %>
|
18
|
+
<%= f.inputs do %>
|
19
|
+
<%= render partial: "admin/field_inputs/#{field_template.field_type}", locals: {builder: field, form_prefix: form_prefix, field_template: field_template} %>
|
20
|
+
<%= field.input :field_template_id, as: :hidden, input_html: {value: field_template.id, name: form_prefix + field.object_name.sub('part[', '[') + "[field_template_id]"} %>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
<% end %>
|
24
|
+
<% end %>
|
25
|
+
<% end %>
|
26
|
+
<% else %>
|
27
|
+
<%= f.input :id, as: :hidden, input_html: {value: part_object.id, name: form_prefix + f.object_name.sub('part[', '[') + "[#{f.index}][id]" } %>
|
28
|
+
<%= f.input :_destroy, as: :boolean, input_html: {name: form_prefix + f.object_name.sub('part[', '[') + "[#{f.index}][_destroy]" }, :wrapper_html => { :class => "destroy-section" } %>
|
29
|
+
<% part_object.part_object_fields.each_with_index do |part_object_field, ix| %>
|
30
|
+
<%= f.semantic_fields_for "part_object_fields_attributes", part_object_field, index: ix do |pof| %>
|
31
|
+
<%= pof.input :id, as: :hidden, input_html: {name: form_prefix + pof.object_name.sub('part[', '[') + "[#{ix}][id]", value: pof.object.id } %>
|
32
|
+
<%= pof.input :fieldable_type, as: :hidden, input_html: {name: form_prefix + pof.object_name.sub('part[', '[') + "[#{ix}][fieldable_type]", value: pof.object.fieldable_type } %>
|
33
|
+
<%= pof.semantic_fields_for "fieldable_attributes", part_object_field.fieldable do |fieldable| %>
|
34
|
+
<%= f.inputs do %>
|
35
|
+
<%= fieldable.input :id, as: :hidden, input_html: {name: form_prefix + fieldable.object_name.sub('part[', '[') + "[id]", value: fieldable.object.id } %>
|
36
|
+
<%= render partial: "admin/field_inputs/#{fieldable.object.field_template.field_type}", locals: {builder:fieldable, form_prefix: form_prefix, field_template:fieldable.object.field_template} %>
|
37
|
+
<%= fieldable.input :field_template_id, as: :hidden, input_html: {value: fieldable.object.field_template_id, name: form_prefix + fieldable.object_name.sub('part[', '[') + "[field_template_id]"} %>
|
38
|
+
<% end %>
|
39
|
+
<% end %>
|
40
|
+
<% end %>
|
41
|
+
<% end %>
|
42
|
+
<% end %>
|
43
|
+
<% end %>
|
44
|
+
<% end %>
|
45
|
+
|
46
|
+
|
47
|
+
<ol>
|
48
|
+
<li class="handle"><span class="icon icon_move_vertical"><svg x="0px" y="0px" width="100%" height="100%" viewBox="0 0 12 32" enable-background="new 0 0 12 32" xml:space="preserve"><g id=""></g><g id="move_x5F_vertical_x5F_12x32"> <g> <polygon fill="#5E6469" points="8,20 8,26 12,26 6,32 0,26 4,26 4,20 "></polygon> <polygon fill="#5E6469" points="4,12 4,6 0,6 6,0 12,6 8,6 8,12 "></polygon> </g></g></svg></span></li>
|
49
|
+
</ol>
|
50
|
+
|
51
|
+
<% if !part_object.new_record? or request.xhr?.blank? %>
|
52
|
+
</fieldset>
|
53
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Define the Part Object %>
|
2
|
+
|
3
|
+
<% part_object = resource.part_objects.build %>
|
4
|
+
|
5
|
+
<%# Build the fields %>
|
6
|
+
<%#= semantic_fields_for resource, namespace: 'new_part_form' do |r| %>
|
7
|
+
<%= render partial: "admin/part_objects/part_object", locals: {part_object: part_object, part: resource, form_prefix: params[:form_name]} %>
|
8
|
+
<%# end %>
|
9
|
+
|
10
|
+
|
11
|
+
<a class="button section_has_many_remove" href="#">Remove</a>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Define the Part Object
|
2
|
+
part_objects = resource.part_objects.build
|
3
|
+
|
4
|
+
# parents_array = params[:form_name].split("[").map{|n| n.chomp(']')}
|
5
|
+
|
6
|
+
# raise
|
7
|
+
|
8
|
+
# Build the form
|
9
|
+
active_admin_form_for part, url: "to_be_stripped" do |f|
|
10
|
+
f.semantic_fields_for :part_objects do |part_object|
|
11
|
+
|
12
|
+
part_object.input :part_id, as: :hidden, input_html: {value: part.id}
|
13
|
+
|
14
|
+
resource.field_templates.each_with_index do |field_template, ix|
|
15
|
+
part_object.semantic_fields_for "part_object_fields_attributes[#{ix}]", part_objects.part_object_fields.build do |part_object_field|
|
16
|
+
|
17
|
+
|
18
|
+
field_object = Field.const_get(field_template.field_type.classify).new
|
19
|
+
|
20
|
+
part_object_field.semantic_fields_for "fieldable_attributes", field_object do |field|
|
21
|
+
part_object.inputs do
|
22
|
+
field.input field_template.field_type, label: field_template.title, required: field_template.is_required
|
23
|
+
field.input :fieldable_type, as: :hidden, input_html: {value: field_template.field_type.classify}
|
24
|
+
field.input :title, as: :hidden, input_html: {value: field_template.title}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module ActiveadminMagicfields
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "add the migrations"
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
unless @prev_migration_nr
|
12
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
13
|
+
else
|
14
|
+
@prev_migration_nr += 1
|
15
|
+
end
|
16
|
+
@prev_migration_nr.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_migrations
|
20
|
+
migration_template "create_parts.rb", "db/migrate/create_parts.rb"
|
21
|
+
migration_template "create_part_objects.rb", "db/migrate/create_part_objects.rb"
|
22
|
+
migration_template "create_part_object_fields.rb", "db/migrate/create_part_object_fields.rb"
|
23
|
+
migration_template "create_field_templates.rb", "db/migrate/create_field_templates.rb"
|
24
|
+
migration_template "create_field_text.rb", "db/migrate/create_field_text.rb"
|
25
|
+
migration_template "create_field_image.rb", "db/migrate/create_field_image.rb"
|
26
|
+
migration_template "create_field_textarea.rb", "db/migrate/create_field_textarea.rb"
|
27
|
+
migration_template "create_field_checkbox.rb", "db/migrate/create_field_checkbox.rb"
|
28
|
+
migration_template "create_field_repeater.rb", "db/migrate/create_field_repeater.rb"
|
29
|
+
migration_template "create_repeater_part_objects.rb", "db/migrate/create_repeater_part_objects.rb"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateFieldTemplates < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :field_templates do |t|
|
4
|
+
t.string :title
|
5
|
+
t.boolean :is_required
|
6
|
+
t.string :field_type
|
7
|
+
t.references :part, index: true
|
8
|
+
|
9
|
+
t.integer :position
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ActiveAdminIntegrationSpecHelper
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def load_defaults!
|
7
|
+
ActiveAdmin.unload!
|
8
|
+
ActiveAdmin.load!
|
9
|
+
ActiveAdmin.register(Article)
|
10
|
+
ActiveAdmin.register(Image)
|
11
|
+
ActiveAdmin.register(Text)
|
12
|
+
# reload_menus!
|
13
|
+
end
|
14
|
+
|
15
|
+
# def reload_menus!
|
16
|
+
# ActiveAdmin.application.namespaces.values.each{|n| n.reset_menu! }
|
17
|
+
# end
|
18
|
+
|
19
|
+
# Sometimes we need to reload the routes within
|
20
|
+
# the application to test them out
|
21
|
+
def reload_routes!
|
22
|
+
Rails.application.reload_routes!
|
23
|
+
end
|
24
|
+
|
25
|
+
# Helper method to load resources and ensure that Active Admin is
|
26
|
+
# setup with the new configurations.
|
27
|
+
#
|
28
|
+
# Eg:
|
29
|
+
# load_resources do
|
30
|
+
# ActiveAdmin.regiser(Post)
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
def load_resources
|
34
|
+
ActiveAdmin.unload!
|
35
|
+
yield
|
36
|
+
reload_menus!
|
37
|
+
reload_routes!
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets up a describe block where you can render controller
|
41
|
+
# actions. Uses the Admin::PostsController as the subject
|
42
|
+
# for the describe block
|
43
|
+
def describe_with_render(*args, &block)
|
44
|
+
describe *args do
|
45
|
+
include RSpec::Rails::ControllerExampleGroup
|
46
|
+
render_views
|
47
|
+
# metadata[:behaviour][:describes] = ActiveAdmin.namespaces[:admin].resources['Post'].controller
|
48
|
+
module_eval &block
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def arbre(assigns = {}, helpers = mock_action_view, &block)
|
53
|
+
Arbre::Context.new(assigns, helpers, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
def render_arbre_component(assigns = {}, helpers = mock_action_view, &block)
|
57
|
+
arbre(assigns, helpers, &block).children.first
|
58
|
+
end
|
59
|
+
|
60
|
+
# Setup a describe block which uses capybara and rails integration
|
61
|
+
# test methods.
|
62
|
+
def describe_with_capybara(*args, &block)
|
63
|
+
describe *args do
|
64
|
+
include RSpec::Rails::IntegrationExampleGroup
|
65
|
+
module_eval &block
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns a fake action view instance to use with our renderers
|
70
|
+
def mock_action_view(assigns = {})
|
71
|
+
controller = ActionView::TestCase::TestController.new
|
72
|
+
ActionView::Base.send :include, ActionView::Helpers
|
73
|
+
ActionView::Base.send :include, ActiveAdmin::ViewHelpers
|
74
|
+
ActionView::Base.send :include, Rails.application.routes.url_helpers
|
75
|
+
ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
|
76
|
+
end
|
77
|
+
alias_method :action_view, :mock_action_view
|
78
|
+
|
79
|
+
# A mock resource to register
|
80
|
+
class MockResource
|
81
|
+
end
|
82
|
+
|
83
|
+
def with_translation(translation)
|
84
|
+
I18n.backend.store_translations :en, translation
|
85
|
+
yield
|
86
|
+
ensure
|
87
|
+
I18n.backend.reload!
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
ENV['RAILS_ENV'] = 'test'
|
93
|
+
ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)
|
94
|
+
|
95
|
+
# Create the test app if it doesn't exists
|
96
|
+
unless File.exists?(ENV['RAILS_ROOT'])
|
97
|
+
system 'rake setup'
|
98
|
+
end
|
99
|
+
|
100
|
+
require 'rails'
|
101
|
+
require 'active_record'
|
102
|
+
require 'active_admin'
|
103
|
+
# require 'devise'
|
104
|
+
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + "/app/admin"]
|
105
|
+
|
106
|
+
require ENV['RAILS_ROOT'] + '/config/environment'
|
107
|
+
|
108
|
+
require 'rspec/rails'
|
109
|
+
|
110
|
+
# Setup Some Admin stuff for us to play with
|
111
|
+
include ActiveAdminIntegrationSpecHelper
|
112
|
+
load_defaults!
|
113
|
+
reload_routes!
|
114
|
+
|
115
|
+
# Disabling authentication in specs so that we don't have to worry about
|
116
|
+
# it allover the place
|
117
|
+
ActiveAdmin.application.authentication_method = false
|
118
|
+
ActiveAdmin.application.current_user_method = false
|
119
|
+
|
120
|
+
# Don't add asset cache timestamps. Makes it easy to integration
|
121
|
+
# test for the presence of an asset file
|
122
|
+
ENV["RAILS_ASSET_ID"] = ''
|
123
|
+
|
124
|
+
RSpec.configure do |config|
|
125
|
+
config.use_transactional_fixtures = true
|
126
|
+
config.use_instantiated_fixtures = false
|
127
|
+
# config.include Devise::TestHelpers, type: :controller
|
128
|
+
config.render_views = false
|
129
|
+
config.filter_run focus: true
|
130
|
+
config.filter_run_excluding skip: true
|
131
|
+
config.run_all_when_everything_filtered = true
|
132
|
+
end
|
133
|
+
|
134
|
+
# All RSpec configuration needs to happen before any examples
|
135
|
+
# or else it whines.
|
136
|
+
require 'integration_example_group'
|
137
|
+
RSpec.configure do |c|
|
138
|
+
c.include RSpec::Rails::IntegrationExampleGroup, file_path: /\bspec\/requests\//
|
139
|
+
# c.include Devise::TestHelpers, type: :controller
|
140
|
+
end
|
141
|
+
|
142
|
+
# improve the performance of the specs suite by not logging anything
|
143
|
+
# see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
|
144
|
+
Rails.logger.level = 4
|
145
|
+
|
146
|
+
|
147
|
+
# Improves performance by forcing the garbage collector to run less often.
|
148
|
+
unless ENV['DEFER_GC'] == '0' || ENV['DEFER_GC'] == 'false'
|
149
|
+
require 'support/deferred_garbage_collection'
|
150
|
+
RSpec.configure do |config|
|
151
|
+
config.before(:all) { DeferredGarbageCollection.start }
|
152
|
+
config.after(:all) { DeferredGarbageCollection.reconsider }
|
153
|
+
end
|
154
|
+
end
|