X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=spec%2Fmodels%2Fauthor_spec.rb;fp=spec%2Fmodels%2Fauthor_spec.rb;h=75506114a1457b8c34d090316d075312a3a5aba1;hp=f8399194059ee419b1b844f6181ecb3dd65d982f;hb=135599effaad9a0b15ad52e46355e885ec0ddc94;hpb=3e64a37b6628a081b06eb7278506fcc10d6a3d34 diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index f8399194..75506114 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -64,54 +64,87 @@ describe Author do describe '所持判定に於いて' do before do @other_user = FactoryGirl.create :user_yas -#アカウントを作ると連動して作家ができる @other_author = FactoryGirl.create :author_yas, :user_id => @other_user.id + @other_author = @other_user.author end - it '作家自身ならyes' do - @author.own?(@author).should == true + context '事前チェックする' do + it '自身にロールリストからの作家取得を依頼している' do + Author.should_receive(:get_author_from_roles).with(any_args).exactly(1) + r = @author.own?([@author]) + end end - it '作家自身でなければno' do - @author.own?(@other_author).should == false + context 'ロール内作家が取得できるとき' do + before do + end + it 'ロール内作家のidが自身の作家idと一致するなら許可する' do + Author.stub(:get_author_from_roles).with(any_args).and_return(@author) + r = @author.own?([@author]) + r.should be_true + end + it 'ロール内作家のidが自身の作家idと一致しないならno' do + Author.stub(:get_author_from_roles).with(any_args).and_return(@other_author) + @author.own?(@other_author).should be_false + end end - it 'パラメータが作家でないならno' do - @author.own?(nil).should == false + context 'ロール内作家が取得できないとき' do + before do + Author.stub(:get_author_from_roles).with(any_args).and_return(nil) + end + it 'Falseを返す' do + r = @author.own?([@author]) + r.should be_false + end end end describe '閲覧許可に於いて' do before do end - context '検査対象がnil(ゲスト)のとき' do - context 'クローズドモードのとき' do - before do - MagicNumber['run_mode'] = 1 - end - it '不許可を返す。' do - r = @author.visible?(nil) - r.should be_false - end - end - context 'オープンモードのとき' do - before do - MagicNumber['run_mode'] = 0 - end - it '許可する' do - r = @author.visible?(nil) - r.should be_true - end - end - end - context '検査対象が作家のとき' do - it '許可する' do - r = @author.visible?(@author) - r.should == true + context 'オープンモードのとき' do + before do + MagicNumber['run_mode'] = 0 + end + it '自身にゲスト用ロールチェックを問い合わせしている' do + Author.any_instance.stub(:guest_role_check).and_return(true) + Author.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1) + r = @author.visible?([@author]) + end + it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do + Author.any_instance.stub(:guest_role_check).and_return(false) + r = @author.visible?([@author]) + r.should be_false end end - context '検査対象がそれ以外のとき' do - it '不許可を返す。' do - r = @author.visible?(@admin) + context 'クローズドモードのとき' do + before do + MagicNumber['run_mode'] = 1 + end + it '自身に読者用ロールチェックを問い合わせしている' do + Author.any_instance.stub(:reader_role_check).and_return(true) + Author.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1) + r = @author.visible?([@author]) + end + it '読者用ロールチェックが失敗したとき、falseを返す' do + Author.any_instance.stub(:reader_role_check).and_return(false) + r = @author.visible?([@author]) r.should be_false end end + context '事前チェックする' do + before do + MagicNumber['run_mode'] = 1 + Author.any_instance.stub(:reader_role_check).and_return(true) + end + end + context 'つつがなく終わるとき' do + before do + MagicNumber['run_mode'] = 1 + Author.any_instance.stub(:reader_role_check).and_return(true) + end + it '許可する' do + r = @author.visible?([@author]) + r.should be_true + end + end end describe '絵師作家判定に於いて' do