spec/unit/form_builder_spec.rb in activeadmin-1.0.0.pre5 vs spec/unit/form_builder_spec.rb in activeadmin-1.0.0

- old
+ new

@@ -28,10 +28,14 @@ def view.fa_icon(*args) args.inspect end + def view.action_name + 'edit' + end + view end def build_form(options = {}, form_object = Post.new, &block) options = {url: helpers.posts_path}.merge(options) @@ -133,21 +137,19 @@ it "should pass the options on to the form" do expect(body).to have_selector("form[enctype='multipart/form-data']") end end - if Rails::VERSION::MAJOR > 3 - context "file input present" do - let :body do - build_form do |f| - f.input :body, as: :file - end + context "file input present" do + let :body do + build_form do |f| + f.input :body, as: :file end + end - it "adds multipart attribute automatically" do - expect(body).to have_selector("form[enctype='multipart/form-data']") - end + it "adds multipart attribute automatically" do + expect(body).to have_selector("form[enctype='multipart/form-data']") end end context "with actions" do it "should generate the form once" do @@ -157,17 +159,43 @@ end f.actions end expect(body).to have_selector("[id=post_title]", count: 1) end - it "should generate one button and a cancel link" do + + context "create another checkbox" do + subject do + build_form do |f| + f.actions + end + end + + %w(new create).each do |action_name| + it "generates create another checkbox on #{action_name} page" do + expect(helpers).to receive(:action_name) { action_name } + allow(helpers).to receive(:active_admin_config) { instance_double(ActiveAdmin::Resource, create_another: true) } + + is_expected.to have_selector("[type=checkbox]", count: 1) + .and have_selector("[name=create_another]", count: 1) + end + end + + %w(show edit update).each do |action_name| + it "doesn't generate create another checkbox on #{action_name} page" do + is_expected.not_to have_selector("[name=create_another]", count: 1) + end + end + end + + it "should generate one button create another checkbox and a cancel link" do body = build_form do |f| f.actions end expect(body).to have_selector("[type=submit]", count: 1) expect(body).to have_selector("[class=cancel]", count: 1) end + it "should generate multiple actions" do body = build_form do |f| f.actions do f.action :submit, label: "Create & Continue" f.action :submit, label: "Create & Edit" @@ -524,10 +552,10 @@ describe "with complex block" do let :body do build_form({url: '/categories'}, Category.new) do |f| f.object.posts.build - f.has_many :posts do |p,i| + f.has_many :posts do |p, i| p.input :title, label: "Title #{i}" end end end