From 07384edb2d510f42d9c19ed580700cd4d167f280 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 27 May 2016 22:00:08 +1000 Subject: [PATCH] Can delete default tag rules --- .../admin/tag_rules/tag_rule.html.haml | 2 +- spec/features/admin/tag_rules_spec.rb | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml b/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml index 4427d284fd..7907b9dfda 100644 --- a/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml +++ b/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml @@ -40,7 +40,7 @@ %td %tags-with-translation{ object: "rule", max: 1, "tags-attr" => "{{opt[rule.type].tagsAttr}}", "tag-list-attr" => "{{opt[rule.type].tagListAttr}}" } %td.actions{ rowspan: 2 } - %a{ ng: { click: "deleteTagRule(tagGroup, rule)" }, :class => "delete-tag-rule icon-trash no-text" } + %a{ ng: { click: "deleteTagRule(tagGroup || defaultTagGroup, rule)" }, :class => "delete-tag-rule icon-trash no-text" } %tr %td %span.text-normal {{ opt[rule.type].textBottom }} diff --git a/spec/features/admin/tag_rules_spec.rb b/spec/features/admin/tag_rules_spec.rb index 63955de1f8..d956ff94b6 100644 --- a/spec/features/admin/tag_rules_spec.rb +++ b/spec/features/admin/tag_rules_spec.rb @@ -219,24 +219,23 @@ feature 'Tag Rules', js: true do end context "deleting" do - let!(:tag_rule) { create(:tag_rule, enterprise: enterprise, preferred_customer_tags: "member" ) } + let!(:tag_rule) { create(:filter_products_tag_rule, enterprise: enterprise, preferred_customer_tags: "member" ) } + let!(:default_rule) { create(:filter_products_tag_rule, is_default: true, enterprise: enterprise ) } before do login_to_admin_section visit main_app.edit_admin_enterprise_path(enterprise) end - it "deletes rules from the database" do + it "deletes both default and customer rules from the database" do click_link "Tag Rules" - expect(page).to have_selector "#tr_0" - - expect{ - within "#tr_0" do - first("a.delete-tag-rule").click - end + expect do + within "#tr_1" do first("a.delete-tag-rule").click end + expect(page).to_not have_selector "#tr_1" + within "#tr_0" do first("a.delete-tag-rule").click end expect(page).to_not have_selector "#tr_0" - }.to change{TagRule.count}.by(-1) + end.to change{TagRule.count}.by(-2) end end end