X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fartists_controller_spec.rb;h=f36d7542d6a4840af970874bf77a7da0c6316f07;hb=cd7625bb17399ae415247f48b1aa0758518d425d;hp=7b929a7cdd8883ffad5dd588e7b3a4e457f74203;hpb=92e42b345715a552a4ce833b03ec68aed94792e0;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/artists_controller_spec.rb b/spec/controllers/artists_controller_spec.rb index 7b929a7c..f36d7542 100644 --- a/spec/controllers/artists_controller_spec.rb +++ b/spec/controllers/artists_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' describe ArtistsController do before do @admin = FactoryGirl.create :admin + @demand_user = FactoryGirl.create :demand_user @sp = FactoryGirl.create :system_picture @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @@ -85,7 +86,7 @@ if MagicNumber['run_mode'] == 1 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -110,6 +111,35 @@ if MagicNumber['run_mode'] == 1 end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + end end describe '閲覧に於いて' do @@ -152,7 +182,7 @@ if MagicNumber['run_mode'] == 1 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -177,6 +207,35 @@ if MagicNumber['run_mode'] == 1 end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @artist.id + response.should be_success + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @artist.id + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @artist.id + response.should be_success + end + end =begin context '対象作家がないとき' do context 'html形式' do @@ -197,6 +256,134 @@ if MagicNumber['run_mode'] == 1 =end end + describe '対象絵師の素材一覧表示に於いて' do + before do + @other_user = FactoryGirl.create( :user_yas) + @other_author = FactoryGirl.create :author, :user_id => @other_user.id + @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id + @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp]) + sign_in @user + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :resource_pictures, :id => @other_artist.id, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :resource_pictures, :id => @other_artist.id + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :resource_pictures, :id => @other_artist.id, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :resource_pictures, :id => @other_artist.id + assigns(:page_size).should eq Author.default_resource_picture_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :resource_pictures, :id => @other_artist.id, :page_size => 1500 + assigns(:page_size).should eq Author.resource_picture_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :resource_pictures, :id => @other_artist.id, :page_size => 0 + assigns(:page_size).should eq Author.default_resource_picture_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :resource_pictures, :id => @other_artist.id + response.should be_success + end + it '絵師モデルに単体取得を問い合わせている' do + Artist.should_receive(:show).exactly(1) + get :resource_pictures, :id => @other_artist.id + end + it '素材モデルに一覧を問い合わせている' do + ResourcePicture.should_receive(:mylist).exactly(1) + get :resource_pictures, :id => @other_artist.id + end + it '@resource_picturesにリストを取得している' do + get :resource_pictures, :id => @other_artist.id + assigns(:resource_pictures).should have_at_least(3).items + end + context 'html形式' do + it 'resource_pictureテンプレートを描画する' do + get :resource_pictures, :id => @other_artist.id + response.should render_template("resource_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :resource_pictures, :id => @other_artist.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it '素材モデルにコマリストのjson出力を問い合わせている' do + ResourcePicture.should_receive(:list_json_opt).exactly(1) + get :resource_pictures, :id => @other_artist.id, :format => :json + end + it 'データがリスト構造になっている' do + get :resource_pictures, :id => @other_artist.id, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいは素材っぽいものであって欲しい' do + get :resource_pictures, :id => @other_artist.id, :format => :json + json = JSON.parse response.body + json.first.has_key?("original_picture_id").should be_true + json.first.has_key?("license_id").should be_true + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :resource_pictures, :id => @other_artist.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :resource_pictures, :id => @other_artist.id + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :resource_pictures, :id => @other_artist.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :resource_pictures, :id => @other_artist.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :resource_pictures, :id => @other_artist.id + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @artist.destroy + end + it 'ステータスコード200 OKを返す' do + get :resource_pictures, :id => @other_artist.id + response.should be_success + end + end + end + describe '絵師数取得に於いて' do before do Artist.should_receive(:visible_count).and_return(3) @@ -261,7 +448,7 @@ if MagicNumber['run_mode'] == 1 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -296,6 +483,37 @@ if MagicNumber['run_mode'] == 1 end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :new + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + get :new + response.body.should redirect_to new_author_path + end + end + end end describe '新規作成に於いて' do @@ -360,7 +578,7 @@ if MagicNumber['run_mode'] == 1 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -385,6 +603,37 @@ if MagicNumber['run_mode'] == 1 end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, :artist => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, :artist => @attr + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, :artist => @attr + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + post :create, :artist => @attr + response.body.should redirect_to new_author_path + end + end + end context '検証、保存に失敗した' do before do Artist.any_instance.stub(:save).and_return(false) @@ -447,7 +696,7 @@ if MagicNumber['run_mode'] == 1 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -472,6 +721,37 @@ if MagicNumber['run_mode'] == 1 end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :edit, :id => @artist.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :edit, :id => @artist.id + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :edit, :id => @artist.id + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + get :edit, :id => @artist.id + response.body.should redirect_to new_author_path + end + end + end end describe '更新に於いて' do @@ -532,15 +812,15 @@ if MagicNumber['run_mode'] == 1 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end - it 'ステータスコード302 Foundを返す' do - put :update, :id => @artist.id, :artist => @attr - response.status.should eq 302 - end context 'html形式' do + it 'ステータスコード302 Foundを返す' do + put :update, :id => @artist.id, :artist => @attr + response.status.should eq 302 + end it 'サインインページへ遷移する' do put :update, :id => @artist.id, :artist => @attr response.body.should redirect_to '/users/sign_in' @@ -553,6 +833,37 @@ if MagicNumber['run_mode'] == 1 end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + put :update, :id => @artist.id, :artist => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + put :update, :id => @artist.id, :artist => @attr + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + put :update, :id => @artist.id, :artist => @attr + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + put :update, :id => @artist.id, :artist => @attr + response.body.should redirect_to new_author_path + end + end + end context '検証、保存に失敗したとき' do before do Artist.any_instance.stub(:save).and_return(false) @@ -605,7 +916,7 @@ else end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -651,7 +962,7 @@ else end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -674,6 +985,58 @@ else end end + describe '対象絵師の素材一覧表示に於いて' do + before do + @other_user = FactoryGirl.create( :user_yas) + @other_author = FactoryGirl.create :author, :user_id => @other_user.id + @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id + @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp]) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :resource_pictures, :id => @other_artist.id + response.should be_success + end + context 'html形式' do + it 'resource_pictureテンプレートを描画する' do + get :resource_pictures, :id => @other_artist.id + response.should render_template("resource_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :resource_pictures, :id => @other_artist.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + it 'ステータスコード200 OKを返す' do + get :resource_pictures, :id => @other_artist.id + response.should be_success + end + context 'html形式' do + it 'resource_pictureテンプレートを描画する' do + get :resource_pictures, :id => @other_artist.id + response.should render_template("resource_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :resource_pictures, :id => @other_artist.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + end + describe '絵師数取得に於いて' do before do Artist.should_receive(:visible_count).and_return(3) @@ -721,7 +1084,7 @@ else end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -788,7 +1151,7 @@ else end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -838,7 +1201,7 @@ else end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -895,7 +1258,7 @@ else end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end