From 9837735c93922a0d614ba9eec73a31df68ab24e9 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 31 Jan 2011 01:55:40 -0500 Subject: [PATCH] added tag subscription functional test --- .../tag_subscriptions_controller.rb | 2 +- app/views/tag_subscriptions/edit.html.erb | 0 app/views/tag_subscriptions/index.html.erb | 0 app/views/tag_subscriptions/new.html.erb | 0 db/development_structure.sql | 2 +- test/factories/tag_subscription.rb | 3 +- .../tag_subscriptions_controller_test.rb | 71 ++++++++++++++++++- 7 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 app/views/tag_subscriptions/edit.html.erb create mode 100644 app/views/tag_subscriptions/index.html.erb create mode 100644 app/views/tag_subscriptions/new.html.erb diff --git a/app/controllers/tag_subscriptions_controller.rb b/app/controllers/tag_subscriptions_controller.rb index ee4d642b4..97d3e21c5 100644 --- a/app/controllers/tag_subscriptions_controller.rb +++ b/app/controllers/tag_subscriptions_controller.rb @@ -15,7 +15,7 @@ class TagSubscriptionsController < ApplicationController end def index - @search = TagSubscription.search(params[:search]).visible + @search = TagSubscription.visible.search(params[:search]) @tag_subscriptions = @search.paginate(:page => params[:page]) respond_with(@tag_subscriptions) end diff --git a/app/views/tag_subscriptions/edit.html.erb b/app/views/tag_subscriptions/edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tag_subscriptions/index.html.erb b/app/views/tag_subscriptions/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tag_subscriptions/new.html.erb b/app/views/tag_subscriptions/new.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/db/development_structure.sql b/db/development_structure.sql index 2c5389b9d..0f23676fb 100644 --- a/db/development_structure.sql +++ b/db/development_structure.sql @@ -1321,7 +1321,7 @@ CREATE TABLE tag_subscriptions ( name character varying(255) NOT NULL, tag_query character varying(255) NOT NULL, post_ids text NOT NULL, - is_visible_on_profile boolean DEFAULT true NOT NULL, + is_public boolean DEFAULT true NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone ); diff --git a/test/factories/tag_subscription.rb b/test/factories/tag_subscription.rb index 8cbc74153..3c1dec0ca 100644 --- a/test/factories/tag_subscription.rb +++ b/test/factories/tag_subscription.rb @@ -1,5 +1,4 @@ Factory.define(:tag_subscription) do |f| - f.owner {|x| x.association(:user)} f.name {Faker::Lorem.words.join(" ")} - f.is_visible_on_profile true + f.is_public true end diff --git a/test/functional/tag_subscriptions_controller_test.rb b/test/functional/tag_subscriptions_controller_test.rb index a96b4f684..120806a03 100644 --- a/test/functional/tag_subscriptions_controller_test.rb +++ b/test/functional/tag_subscriptions_controller_test.rb @@ -1,8 +1,73 @@ require 'test_helper' class TagSubscriptionsControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + context "The tag subscriptions controller" do + setup do + @user = Factory.create(:user) + CurrentUser.user = @user + CurrentUser.ip_addr = "127.0.0.1" + end + + teardown do + CurrentUser.user = nil + CurrentUser.ip_addr = nil + end + + context "index action" do + setup do + @tag_subscription = Factory.create(:tag_subscription, :name => "aaa", :owner => @user) + end + + should "list all visible tag subscriptions" do + get :index + assert_response :success + end + + context "with search conditions" do + should "list all matching forum posts" do + get :index, {:search => {:name_equals => "aaa"}} + assert_response :success + assert_equal(1, assigns(:tag_subscriptions).size) + end + end + end + + context "edit action" do + setup do + @tag_subscription = Factory.create(:tag_subscription, :owner => @user) + end + + should "render" do + get :edit, {:id => @tag_subscription.id}, {:user_id => @user.id} + assert_response :success + end + end + + context "new action" do + should "render" do + get :new, {}, {:user_id => @user.id} + assert_response :success + end + end + + context "create action" do + should "create a new tag subscription" do + assert_difference("TagSubscription.count", 1) do + post :create, {:tag_subscription => {:name => "aaa", :tag_query => "bbb"}}, {:user_id => @user.id} + end + end + end + + context "destroy action" do + setup do + @tag_subscription = Factory.create(:tag_subscription) + end + + should "destroy the posts" do + assert_difference("TagSubscription.count", -1) do + post :destroy, {:id => @tag_subscription.id}, {:user_id => @user.id} + end + end + end end end