From debc98ac994d5c3869744acb98219918127412be Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Mon, 12 Jun 2017 12:42:19 +0200 Subject: [PATCH 01/11] Add category scope and category? method to ActsAsTaggableOn::Tag --- config/initializers/acts_as_taggable_on.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index e570e08de..139f9963c 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -29,6 +29,12 @@ module ActsAsTaggableOn Tag.class_eval do + scope :category, -> { where(kind: "category") } + + def category? + kind == "category" + end + include Graphqlable scope :public_for_api, -> do From 7fe5fc18b0652a34d61b41ee128a3a3325f70960 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Mon, 12 Jun 2017 12:43:39 +0200 Subject: [PATCH 02/11] Manage only tags of kind 'category' on admin/tags controller --- app/controllers/admin/tags_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 5655b0f8a..82186ccaf 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -4,12 +4,12 @@ class Admin::TagsController < Admin::BaseController respond_to :html, :js def index - @tags = ActsAsTaggableOn::Tag.order(featured: :desc).page(params[:page]) - @tag = ActsAsTaggableOn::Tag.new + @tags = ActsAsTaggableOn::Tag.category.order(featured: :desc).page(params[:page]) + @tag = ActsAsTaggableOn::Tag.category.new end def create - ActsAsTaggableOn::Tag.create(tag_params) + ActsAsTaggableOn::Tag.category.create(tag_params) redirect_to admin_tags_path end @@ -30,7 +30,7 @@ class Admin::TagsController < Admin::BaseController end def find_tag - @tag = ActsAsTaggableOn::Tag.find(params[:id]) + @tag = ActsAsTaggableOn::Tag.category.find(params[:id]) end end From 7de6319324da86395da7e8b5fdefb17ffab247b6 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Mon, 12 Jun 2017 12:46:27 +0200 Subject: [PATCH 03/11] Fix and add some tests on features/admin/tags_specs --- spec/factories.rb | 4 +++ spec/features/admin/tags_spec.rb | 47 ++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 42c8dbfc5..e046dc42d 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -538,6 +538,10 @@ FactoryGirl.define do trait :unfeatured do featured false end + + factory :category do + kind "category" + end end factory :setting do diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index b944cdd9e..3a2759490 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -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 \ No newline at end of file + 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 From a600dcbb367ebad164bec7be6ebbd11b6340229a Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 11:54:31 +0200 Subject: [PATCH 04/11] Replace category factory in tags with a trait --- spec/factories.rb | 2 +- spec/features/admin/tags_spec.rb | 6 +++--- spec/features/proposals_spec.rb | 10 +++++----- spec/features/tags/budget_investments_spec.rb | 8 ++++---- spec/features/tags/proposals_spec.rb | 12 +++++------ spec/features/tags_spec.rb | 4 ++-- spec/lib/acts_as_taggable_on_spec.rb | 2 +- spec/lib/graphql_spec.rb | 6 +++--- spec/models/proposal_spec.rb | 20 +++++++++---------- spec/models/tag_cloud_spec.rb | 8 ++++---- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index e046dc42d..7ff7e5a31 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -539,7 +539,7 @@ FactoryGirl.define do featured false end - factory :category do + trait :category do kind "category" end end diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index 3a2759490..90cfde90d 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' feature 'Admin tags' do background do - @tag1 = create(:category) + @tag1 = create(:tag, :category) login_as(create(:administrator).user) end @@ -51,7 +51,7 @@ feature 'Admin tags' do end scenario 'Delete' do - tag2 = create(:category, name: "bad tag") + tag2 = create(:tag, :category, name: "bad tag") create(:debate, tag_list: tag2.name) visit admin_tags_path @@ -68,7 +68,7 @@ feature 'Admin tags' do end scenario 'Delete tag with hidden taggables' do - tag2 = create(:category, name: "bad tag") + tag2 = create(:tag, :category, name: "bad tag") debate = create(:debate, tag_list: tag2.name) debate.hide diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index bd7cafee1..6fb298303 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1345,8 +1345,8 @@ feature 'Proposals' do context "Summary" do scenario "Displays proposals grouped by category" do - create(:tag, kind: 'category', name: 'Culture') - create(:tag, kind: 'category', name: 'Social Services') + create(:tag, :category, name: 'Culture') + create(:tag, :category, name: 'Social Services') 3.times { create(:proposal, tag_list: 'Culture') } 3.times { create(:proposal, tag_list: 'Social Services') } @@ -1389,7 +1389,7 @@ feature 'Proposals' do end scenario "Displays a maximum of 3 proposals per category" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') 4.times { create(:proposal, tag_list: 'culture') } visit summary_proposals_path @@ -1398,7 +1398,7 @@ feature 'Proposals' do end scenario "Orders proposals by votes" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') create(:proposal, title: 'Best', tag_list: 'culture').update_column(:confidence_score, 10) create(:proposal, title: 'Worst', tag_list: 'culture').update_column(:confidence_score, 2) create(:proposal, title: 'Medium', tag_list: 'culture').update_column(:confidence_score, 5) @@ -1410,7 +1410,7 @@ feature 'Proposals' do end scenario "Displays proposals from last week" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') proposal1 = create(:proposal, tag_list: 'culture', created_at: 1.day.ago) proposal2 = create(:proposal, tag_list: 'culture', created_at: 5.days.ago) proposal3 = create(:proposal, tag_list: 'culture', created_at: 8.days.ago) diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index 4c978c740..ada2338b4 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -79,8 +79,8 @@ feature 'Tags' do scenario 'Category with category tags', :js do login_as(author) - education = create(:tag, name: 'Education', kind: 'category') - health = create(:tag, name: 'Health', kind: 'category') + education = create(:tag, :category, name: 'Education') + health = create(:tag, :category, name: 'Health') visit new_budget_investment_path(budget_id: budget.id) @@ -221,8 +221,8 @@ feature 'Tags' do context "Categories" do - let!(:tag1) { create(:tag, kind: 'category', name: 'Medio Ambiente') } - let!(:tag2) { create(:tag, kind: 'category', name: 'Economía') } + let!(:tag1) { create(:tag, :category, name: 'Medio Ambiente') } + let!(:tag2) { create(:tag, :category, name: 'Economía') } let!(:investment1) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } let!(:investment2) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } diff --git a/spec/features/tags/proposals_spec.rb b/spec/features/tags/proposals_spec.rb index dbab6a95f..cf5017d4f 100644 --- a/spec/features/tags/proposals_spec.rb +++ b/spec/features/tags/proposals_spec.rb @@ -91,8 +91,8 @@ feature 'Tags' do user = create(:user) login_as(user) - education = create(:tag, name: 'Education', kind: 'category') - health = create(:tag, name: 'Health', kind: 'category') + education = create(:tag, :category, name: 'Education') + health = create(:tag, :category, name: 'Health') visit new_proposal_path @@ -265,8 +265,8 @@ feature 'Tags' do context "Categories" do scenario 'Display category tags' do - create(:tag, kind: 'category', name: 'Medio Ambiente') - create(:tag, kind: 'category', name: 'Economía') + create(:tag, :category, name: 'Medio Ambiente') + create(:tag, :category, name: 'Economía') earth = create(:proposal, tag_list: 'Medio Ambiente') money = create(:proposal, tag_list: 'Economía') @@ -280,8 +280,8 @@ feature 'Tags' do end scenario "Filter by category tags" do - create(:tag, kind: 'category', name: 'Medio Ambiente') - create(:tag, kind: 'category', name: 'Economía') + create(:tag, :category, name: 'Medio Ambiente') + create(:tag, :category, name: 'Economía') proposal1 = create(:proposal, tag_list: 'Medio Ambiente') proposal2 = create(:proposal, tag_list: 'Medio Ambiente') diff --git a/spec/features/tags_spec.rb b/spec/features/tags_spec.rb index 4ca42f5eb..8497d5b63 100644 --- a/spec/features/tags_spec.rb +++ b/spec/features/tags_spec.rb @@ -148,8 +148,8 @@ feature 'Tags' do end scenario "scoped by category" do - create(:tag, kind: 'category', name: 'Medio Ambiente') - create(:tag, kind: 'category', name: 'Economía') + create(:tag, :category, name: 'Medio Ambiente') + create(:tag, :category, name: 'Economía') earth = create(:proposal, tag_list: 'Medio Ambiente, Agua') money = create(:proposal, tag_list: 'Economía, Corrupción') diff --git a/spec/lib/acts_as_taggable_on_spec.rb b/spec/lib/acts_as_taggable_on_spec.rb index d261bbad2..761e90553 100644 --- a/spec/lib/acts_as_taggable_on_spec.rb +++ b/spec/lib/acts_as_taggable_on_spec.rb @@ -77,7 +77,7 @@ describe 'ActsAsTaggableOn' do end it "returns tags whose kind is 'category' and have at least one tagging whose taggable is not hidden" do - tag = create(:tag, kind: 'category') + tag = create(:tag, :category) proposal = create(:proposal) proposal.tag_list.add(tag) proposal.save diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index 725cc109a..b1e7073ea 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -207,7 +207,7 @@ describe 'ConsulSchema' do it 'only retruns tags with kind nil or category' do tag = create(:tag, name: 'Parks') - category_tag = create(:tag, name: 'Health', kind: 'category') + category_tag = create(:tag, :category, name: 'Health') admin_tag = create(:tag, name: 'Admin tag', kind: 'admin') proposal = create(:proposal, tag_list: 'Parks, Health, Admin tag') @@ -269,7 +269,7 @@ describe 'ConsulSchema' do it 'only retruns tags with kind nil or category' do tag = create(:tag, name: 'Parks') - category_tag = create(:tag, name: 'Health', kind: 'category') + category_tag = create(:tag, :category, name: 'Health') admin_tag = create(:tag, name: 'Admin tag', kind: 'admin') debate = create(:debate, tag_list: 'Parks, Health, Admin tag') @@ -453,7 +453,7 @@ describe 'ConsulSchema' do describe 'Tags' do it 'only display tags with kind nil or category' do tag = create(:tag, name: 'Parks') - category_tag = create(:tag, name: 'Health', kind: 'category') + category_tag = create(:tag, :category, name: 'Health') admin_tag = create(:tag, name: 'Admin tag', kind: 'admin') proposal = create(:proposal, tag_list: 'Parks') diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index f60bff18c..d8c467974 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -703,14 +703,14 @@ describe Proposal do context "categories" do it "should return proposals tagged with a category" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') proposal = create(:proposal, tag_list: 'culture') expect(Proposal.for_summary.values.flatten).to include(proposal) end it "should not return proposals tagged without a category" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') proposal = create(:proposal, tag_list: 'parks') expect(Proposal.for_summary.values.flatten).to_not include(proposal) @@ -735,19 +735,19 @@ describe Proposal do end it "should return proposals created this week" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') proposal = create(:proposal, tag_list: 'culture') expect(Proposal.for_summary.values.flatten).to include(proposal) end it "should not return proposals created more than a week ago" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') proposal = create(:proposal, tag_list: 'culture', created_at: 8.days.ago) expect(Proposal.for_summary.values.flatten).to_not include(proposal) end it "should order proposals by votes" do - create(:tag, kind: 'category', name: 'culture') + create(:tag, :category, name: 'culture') create(:proposal, tag_list: 'culture').update_column(:confidence_score, 2) create(:proposal, tag_list: 'culture').update_column(:confidence_score, 10) create(:proposal, tag_list: 'culture').update_column(:confidence_score, 5) @@ -760,9 +760,9 @@ describe Proposal do end it "should order groups alphabetically" do - create(:tag, kind: 'category', name: 'health') - create(:tag, kind: 'category', name: 'culture') - create(:tag, kind: 'category', name: 'social services') + create(:tag, :category, name: 'health') + create(:tag, :category, name: 'culture') + create(:tag, :category, name: 'social services') health_proposal = create(:proposal, tag_list: 'health') culture_proposal = create(:proposal, tag_list: 'culture') @@ -776,8 +776,8 @@ describe Proposal do end it "should return proposals grouped by tag" do - create(:tag, kind: 'category', name: 'culture') - create(:tag, kind: 'category', name: 'health') + create(:tag, :category, name: 'culture') + create(:tag, :category, name: 'health') proposal1 = create(:proposal, tag_list: 'culture') proposal2 = create(:proposal, tag_list: 'culture') diff --git a/spec/models/tag_cloud_spec.rb b/spec/models/tag_cloud_spec.rb index 5de136ae1..c99e6a919 100644 --- a/spec/models/tag_cloud_spec.rb +++ b/spec/models/tag_cloud_spec.rb @@ -41,8 +41,8 @@ describe TagCloud do end it "does not return category tags" do - create(:tag, kind: 'category', name: 'Education') - create(:tag, kind: 'category', name: 'Participation') + create(:tag, :category, name: 'Education') + create(:tag, :category, name: 'Participation') create(:proposal, tag_list: 'education, parks') create(:proposal, tag_list: 'participation, water') @@ -65,8 +65,8 @@ describe TagCloud do end it "returns tags scoped by category" do - create(:tag, kind: 'category', name: 'Education') - create(:tag, kind: 'category', name: 'Participation') + create(:tag, :category, name: 'Education') + create(:tag, :category, name: 'Participation') create(:proposal, tag_list: 'education, parks') create(:proposal, tag_list: 'participation, water') From 8dd52110db7253800d68f17697005aef37ef786a Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 14:50:46 +0200 Subject: [PATCH 05/11] Use category scope instead of condition on kind on Tag --- app/controllers/budgets/ballot/lines_controller.rb | 2 +- app/controllers/budgets/investments_controller.rb | 2 +- app/controllers/concerns/commentable_actions.rb | 2 +- app/controllers/management/budgets/investments_controller.rb | 2 +- config/initializers/acts_as_taggable_on.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 25f356f1f..d5d5468a2 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -67,7 +67,7 @@ module Budgets end def load_categories - @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) + @categories = ActsAsTaggableOn::Tag.category.order(:name) end def load_ballot_referer diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 469b09255..f6bba1200 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -118,7 +118,7 @@ module Budgets end def load_categories - @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) + @categories = ActsAsTaggableOn::Tag.category.order(:name) end def tag_cloud diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 489d1857c..195d10459 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -92,7 +92,7 @@ module CommentableActions end def load_categories - @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) + @categories = ActsAsTaggableOn::Tag.category.order(:name) end def parse_tag_filter diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 652d2b9a7..6c1e1bfcd 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -64,7 +64,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController end def load_categories - @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) + @categories = ActsAsTaggableOn::Tag.category.order(:name) end end diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 139f9963c..57766c8c9 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -58,7 +58,7 @@ module ActsAsTaggableOn end def self.category_names - Tag.where("kind = 'category'").pluck(:name) + Tag.category.pluck(:name) end def self.spending_proposal_tags From fd2c51d4b17b66ce9d614421a48af58a997750c7 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 15:00:02 +0200 Subject: [PATCH 06/11] Fix admin/tags test avoiding the use of conditional --- spec/features/admin/tags_spec.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index 90cfde90d..7d5119162 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -8,16 +8,12 @@ feature 'Admin tags' do end scenario 'Index' do - create(:debate, tag_list: 'supertag') - debate_tag = ActsAsTaggableOn::Tag.find_by(name: "supertag") + debate = create(:debate) + debate.tag_list.add(create(:tag, :category, name: "supertag")) visit admin_tags_path expect(page).to have_content @tag1.name - if debate_tag.category? - expect(page).to have_content 'supertag' - else - expect(page).to_not have_content 'supertag' - end + expect(page).to have_content 'supertag' end scenario 'Create' do From eb2e5c58b6e1a90b4e64783ebf6abd33515b334c Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 15:04:30 +0200 Subject: [PATCH 07/11] Remove unused featured traits from tags factory --- spec/factories.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 7ff7e5a31..94d1a86ff 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -531,14 +531,6 @@ FactoryGirl.define do factory :tag, class: 'ActsAsTaggableOn::Tag' do sequence(:name) { |n| "Tag #{n} name" } - trait :featured do - featured true - end - - trait :unfeatured do - featured false - end - trait :category do kind "category" end From e60ffa3c001ee0b7e59d82cfd9c9caf1d8a66b9d Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 15:43:49 +0200 Subject: [PATCH 08/11] Remove featured attribute management on admin/tags --- app/controllers/admin/tags_controller.rb | 9 ++------ app/views/admin/tags/index.html.erb | 11 ---------- config/locales/admin.en.yml | 2 -- config/locales/admin.es.yml | 2 -- config/locales/admin.fr.yml | 2 -- config/locales/admin.nl.yml | 2 -- spec/features/admin/tags_spec.rb | 26 ------------------------ 7 files changed, 2 insertions(+), 52 deletions(-) diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 82186ccaf..6bccb176a 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -4,7 +4,7 @@ class Admin::TagsController < Admin::BaseController respond_to :html, :js def index - @tags = ActsAsTaggableOn::Tag.category.order(featured: :desc).page(params[:page]) + @tags = ActsAsTaggableOn::Tag.category.page(params[:page]) @tag = ActsAsTaggableOn::Tag.category.new end @@ -13,11 +13,6 @@ class Admin::TagsController < Admin::BaseController redirect_to admin_tags_path end - def update - @tag.update(tag_params) - redirect_to admin_tags_path - end - def destroy @tag.destroy redirect_to admin_tags_path @@ -26,7 +21,7 @@ class Admin::TagsController < Admin::BaseController private def tag_params - params.require(:tag).permit(:featured, :name) + params.require(:tag).permit(:name) end def find_tag diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index c1eda4b30..715479420 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -8,12 +8,6 @@ <%= f.text_field :name, placeholder: t("admin.tags.name.placeholder"), label: false %> - <%= f.submit(t("admin.tags.create"), class: "button success") %> @@ -33,13 +27,8 @@ <%= tag.name %> - <%= f.label "featured_#{tag.id}" do %> - <%= f.check_box :featured, title: t('admin.tags.mark_as_featured'), label: false, id: "tag_featured_#{tag.id}", class: "inline-block" %> - <%= t("admin.tags.mark_as_featured") %> - <% end %> - <%= f.submit(t("admin.tags.update"), class: "button hollow on-hover") %> <%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: "button hollow alert on-hover" %> <% end %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index bbd8dd1bd..7638ce535 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -812,10 +812,8 @@ en: index: add_tag: Add a new proposal topic title: Proposal topics - mark_as_featured: Propose topic upon creating proposal name: placeholder: Type the name of the topic - update: Update Topic users: columns: name: Name diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index a3c6a99b9..92d5fb534 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -812,10 +812,8 @@ es: index: add_tag: Añade un nuevo tema de propuesta title: Temas de propuesta - mark_as_featured: Proponer tema al crear propuesta name: placeholder: Escribe el nombre del tema - update: Actualizar Tema users: columns: name: Nombre diff --git a/config/locales/admin.fr.yml b/config/locales/admin.fr.yml index 8100a95a6..d020a5690 100644 --- a/config/locales/admin.fr.yml +++ b/config/locales/admin.fr.yml @@ -644,10 +644,8 @@ fr: index: add_tag: Ajouter un nouveau sujet de proposition title: Sujets de propositions - mark_as_featured: Proposer le sujet lors de la création d'une proposition name: placeholder: Saisir le nom du sujet - update: Mettre-à-jour le sujet users: index: filter: Filtrer diff --git a/config/locales/admin.nl.yml b/config/locales/admin.nl.yml index 40b21ed32..f31313cf4 100755 --- a/config/locales/admin.nl.yml +++ b/config/locales/admin.nl.yml @@ -641,10 +641,8 @@ nl: index: add_tag: Add a new proposal topic title: Proposal topics - mark_as_featured: Propose topic upon creating proposal name: placeholder: Type the name of the topic - update: Update Topic users: index: filter: Filter diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index 7d5119162..dd9c38c6b 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -31,21 +31,6 @@ feature 'Admin tags' do expect(page).to have_content 'important issues' end - scenario 'Update' do - visit admin_tags_path - featured_checkbox = find("#tag_featured_#{@tag1.id}") - expect(featured_checkbox.checked?).to be_blank - - within("#edit_tag_#{@tag1.id}") do - check "tag_featured_#{@tag1.id}" - click_button 'Update Topic' - end - - visit admin_tags_path - featured_checkbox = find("#tag_featured_#{@tag1.id}") - expect(featured_checkbox.checked?).to eq(true) - end - scenario 'Delete' do tag2 = create(:tag, :category, name: "bad tag") create(:debate, tag_list: tag2.name) @@ -101,17 +86,6 @@ feature 'Admin tags' do 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 From ae9030e6c5ae1f59ac6242461a5324e597ebba53 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 16:14:44 +0200 Subject: [PATCH 09/11] Change categories creation on dev_seeds removing reference to featured attribute --- db/dev_seeds.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 99605b392..8f34fddd5 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -130,21 +130,21 @@ not_org_users = User.where(['users.id NOT IN(?)', org_user_ids]) puts " ✅" print "Creating Tags Categories" -ActsAsTaggableOn::Tag.create!(name: "Asociaciones", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Cultura", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Deportes", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Derechos Sociales", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Economía", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Empleo", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Equidad", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Sostenibilidad", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Participación", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Movilidad", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Medios", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category") +ActsAsTaggableOn::Tag.category.create!(name: "Asociaciones") +ActsAsTaggableOn::Tag.category.create!(name: "Cultura") +ActsAsTaggableOn::Tag.category.create!(name: "Deportes") +ActsAsTaggableOn::Tag.category.create!(name: "Derechos Sociales") +ActsAsTaggableOn::Tag.category.create!(name: "Economía") +ActsAsTaggableOn::Tag.category.create!(name: "Empleo") +ActsAsTaggableOn::Tag.category.create!(name: "Equidad") +ActsAsTaggableOn::Tag.category.create!(name: "Sostenibilidad") +ActsAsTaggableOn::Tag.category.create!(name: "Participación") +ActsAsTaggableOn::Tag.category.create!(name: "Movilidad") +ActsAsTaggableOn::Tag.category.create!(name: "Medios") +ActsAsTaggableOn::Tag.category.create!(name: "Salud") +ActsAsTaggableOn::Tag.category.create!(name: "Transparencia") +ActsAsTaggableOn::Tag.category.create!(name: "Seguridad y Emergencias") +ActsAsTaggableOn::Tag.category.create!(name: "Medio Ambiente") puts " ✅" print "Creating Debates" From a42c75647ea634fdd9ffc4155269dce53af8f1d0 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 16:23:15 +0200 Subject: [PATCH 10/11] Add migration to remove featured column from tags table --- db/migrate/20170623141655_remove_featured_from_tags.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20170623141655_remove_featured_from_tags.rb diff --git a/db/migrate/20170623141655_remove_featured_from_tags.rb b/db/migrate/20170623141655_remove_featured_from_tags.rb new file mode 100644 index 000000000..a819cf553 --- /dev/null +++ b/db/migrate/20170623141655_remove_featured_from_tags.rb @@ -0,0 +1,5 @@ +class RemoveFeaturedFromTags < ActiveRecord::Migration + def change + remove_column :tags, :featured, :boolean, default: false + end +end From dec6b67dba9b9bb098721999f3f51183ac4e77d6 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Fri, 23 Jun 2017 16:24:56 +0200 Subject: [PATCH 11/11] Update db/schema.rb --- db/schema.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 8fae3e8dd..98e563748 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170613203256) do +ActiveRecord::Schema.define(version: 20170623141655) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -832,7 +832,6 @@ ActiveRecord::Schema.define(version: 20170613203256) do create_table "tags", force: :cascade do |t| t.string "name", limit: 40 t.integer "taggings_count", default: 0 - t.boolean "featured", default: false t.integer "debates_count", default: 0 t.integer "proposals_count", default: 0 t.integer "spending_proposals_count", default: 0