before do
@admin = FactoryGirl.create :admin
@user = FactoryGirl.create( :user_yas)
- @author = @user.author
- @other_user = FactoryGirl.create( :user_yas)\r
- @other_author = @other_user.author\r
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @other_user = FactoryGirl.create( :user_yas)
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
describe '所持判定に於いて' do
before do
@artist = FactoryGirl.create :artist, :author_id => @author.id
- @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
+ @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
end
- it '自分の絵師ならyes' do
- @artist.own?(@author).should == true
+ context '事前チェックする' do
+ it '自身にロールリストからの作家取得を依頼している' do
+ Artist.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+ r = @artist.own?([@author])
+ end
end
- it '他人の絵師ならno' do
- @artist.own?(@other_author).should == false
+ context 'ロール内作家が取得できるとき' do
+ before do
+ end
+ it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+ Artist.stub(:get_author_from_roles).with(any_args).and_return(@author)
+ r = @artist.own?([@author])
+ r.should be_true
+ end
+ it 'ロール内作家のidが自身の作家idと一致しないならno' do
+ Artist.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+ @artist.own?(@other_author).should be_false
+ end
end
- it 'パラメータが作家でないならならno' do
- @artist.own?(nil).should == false
+ context 'ロール内作家が取得できないとき' do
+ before do
+ Artist.stub(:get_author_from_roles).with(any_args).and_return(nil)
+ end
+ it 'Falseを返す' do
+ r = @artist.own?([@author])
+ r.should be_false
+ end
end
end
before do
@artist = FactoryGirl.create :artist, :author_id => @author.id
end
- context '検査対象がnil(ゲスト)のとき' do
- context 'クローズドモードのとき' do
- before do
- MagicNumber['run_mode'] = 1
- end
- it '不許可を返す。' do\r
- r = @artist.visible?(nil)
- r.should be_false
- end\r
- end\r
- context 'オープンモードのとき' do
- before do
- MagicNumber['run_mode'] = 0
- end
- it '許可する' do\r
- r = @artist.visible?(nil)
- r.should be_true
- end\r
- end\r
- end\r
- context '検査対象が作家のとき' do
- it '許可する' do\r
- r = @artist.visible?(@author)
- r.should == true
- end\r
- end\r
- context '検査対象がそれ以外のとき' do
- it '不許可を返す。' do\r
- r = @artist.visible?(@admin)
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '自身にゲスト用ロールチェックを問い合わせしている' do
+ Artist.any_instance.stub(:guest_role_check).and_return(true)
+ Artist.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+ r = @artist.visible?([@author])
+ end
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+ Artist.any_instance.stub(:guest_role_check).and_return(false)
+ r = @artist.visible?([@author])
+ r.should be_false
+ end
+ end
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '自身に素材読者用ロールチェックを問い合わせしている' do
+ Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
+ Artist.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)
+ r = @artist.visible?([@author])
+ end
+ it '素材読者用ロールチェックが失敗したとき、falseを返す' do
+ Artist.any_instance.stub(:resource_reader_role_check).and_return(false)
+ r = @artist.visible?([@author])
r.should be_false
- end\r
- end\r
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
+ end
+ it '許可する' do
+ r = @artist.visible?([@author])
+ r.should be_true
+ end
+ end
end
describe '一覧取得に於いて' do
Artist.page_size('1000').should eq Artist.max_page_size
end
end
- context 'つつがなく終わるとき' do\r
- it '一覧取得オプションを利用している' do\r
- Artist.stub(:list_opt).with(any_args).and_return({})\r
- Artist.should_receive(:list_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ Artist.stub(:list_opt).with(any_args).and_return({})
+ Artist.should_receive(:list_opt).with(any_args).exactly(1)
r = Artist.list
- end\r
- end\r
+ end
+ end
it 'リストを返す' do
r = Artist.list
r.should eq [@artist]
before do
@artist = FactoryGirl.create :artist, :author_id => @author.id
end
- context 'つつがなく終わるとき' do\r
- it '単体取得オプションを利用している' do\r
- Artist.stub(:show_opt).with(any_args).and_return({})\r
- Artist.should_receive(:show_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ Artist.stub(:show_opt).with(any_args).and_return({})
+ Artist.should_receive(:show_opt).with(any_args).exactly(1)
r = Artist.show @artist.id, @author
- end\r
- it '閲覧許可を問い合わせている' do\r
- Artist.any_instance.stub(:visible?).with(any_args).and_return(true)\r
- Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+ end
+ it '閲覧許可を問い合わせている' do
+ Artist.any_instance.stub(:visible?).with(any_args).and_return(true)
+ Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)
r = Artist.show @artist.id, @author
- end\r
- end\r
+ end
+ end
it '指定の絵師を返す' do
a = Artist.show @artist.id, @author
a.should eq @artist
end
- context '閲覧許可が出なかったとき' do\r
- it '403Forbidden例外を返す' do\r
- Artist.any_instance.stub(:visible?).and_return(false)\r
- lambda{\r
- Artist.show @artist.id, @author\r
- }.should raise_error(ActiveRecord::Forbidden)\r
- end\r
- end\r
- context '存在しない絵師を開こうとしたとき' do\r
- it '404RecordNotFound例外を返す' do\r
- lambda{\r
- Artist.show 110, @author\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ Artist.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ Artist.show @artist.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない絵師を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ Artist.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
end
describe '編集取得に於いて' do
before do
@artist = FactoryGirl.create :artist, :author_id => @author.id
end
- context 'つつがなく終わるとき' do\r
- it '単体取得オプションを利用している' do\r
- Artist.stub(:show_opt).with(any_args).and_return({})\r
- Artist.should_receive(:show_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ Artist.stub(:show_opt).with(any_args).and_return({})
+ Artist.should_receive(:show_opt).with(any_args).exactly(1)
r = Artist.edit @artist.id, @author
- end\r
- it '所持判定を問い合わせている' do\r
- Artist.any_instance.stub(:own?).with(any_args).and_return(true)\r
- Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+ end
+ it '所持判定を問い合わせている' do
+ Artist.any_instance.stub(:own?).with(any_args).and_return(true)
+ Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)
r = Artist.edit @artist.id, @author
- end\r
- end\r
+ end
+ end
it '指定の絵師を返す' do
Artist.any_instance.stub(:own?).and_return(true)
r = Artist.edit @artist.id, @author.id