From 92e1cbf63d7c8f056d5ea2dbe130d34c68443510 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 27 Jan 2011 12:39:19 +0100 Subject: [PATCH 1/2] Public tables tags --- app/controllers/admin/tables_controller.rb | 14 +++----------- app/models/tag.rb | 19 +++++++++++++++++++ spec/acceptance/dashboard_spec.rb | 5 +++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/tables_controller.rb b/app/controllers/admin/tables_controller.rb index 4b1f19366f..07d972b9c2 100644 --- a/app/controllers/admin/tables_controller.rb +++ b/app/controllers/admin/tables_controller.rb @@ -8,19 +8,11 @@ class Admin::TablesController < ApplicationController current_page = params[:page].nil? ? 1 : params[:page].to_i per_page = 10 unless params[:public] - @tags = Tag.fetch("select tags.name, count(*) as count - from tags - where tags.user_id = ? - group by tags.name - order by count desc limit 5", current_user.id).all + @tags = Tag.load_user_tags(current_user.id, :limit => 5) @tables = Table.filter(:user_id => current_user.id).order(:id).reverse.select(:id,:name,:privacy,:updated_at,:tags). - paginate(current_page, per_page, current_user.tables_count) + paginate(current_page, per_page, current_user.tables_count) else - @tags = Tag.fetch("select tags.name, count(*) as count - from tags - where tags.user_id != ? - group by tags.name - order by count desc limit 5", current_user.id).all + @tags = Tag.load_public_tags(current_user.id, :limit => 5) @tables = Table.filter(~{:user_id => current_user.id} & {:privacy => Table::PUBLIC}).order(:id).reverse. select(:id,:name,:privacy,:updated_at,:tags).paginate(current_page, per_page) render :template => 'admin/tables/index_public' and return diff --git a/app/models/tag.rb b/app/models/tag.rb index f84edf2438..495940f4c0 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -6,4 +6,23 @@ class Tag < Sequel::Model # Allowed columns set_allowed_columns(:name) + def self.load_user_tags(user_id, options = {}) + options[:limit] ||= 5 + fetch("select tags.name, count(*) as count + from tags + where tags.user_id = ? + group by tags.name + order by count desc limit 5", user_id).all + end + + def self.load_public_tags(user_id, options = {}) + options[:limit] ||= 5 + fetch("select tags.name, count(*) as count + from tags + inner join user_tables on user_tables.id = tags.table_id and user_tables.privacy = #{Table::PUBLIC} + where tags.user_id != ? + group by tags.name + order by count desc limit 5", user_id).all + end + end diff --git a/spec/acceptance/dashboard_spec.rb b/spec/acceptance/dashboard_spec.rb index fc9da177ee..6191bdca56 100644 --- a/spec/acceptance/dashboard_spec.rb +++ b/spec/acceptance/dashboard_spec.rb @@ -184,6 +184,11 @@ feature "Dashboard", %q{ page.should have_content("21 Public tables in cartoDB") + page.should have_content("BROWSE BY TAGS") + page.should have_css("ul li:eq(1) a span", :text => "vodka") + page.should have_css("ul li a span", :text => "restaurants") + page.should have_no_css("ul li a span", :text => "drinking") + within("ul.your_tables li:eq(1)") do page.should have_link("Favourite restaurants") page.should have_content("PUBLIC") From 937963994bfe69786b5f9a0e7dd2a2815d32b6a3 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 27 Jan 2011 13:02:22 +0100 Subject: [PATCH 2/2] Specs for table modification --- spec/acceptance/tables_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/acceptance/tables_spec.rb diff --git a/spec/acceptance/tables_spec.rb b/spec/acceptance/tables_spec.rb new file mode 100644 index 0000000000..e5cb29c477 --- /dev/null +++ b/spec/acceptance/tables_spec.rb @@ -0,0 +1,29 @@ +require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper') + +feature "Tables" do + + background do + @user = create_user + @table = create_table :user_id => @user.id, :name => 'Twitter followers', :privacy => Table::PUBLIC + + login_as @user + + click_link_or_button("Twitter followers") + end + + scenario "Toggle the privacy of a table" do + # Toggle to private + click_link_or_button("PUBLIC") + page.find("span.privacy_window ul li.private a").click + + page.should have_css("p.status", :text => 'private') + page.find("div.performing_op p.success").text.should == 'The status has been changed' + + # Toggle to public + page.find("p.status a").click + page.find("span.privacy_window ul li.public a").click + + page.should have_css("p.status", :text => 'public') + page.find("div.performing_op p.success").text.should == 'The status has been changed' + end +end