X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=spec%2Fmodels%2Fauthor_spec.rb;h=dfc036ecc805856f2937deadcf88917c54d616ea;hp=c90208e875384d22897a41363d6783815e6bbf72;hb=2bd8e046bbbdd6d620af0637c3291cc7d787b0c5;hpb=c1ce32fbd93b9412ac557fe4d2e53887708caafd diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index c90208e8..dfc036ec 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -6,7 +6,7 @@ describe Author do before do @admin = FactoryGirl.create :admin @user = FactoryGirl.create( :user_yas) - @author = @user.author + @author = FactoryGirl.create :author, :user_id => @user.id end describe '検証に於いて' do @@ -64,7 +64,7 @@ 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 = FactoryGirl.create :author_yas, :user_id => @other_user.id end it '作家自身ならyes' do @author.own?(@author).should == true @@ -85,33 +85,33 @@ describe Author do before do MagicNumber['run_mode'] = 1 end - it '不許可を返す。' do + it '不許可を返す。' do r = @author.visible?(nil) r.should be_false - end - end + end + end context 'オープンモードのとき' do before do MagicNumber['run_mode'] = 0 end - it '許可する' do + it '許可する' do r = @author.visible?(nil) r.should be_true - end - end - end + end + end + end context '検査対象が作家のとき' do - it '許可する' do + it '許可する' do r = @author.visible?(@author) r.should == true - end - end + end + end context '検査対象がそれ以外のとき' do - it '不許可を返す。' do + it '不許可を返す。' do r = @author.visible?(@admin) r.should be_false - end - end + end + end end describe '絵師作家判定に於いて' do @@ -158,20 +158,20 @@ describe Author do Author.page_size('1000').should eq Author.max_page_size end end - context 'つつがなく終わるとき' do - it '一覧取得オプションを利用している' do - Author.stub(:list_opt).with(any_args).and_return({}) - Author.should_receive(:list_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + Author.stub(:list_opt).with(any_args).and_return({}) + Author.should_receive(:list_opt).with(any_args).exactly(1) r = Author.list - end - end + end + end it 'リストを返す' do r = Author.list r.should eq [@author] end it '作成時系列で並んでいる' do @other_user = FactoryGirl.create :user_yas - #アカウントを作ると連動して作家ができる + @other_author = FactoryGirl.create :author, :user_id => @other_user.id n = @other_user.author n.created_at = Time.now + 100 n.save @@ -181,19 +181,19 @@ describe Author do context 'DBに5件あって1ページの件数を2件に変えたとして' do before do @other_user2 = FactoryGirl.create :user_yas - @author2 = @other_user2.author + @author2 = FactoryGirl.create :author, :user_id => @other_user2.id @author2.created_at = Time.now + 100 @author2.save @other_user3 = FactoryGirl.create :user_yas - @author3 = @other_user3.author + @author3 = FactoryGirl.create :author, :user_id => @other_user3.id @author3.created_at = Time.now + 200 @author3.save @other_user4 = FactoryGirl.create :user_yas - @author4 = @other_user4.author + @author4 = FactoryGirl.create :author, :user_id => @other_user4.id @author4.created_at = Time.now + 300 @author4.save @other_user5 = FactoryGirl.create :user_yas - @author5 = @other_user5.author + @author5 = FactoryGirl.create :author, :user_id => @other_user5.id @author5.created_at = Time.now + 400 @author5.save Author.stub(:default_page_size).and_return(2) @@ -219,19 +219,19 @@ describe Author do context 'DBに5件あって1ページの件数を0件に変えたとして' do before do @other_user2 = FactoryGirl.create :user_yas - @author2 = @other_user2.author + @author2 = FactoryGirl.create :author, :user_id => @other_user2.id @author2.created_at = Time.now + 100 @author2.save @other_user3 = FactoryGirl.create :user_yas - @author3 = @other_user3.author + @author3 = FactoryGirl.create :author, :user_id => @other_user3.id @author3.created_at = Time.now + 200 @author3.save @other_user4 = FactoryGirl.create :user_yas - @author4 = @other_user4.author + @author4 = FactoryGirl.create :author, :user_id => @other_user4.id @author4.created_at = Time.now + 300 @author4.save @other_user5 = FactoryGirl.create :user_yas - @author5 = @other_user5.author + @author5 = FactoryGirl.create :author, :user_id => @other_user5.id @author5.created_at = Time.now + 400 @author5.save Author.stub(:default_page_size).and_return(2) @@ -271,53 +271,53 @@ describe Author do describe '単体取得に於いて' do before do end - context 'つつがなく終わるとき' do - it '単体取得オプションを利用している' do - Author.stub(:show_opt).with(any_args).and_return({}) - Author.should_receive(:show_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Author.stub(:show_opt).with(any_args).and_return({}) + Author.should_receive(:show_opt).with(any_args).exactly(1) r = Author.show @author.id, @author - end - it '閲覧許可を問い合わせている' do - Author.any_instance.stub(:visible?).with(any_args).and_return(true) - Author.any_instance.should_receive(:visible?).with(any_args).exactly(1) + end + it '閲覧許可を問い合わせている' do + Author.any_instance.stub(:visible?).with(any_args).and_return(true) + Author.any_instance.should_receive(:visible?).with(any_args).exactly(1) r = Author.show @author.id, @author - end - end + end + end it '指定の作家を返す' do r = Author.show @author.id, @author r.should eq @author end - context '閲覧許可が出なかったとき' do - it '403Forbidden例外を返す' do - Author.any_instance.stub(:visible?).and_return(false) - lambda{ - Author.show @author.id, @author - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しない作家を開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Author.show 110, @author - }.should raise_error(ActiveRecord::RecordNotFound) - end - end + context '閲覧許可が出なかったとき' do + it '403Forbidden例外を返す' do + Author.any_instance.stub(:visible?).and_return(false) + lambda{ + Author.show @author.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない作家を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Author.show 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end end describe '編集取得に於いて' do before do end - context 'つつがなく終わるとき' do - it '単体取得オプションを利用している' do - Author.stub(:show_opt).with(any_args).and_return({}) - Author.should_receive(:show_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Author.stub(:show_opt).with(any_args).and_return({}) + Author.should_receive(:show_opt).with(any_args).exactly(1) r = Author.edit @author.id, @author - end - it '所持判定を問い合わせている' do - Author.any_instance.stub(:own?).with(any_args).and_return(true) - Author.any_instance.should_receive(:own?).with(any_args).exactly(1) + end + it '所持判定を問い合わせている' do + Author.any_instance.stub(:own?).with(any_args).and_return(true) + Author.any_instance.should_receive(:own?).with(any_args).exactly(1) r = Author.edit @author.id, @author - end - end + end + end it '指定の作家を返す' do Author.any_instance.stub(:own?).and_return(true) r = Author.edit @author.id, @author.id