tests: add favorite groups controller tests.
This commit is contained in:
@@ -120,7 +120,7 @@ class FavoriteGroup < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize_creator
|
def initialize_creator
|
||||||
self.creator_id = CurrentUser.id
|
self.creator_id ||= CurrentUser.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def strip_name
|
def strip_name
|
||||||
@@ -214,6 +214,7 @@ class FavoriteGroup < ActiveRecord::Base
|
|||||||
super
|
super
|
||||||
@neighbor_posts = nil
|
@neighbor_posts = nil
|
||||||
clear_post_id_array
|
clear_post_id_array
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_page
|
def last_page
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory(:favorite_group) do
|
factory :favorite_group do
|
||||||
|
name { FFaker::Lorem.word }
|
||||||
|
creator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory(:user) do
|
factory(:user, aliases: [:creator, :updater]) do
|
||||||
name {(rand(1_000_000) + 10).to_s}
|
name {(rand(1_000_000) + 10).to_s}
|
||||||
password "password"
|
password "password"
|
||||||
password_hash {User.sha1("password")}
|
password_hash {User.sha1("password")}
|
||||||
|
|||||||
81
test/functional/favorite_groups_controller_test.rb
Normal file
81
test/functional/favorite_groups_controller_test.rb
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class FavoriteGroupsControllerTest < ActionController::TestCase
|
||||||
|
context "The favorite groups controller" do
|
||||||
|
setup do
|
||||||
|
@user = FactoryGirl.create(:user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
should "render" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "show action" do
|
||||||
|
should "render" do
|
||||||
|
favgroup = FactoryGirl.create(:favorite_group)
|
||||||
|
|
||||||
|
get :show, { id: favgroup.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 "render" do
|
||||||
|
post :create, { favorite_group: FactoryGirl.attributes_for(:favorite_group) }, { user_id: @user.id }
|
||||||
|
assert_redirected_to favorite_groups_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "edit action" do
|
||||||
|
should "render" do
|
||||||
|
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||||
|
|
||||||
|
get :edit, { id: favgroup.id }, { user_id: @user.id }
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
should "render" do
|
||||||
|
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||||
|
params = { id: favgroup.id, favorite_group: { name: "foo" } }
|
||||||
|
|
||||||
|
put :update, params, { user_id: @user.id }
|
||||||
|
assert_redirected_to favgroup
|
||||||
|
assert_equal("foo", favgroup.reload.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
should "render" do
|
||||||
|
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||||
|
|
||||||
|
delete :destroy, { id: favgroup.id }, { user_id: @user.id }
|
||||||
|
assert_redirected_to favorite_groups_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "add_post action" do
|
||||||
|
should "render" do
|
||||||
|
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||||
|
post = FactoryGirl.create(:post)
|
||||||
|
|
||||||
|
put :add_post, { id: favgroup.id, post_id: post.id, format: "js" }, { user_id: @user.id }
|
||||||
|
assert_response :success
|
||||||
|
assert_equal([post.id], favgroup.reload.post_id_array)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user