#コマ\r
describe Panel do\r
before do\r
- FactoryGirl.create :admin\r
+ @admin = FactoryGirl.create :admin\r
@sp = FactoryGirl.create :system_picture\r
@lg = FactoryGirl.create :license_group\r
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
- @color = FactoryGirl.create :color
+ @color = FactoryGirl.create :color\r
@user = FactoryGirl.create( :user_yas)\r
- @author = @user.author\r
+ @author = FactoryGirl.create :author, :user_id => @user.id\r
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
@other_user = FactoryGirl.create( :user_yas)\r
- @other_author = @other_user.author\r
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id\r
@other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
@panel = FactoryGirl.build :panel, :author_id => @author.id\r
end\r
\r
- context 'オーソドックスなデータのとき' do
- it '下限データが通る' do
- @panel.width = 1
- @panel.height = 1
- @panel.border = 0
- @panel.x = -99999
- @panel.y = -99999
- @panel.z = 1
- @panel.publish = 0
- @panel.should be_valid
- end
- it '上限データが通る' do
- @panel.width = 99999
- @panel.height = 99999
- @panel.border = 99999
- @panel.x = 99999
- @panel.y = 99999
- @panel.z = 99999
- @panel.publish = 99999
- @panel.should be_valid
- end
- end
-
+ context 'オーソドックスなデータのとき' do\r
+ it '下限データが通る' do\r
+ @panel.width = 1\r
+ @panel.height = 1\r
+ @panel.border = 0\r
+ @panel.x = -99999\r
+ @panel.y = -99999\r
+ @panel.z = 1\r
+ @panel.publish = 0\r
+ @panel.should be_valid\r
+ end\r
+ it '上限データが通る' do\r
+ @panel.width = 99999\r
+ @panel.height = 99999\r
+ @panel.border = 99999\r
+ @panel.x = 99999\r
+ @panel.y = 99999\r
+ @panel.z = 99999\r
+ @panel.publish = 99999\r
+ @panel.should be_valid\r
+ end\r
+ end\r
+ \r
context 'widthを検証するとき' do\r
it 'nullなら失敗する' do\r
@panel.width = nil\r
\r
describe '作者判定に於いて' do\r
before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
it '自作のコマならyes' do\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.own?(@author).should == true\r
+ @panel.own?(@author).should == true\r
end\r
it '他人のコマならno' do\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.own?(@other_author).should == false\r
+ @panel.own?(@other_author).should == false\r
end\r
- it '作家が不明ならno' do\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.own?(nil).should == false\r
+ it 'パラメータが作家でないならno' do\r
+ @panel.own?(nil).should == false\r
end\r
end\r
\r
describe '閲覧許可に於いて' do\r
before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
- it '自作のコマを見るときは許可する' do\r
- Panel.any_instance.stub(:own?).and_return(true)\r
- Panel.any_instance.stub(:publish?).and_return(true)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == true\r
+ context '検査対象がnil(ゲスト)のとき' do\r
+ context 'クローズドモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ end\r
+ it '不許可を返す。' do\r
+ r = @panel.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
+ end\r
+ it '公開コマなら許可する' do\r
+ Panel.any_instance.stub(:publish?).and_return(true)\r
+ r = @panel.visible?(nil)\r
+ r.should be_true\r
+ end\r
+ it '非公開コマなら許可しない' do\r
+ Panel.any_instance.stub(:publish?).and_return(false)\r
+ r = @panel.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
end\r
- it '自作のコマは非公開でも許可する' do\r
- Panel.any_instance.stub(:own?).and_return(true)\r
- Panel.any_instance.stub(:publish?).and_return(false)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == true\r
- end\r
- it '他人のコマでも公開なら許可する' do\r
- Panel.any_instance.stub(:own?).and_return(false)\r
- Panel.any_instance.stub(:publish?).and_return(true)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == true\r
- end\r
- it '他人のコマで非公開なら許可しない' do\r
- Panel.any_instance.stub(:own?).and_return(false)\r
- Panel.any_instance.stub(:publish?).and_return(false)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == false\r
+ context '検査対象が作家のとき' do\r
+ it '自分のコマなら許可する' do\r
+ Panel.any_instance.stub(:own?).and_return(true)\r
+ Panel.any_instance.stub(:publish?).and_return(true)\r
+ r = @panel.visible?(@author)\r
+ r.should == true\r
+ end\r
+ it '他人の非公開コマなら許可しない' do\r
+ Panel.any_instance.stub(:own?).and_return(false)\r
+ Panel.any_instance.stub(:publish?).and_return(false)\r
+ r = @panel.visible?(@author)\r
+ r.should == false\r
+ end\r
+ it '他人のコマでも公開なら許可する' do\r
+ Panel.any_instance.stub(:own?).and_return(false)\r
+ Panel.any_instance.stub(:publish?).and_return(true)\r
+ r = @panel.visible?(@author)\r
+ r.should == true\r
+ end\r
+ end\r
+ context '検査対象がそれ以外のとき' do\r
+ it '不許可を返す。' do\r
+ r = @panel.visible?(@admin)\r
+ r.should be_false\r
+ end\r
end\r
end\r
\r
r.should eq [@panel]\r
end\r
it '時系列で並んでいる' do\r
- #公開コミックは(他人のコミックであっても)含んでいる
+ #公開コミックは(他人のコミックであっても)含んでいる\r
npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
r = Panel.list\r
r.should eq [npl, @panel]\r
pl.should eq [@panel]\r
end\r
end\r
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
@npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
@npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
@npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
@npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
Panel.stub(:default_page_size).and_return(2)\r
- end
- it '件数0は全件(5件)を返す' do
- r = Panel.list 5, 0
- r.should have(5).items
- end
- end
+ end\r
+ it '件数0は全件(5件)を返す' do\r
+ r = Panel.list 5, 0\r
+ r.should have(5).items \r
+ end\r
+ end\r
end\r
describe '一覧取得オプションに於いて' do\r
it 'includeキーを含んでいる' do\r
pl = Panel.mylist @author\r
pl.should eq [npl, @panel]\r
end\r
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
@npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
@npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
@npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
@npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
- end
+ end\r
it '通常は2件を返す' do\r
pl = Panel.list 1, 2\r
pl.should have(2).items \r
pl = Panel.mylist @author, 3, 2\r
pl.should eq [@panel]\r
end\r
- end
- context 'DBに5件あって1ページの件数を0件に変えたとして' do
- before do
+ end\r
+ context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
+ before do\r
@npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
@npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
@npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
@npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
Author.stub(:default_panel_page_size).and_return(2)\r
- end
- it '通常は全件(5件)を返す' do
- r = Panel.mylist @author, 5, 0
- r.should have(5).items
- end
- end
+ end\r
+ it '通常は全件(5件)を返す' do\r
+ r = Panel.mylist @author, 5, 0\r
+ r.should have(5).items \r
+ end\r
+ end\r
end\r
\r
describe '単体取得に於いて' do\r
it '単体取得オプションを利用している' do\r
Panel.stub(:show_opt).with(any_args).and_return({})\r
Panel.should_receive(:show_opt).with(any_args).exactly(1)\r
- r = Panel.show @panel.id, @author
+ r = Panel.show @panel.id, @author\r
end\r
it '閲覧許可を問い合わせている' do\r
Panel.any_instance.stub(:visible?).with(any_args).and_return(true)\r
Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
- r = Panel.show @panel.id, @author
+ r = Panel.show @panel.id, @author\r
end\r
end\r
it '指定のコマを返す' do\r
it '単体取得オプションを利用している' do\r
Panel.stub(:show_opt).with(any_args).and_return({})\r
Panel.should_receive(:show_opt).with(any_args).exactly(1)\r
- r = Panel.edit @panel.id, @author
+ r = Panel.edit @panel.id, @author\r
end\r
it '所持判定を問い合わせている' do\r
Panel.any_instance.stub(:own?).with(any_args).and_return(true)\r
Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
- r = Panel.edit @panel.id, @author
+ r = Panel.edit @panel.id, @author\r
end\r
end\r
it '指定のコマを返す' do\r
j.first.has_key?('p').should be_true\r
end\r
end\r
+ \r
+ describe 'ライセンス素材に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+ @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id)\r
+ )\r
+ @pc = @panel.panel_colors.create(\r
+ FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)\r
+ )\r
+ @panel.reload\r
+ end\r
+ context '事前チェック' do\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ end\r
+ it '連想配列(値は実素材、キーは実素材id)を返している' do\r
+ r = @panel.licensed_pictures\r
+ r.is_a?(Hash).should be_true\r
+ r.should have(2).items\r
+ r[@pp.picture_id].should eq @p\r
+ r[@gp.picture_id].should eq @p2\r
+ end\r
+ end\r
+ \r
describe '検証値収集に於いて' do\r
context 'つつがなく終わるとき' do\r
it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do\r
describe '保存に於いて' do\r
before do\r
@attr = FactoryGirl.attributes_for :panel\r
- @panel = Panel.new
- @panel.supply_default
+ @panel = Panel.new\r
+ @panel.supply_default\r
end\r
context 'つつがなく終わるとき' do\r
before do\r
FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)\r
)\r
@panel2.save!\r
- p @panel2\r
- p @panel2.panel_pictures\r
end\r
end\r
describe 'id一致チェックに於いて' do\r