# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの背景間接
+#選択色地
describe GroundColor 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
+ describe '閲覧許可に於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '自身にゲスト用ロールチェックを問い合わせしている' do
+ GroundColor.any_instance.stub(:guest_role_check).and_return(true)
+ GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+ r = @gc.visible?([@author])
+ end
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+ GroundColor.any_instance.stub(:guest_role_check).and_return(false)
+ r = @gc.visible?([@author])
+ r.should be_false
+ end
+ end
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '自身に読者用ロールチェックを問い合わせしている' do
+ GroundColor.any_instance.stub(:reader_role_check).and_return(true)
+ GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+ r = @gc.visible?([@author])
+ end
+ it '読者用ロールチェックが失敗したとき、falseを返す' do
+ GroundColor.any_instance.stub(:reader_role_check).and_return(false)
+ r = @gc.visible?([@author])
+ r.should be_false
+ end
+ end
+ context '事前チェックする' do
+ before do
+ MagicNumber['run_mode'] = 1
+ GroundColor.any_instance.stub(:reader_role_check).and_return(true)
+ end
+ it '自身のコマに所持判定を問い合わせしている' do
+ Panel.any_instance.stub(:own?).and_return(true)
+ Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+ r = @gc.visible?([@author])
+ end
+ it '自身のコマに閲覧許可を問い合わせしている' do
+ Panel.any_instance.stub(:own?).and_return(false)
+ Panel.any_instance.stub(:visible?).and_return(true)
+ Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = @gc.visible?([@author])
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ Panel.any_instance.stub(:reader_role_check).and_return(true)
+ end
+ it '自分のコマの選択色地なら許可する' do
+ Panel.any_instance.stub(:own?).and_return(true)
+ Panel.any_instance.stub(:visible?).and_return(false)
+ r = @gc.visible?([@author])
+ r.should be_true
+ end
+ it '他人の非公開コマの選択色地なら許可しない' do
+ Panel.any_instance.stub(:own?).and_return(false)
+ Panel.any_instance.stub(:visible?).and_return(false)
+ r = @gc.visible?([@author])
+ r.should be_false
+ end
+ it '他人のコマの選択色地でも公開なら許可する' do
+ Panel.any_instance.stub(:own?).and_return(false)
+ Panel.any_instance.stub(:visible?).and_return(true)
+ r = @gc.visible?([@author])
+ r.should be_true
+ end
+ end
+ end
+
describe '一覧取得に於いて' do
before do
@gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
GroundColor.page_size('1000').should eq GroundColor.max_page_size
end
end
- context 'つつがなく終わるとき' do\r
- it '一覧取得オプションを利用している' do\r
- GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})\r
- GroundColor.should_receive(:list_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
+ GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
r = GroundColor.list
- end\r
- end\r
+ end
+ end
it 'リストを返す' do
pl = GroundColor.list
pl.should eq [@gc]
pl = GroundColor.list
pl.should eq [npl, @gc]
end
- it '非公開のコマの景色は含まない' do
+ it '非公開のコマの選択色地は含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :updated_at => Time.now + 100
pl = GroundColor.list
end
end
- describe '一覧取得オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = GroundColor.list_opt
- r.has_key?(:include).should be_true
- end
- it '2つの項目を含んでいる' do
- r = GroundColor.list_opt[:include]
- r.should have(2).items
- end
- it 'コマを含んでいる' do
- r = GroundColor.list_opt[:include]
- r.has_key?(:panel).should be_true
- end
- it 'コマは作家を含んでいる' do
- r = GroundColor.list_opt[:include]
- r[:panel].has_key?(:author).should be_true
- end
- it '色を含んでいる' do
- r = GroundColor.list_opt[:include]
- r.has_key?(:color).should be_true
- end
- end
- describe 'json一覧出力オプションに於いて' do
+ describe '自分のコマで使った選択色地一覧取得に於いて' do
before do
- @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
- @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
- @sbt = FactoryGirl.create :speech_balloon_template\r
- @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
- @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
- @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
@gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
end
- it 'コマを含んでいる' do
- r = GroundColor.list.to_json GroundColor.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('panel').should be_true
- end
- it 'コマは作家を含んでいる' do
- r = GroundColor.list.to_json GroundColor.list_json_opt
- j = JSON.parse r
- i = j.first
- s = i['panel']
- s.has_key?('author').should be_true
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
+ GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
+ r = GroundColor.mylist @author
end
- it '色を含んでいる' do
- r = GroundColor.list.to_json GroundColor.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('color').should be_true
- end
- end
-
- describe '自分のコマで使った色一覧取得に於いて' do
- before do
- @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
end
- context 'つつがなく終わるとき' do\r
- it '一覧取得オプションを利用している' do\r
- GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})\r
- GroundColor.should_receive(:list_opt).with(any_args).exactly(1)\r
- r = GroundColor.mylist @author
- end\r
- end\r
it 'リストを返す' do
pl = GroundColor.mylist @author
pl.should eq [@gc]
pl = GroundColor.mylist @author
pl.should eq [npl, @gc]
end
- it '他人のコマの景色は公開でも含まない' do
+ it '他人のコマの選択色地は公開でも含まない' do
hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id
pl = GroundColor.mylist @author
pl.should eq [@gc]
end
- it '自分のコマの景色は非公開でも含んでいる' do
+ it '自分のコマの選択色地は非公開でも含んでいる' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
pl = GroundColor.mylist @author
@gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
@gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
@gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
- Author.stub(:default_ground_color_page_size).and_return(2)\r
+ Author.stub(:default_ground_color_page_size).and_return(2)
end
it '通常は全件(5件)を返す' do
r = GroundColor.mylist @author, 5, 0
end
end
+ describe '他作家の選択色地一覧取得に於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id
+ end
+ it 'リストを返す' do
+ r = GroundColor.himlist @other_author
+ r.should eq [@other_gc]
+ end
+ it '時系列で並んでいる' do
+ new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
+ new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 100
+ r = GroundColor.himlist @other_author
+ r.should eq [new_gc, @other_gc]
+ end
+ it '公開コマに限る' do
+ hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
+ hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id, :color_id => @color.id
+ r = GroundColor.himlist @other_author
+ r.should eq [@other_gc]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 100
+ @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 200
+ @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 300
+ @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 400
+ end
+ it '通常は2件を返す' do
+ pl = GroundColor.himlist @other_author, 1, 2
+ pl.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ pl = GroundColor.himlist @other_author, 1, 2
+ pl.should eq [@other_gc5, @other_gc4]
+ end
+ it 'page=2なら中間2件を返す' do
+ pl = GroundColor.himlist @other_author, 2, 2
+ pl.should eq [@other_gc3, @other_gc2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ pl = GroundColor.himlist @other_author, 3, 2
+ pl.should eq [@other_gc]
+ end
+ end
+ context 'DBに5件あって1ページの件数を0件に変えたとして' do
+ before do
+ @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 100
+ @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 200
+ @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 300
+ @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 400
+ Author.stub(:default_ground_color_page_size).and_return(2)
+ end
+ it '通常は全件(5件)を返す' do
+ r = GroundColor.himlist @other_author, 5, 0
+ r.should have(5).items
+ end
+ end
+ end
+
+ describe '一覧取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = GroundColor.list_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = GroundColor.list_opt[:include]
+ r.should have(2).items
+ end
+ it 'コマを含んでいる' do
+ r = GroundColor.list_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundColor.list_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it '色を含んでいる' do
+ r = GroundColor.list_opt[:include]
+ r.has_key?(:color).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @sbt = FactoryGirl.create :speech_balloon_template
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ it 'コマを含んでいる' do
+ r = GroundColor.list.to_json GroundColor.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundColor.list.to_json GroundColor.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '色を含んでいる' do
+ r = GroundColor.list.to_json GroundColor.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('color').should be_true
+ end
+ end
+
+ describe '単体取得に於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
+ r = GroundColor.show @gc.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
+ GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = GroundColor.show @gc.id, @author
+ end
+ end
+ it '指定の選択色地を返す' do
+ GroundColor.any_instance.stub(:visible?).and_return(true)
+ pl = GroundColor.show @gc.id, @author
+ pl.should eq @gc
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ GroundColor.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ GroundColor.show @gc.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない選択色地を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ GroundColor.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = GroundColor.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r.should have(2).items
+ end
+ it 'コマを含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it '色を含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r.has_key?(:color).should be_true
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ it 'コマを含んでいる' do
+ r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '色を含んでいる' do
+ r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('color').should be_true
+ end
+ end
+
end