Fix and add some tests on features/admin/tags_specs

This commit is contained in:
Eduardo Martinez Echevarria
2017-06-12 12:46:27 +02:00
parent 7fe5fc18b0
commit 7de6319324
2 changed files with 46 additions and 5 deletions

View File

@@ -538,6 +538,10 @@ FactoryGirl.define do
trait :unfeatured do
featured false
end
factory :category do
kind "category"
end
end
factory :setting do

View File

@@ -3,16 +3,21 @@ require 'rails_helper'
feature 'Admin tags' do
background do
@tag1 = create(:tag)
@tag1 = create(:category)
login_as(create(:administrator).user)
end
scenario 'Index' do
create(:debate, tag_list: 'supertag')
debate_tag = ActsAsTaggableOn::Tag.find_by(name: "supertag")
visit admin_tags_path
expect(page).to have_content @tag1.name
expect(page).to have_content 'supertag'
if debate_tag.category?
expect(page).to have_content 'supertag'
else
expect(page).to_not have_content 'supertag'
end
end
scenario 'Create' do
@@ -46,7 +51,7 @@ feature 'Admin tags' do
end
scenario 'Delete' do
tag2 = create(:tag, name: 'bad tag')
tag2 = create(:category, name: "bad tag")
create(:debate, tag_list: tag2.name)
visit admin_tags_path
@@ -63,7 +68,7 @@ feature 'Admin tags' do
end
scenario 'Delete tag with hidden taggables' do
tag2 = create(:tag, name: 'bad tag')
tag2 = create(:category, name: "bad tag")
debate = create(:debate, tag_list: tag2.name)
debate.hide
@@ -81,4 +86,36 @@ feature 'Admin tags' do
expect(page).to_not have_content tag2.name
end
end
context "Manage only tags of kind category" do
scenario "Index shows only categories" do
not_category_tag = create(:tag, name: "Not a category")
visit admin_tags_path
expect(page).to have_content @tag1.name
expect(page).to_not have_content "Not a category"
end
scenario "Create instanciates tags of correct kind" do
visit admin_tags_path
within("form.new_tag") do
fill_in "tag_name", with: "wow_category"
click_button 'Create Topic'
end
expect(ActsAsTaggableOn::Tag.category.where(name: "wow_category")).to exist
end
scenario "Update doesn't affect the category kind" do
visit admin_tags_path
within("#edit_tag_#{@tag1.id}") do
check "tag_featured_#{@tag1.id}"
click_button 'Update Topic'
end
expect(ActsAsTaggableOn::Tag.category.where(id: @tag1.id)).to exist
end
end
end