# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの画像背景
+#絵地
describe GroundPicture do
before do
- FactoryGirl.create :admin
+ @admin = FactoryGirl.create :admin
@user = FactoryGirl.create( :user_yas)
- @author = @user.author
+ @author = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@other_user = FactoryGirl.create( :user_yas)
- @other_author = @other_user.author
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
end
end
-
context 'panel_idを検証するとき' do
#ネストの保存はnilを許可しなければならないので数値チェックだけ
it '数値でなければ失敗する' do
end
end
+ describe '閲覧許可に於いて' do
+ before do
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ end
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do
+ r = @gp.visible?(nil)
+ r.should be_false
+ end
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開されたコマの絵地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @gp.visible?(nil)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gp.visible?(nil)
+ r.should be_false
+ end
+ end
+ end
+ context '検査対象が作家のとき' do
+ it '公開されたコマの絵地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @gp.visible?(@author)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gp.visible?(@author)
+ r.should be_false
+ end
+ end
+ context '検査対象が管理者のとき' do
+ it '許可を返す。' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gp.visible?(@admin)
+ r.should be_true
+ end
+ end
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do
+ r = @gp.visible?(1)
+ r.should be_false
+ end
+ end
+ end
describe '一覧取得に於いて' do
before do
@gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
pl = GroundPicture.list
pl.should eq [npl, @gp]
end
- it '非公開のコマの景色は含まない' do
+ it '非公開のコマの絵地は含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
pl = GroundPicture.list
end
end
- describe '自分のコマで使った景色画像一覧取得に於いて' do
+ describe '自分のコマで使った絵地一覧取得に於いて' do
before do
@gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
end
pl = GroundPicture.mylist @author
pl.should eq [npl, @gp]
end
- it '他人のコマの景色は公開でも含まない' do
+ it '他人のコマの絵地は公開でも含まない' do
hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
pl = GroundPicture.mylist @author
pl.should eq [@gp]
end
- it '自分のコマの景色は非公開でも含んでいる' do
+ it '自分のコマの絵地は非公開でも含んでいる' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
pl = GroundPicture.mylist @author
end
end
+ describe '単体取得に於いて' do
+ before do
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ GroundPicture.should_receive(:show_opt).with(any_args).exactly(1)
+ r = GroundPicture.show @gp.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
+ GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = GroundPicture.show @gp.id, @author
+ end
+ end
+ it '指定の絵地を返す' do
+ GroundPicture.any_instance.stub(:visible?).and_return(true)
+ pl = GroundPicture.show @gp.id, @author
+ pl.should eq @gp
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ GroundPicture.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ GroundPicture.show @gp.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない絵地を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ GroundPicture.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = GroundPicture.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r.should have(2).items
+ end
+ it 'コマを含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it '実素材を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r.has_key?(:picture).should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r[:picture].has_key?(:artist).should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r[:picture].has_key?(:license).should be_true
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ before do
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ end
+ it 'コマを含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '実素材を含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('picture').should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j['picture']
+ i.has_key?('artist').should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j['picture']
+ i.has_key?('license').should be_true
+ end
+ end
end