describe Author do
before do
- FactoryGirl.create :admin
+ SpeechBalloonTemplate.delete_all
+ @admin = FactoryGirl.create :admin
@user = FactoryGirl.create( :user_yas)
- @author = @user.author
+ @author = FactoryGirl.create :author, :user_id => @user.id
end
describe '検証に於いて' do
context 'オーソドックスなデータのとき' do
it '下限データが通る' do
@author.name = 'a'
+ @author.working_panel_id = 0
@author.should be_valid
end
it '上限データが通る' do
@author.should_not be_valid
end
end
+ context 'working_panel_idを検証するとき' do
+ it '数値でなければ失敗する' do
+ @author.working_panel_id = 'a'
+ @author.should_not be_valid
+ end
+ end
context 'user_idを検証するとき' do
it 'nullなら失敗する' do
@author.user_id = nil
end
end
+ describe '文字コード検証に於いて' do
+ before do
+ end
+
+ context 'nameを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @author.name = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @author.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
+
+ end
+
describe 'デフォルト値補充に於いて' do
it '名前がno nameになっている' do
@author = FactoryGirl.build :author, :name => nil
describe '所持判定に於いて' do
before do
@other_user = FactoryGirl.create :user_yas
-#アカウントを作ると連動して作家ができる @other_author = FactoryGirl.create :author_yas, :user_id => @other_user.id\r
+ @other_author = @other_user.author
end
- it '作家自身ならyes' do
- @author.own?(@author).should == true
+ context '事前チェックする' do
+ it '自身にロールリストからの作家取得を依頼している' do
+ Author.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+ r = @author.own?([@author])
+ end
end
- it '作家自身でなければno' do
- @author.own?(@other_author).should == false
+ context 'ロール内作家が取得できるとき' do
+ before do
+ end
+ it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+ Author.stub(:get_author_from_roles).with(any_args).and_return(@author)
+ r = @author.own?([@author])
+ r.should be_true
+ end
+ it 'ロール内作家のidが自身の作家idと一致しないならno' do
+ Author.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+ @author.own?(@other_author).should be_false
+ end
end
- it '作家が不明ならno' do
- @author.own?(nil).should == false
+ context 'ロール内作家が取得できないとき' do
+ before do
+ Author.stub(:get_author_from_roles).with(any_args).and_return(nil)
+ end
+ it 'Falseを返す' do
+ r = @author.own?([@author])
+ r.should be_false
+ end
end
end
describe '閲覧許可に於いて' do
before do
end
- it '許可する' do\r
- @author.visible?(@author).should == true
- end\r
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '自身にゲスト用ロールチェックを問い合わせしている' do
+ Author.any_instance.stub(:guest_role_check).and_return(true)
+ Author.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+ r = @author.visible?([@author])
+ end
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+ Author.any_instance.stub(:guest_role_check).and_return(false)
+ r = @author.visible?([@author])
+ r.should be_false
+ end
+ end
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '自身に読者用ロールチェックを問い合わせしている' do
+ Author.any_instance.stub(:reader_role_check).and_return(true)
+ Author.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+ r = @author.visible?([@author])
+ end
+ it '読者用ロールチェックが失敗したとき、falseを返す' do
+ Author.any_instance.stub(:reader_role_check).and_return(false)
+ r = @author.visible?([@author])
+ r.should be_false
+ end
+ end
+ context '事前チェックする' do
+ before do
+ MagicNumber['run_mode'] = 1
+ Author.any_instance.stub(:reader_role_check).and_return(true)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ Author.any_instance.stub(:reader_role_check).and_return(true)
+ end
+ it '許可する' do
+ r = @author.visible?([@author])
+ r.should be_true
+ end
+ end
end
describe '絵師作家判定に於いて' do
Author.page_size('1000').should eq Author.max_page_size
end
end
- context 'つつがなく終わるとき' do\r
- it '一覧取得オプションを利用している' do\r
- Author.stub(:list_opt).with(any_args).and_return({})\r
- Author.should_receive(:list_opt).with(any_args).exactly(1)\r
+ 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\r
- end\r
+ 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
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)
r.should eq [@author]
end
end
- context 'DBに5件あって1ページの件数を0件に変えたとして' do
- before do
- @other_user2 = FactoryGirl.create :user_yas
- @author2 = @other_user2.author
- @author2.created_at = Time.now + 100
- @author2.save
- @other_user3 = FactoryGirl.create :user_yas
- @author3 = @other_user3.author
- @author3.created_at = Time.now + 200
- @author3.save
- @other_user4 = FactoryGirl.create :user_yas
- @author4 = @other_user4.author
- @author4.created_at = Time.now + 300
- @author4.save
- @other_user5 = FactoryGirl.create :user_yas
- @author5 = @other_user5.author
- @author5.created_at = Time.now + 400
- @author5.save
- Author.stub(:default_page_size).and_return(0)
- end
- it '通常は全件(5件)を返す' do
- r = Author.list
- r.should have(5).items
- end
+ end
+
+ describe '一覧ページ制御に於いて' do
+ before do
+ Author.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Author.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Author.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
end
end
+
describe '一覧取得オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = Author.list_opt
- r.has_key?(:include).should be_true
- end
it '1つの項目を含んでいる' do
- r = Author.list_opt[:include]
+ r = Author.list_opt
r.should have(1).items
end
it '絵師を含んでいる' do
- r = Author.list_opt[:include]
+ r = Author.list_opt
r.has_key?(:artist).should be_true
end
end
describe 'json一覧出力オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = Author.list_json_opt
- r.has_key?(:include).should be_true
- end
- it '1つの項目を含んでいる' do
- r = Author.list_json_opt[:include]
- r.should have(1).items
+ before do
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
end
it '絵師を含んでいる' do
- r = Author.list_json_opt[:include]
- r.has_key?(:artist).should be_true
+ r = Author.list.to_json Author.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('artist').should be_true
end
end
describe '単体取得に於いて' do
before do
end
- context 'つつがなく終わるとき' do\r
- it '単体取得オプションを利用している' do\r
- Author.stub(:show_opt).with(any_args).and_return({})\r
- Author.should_receive(:show_opt).with(any_args).exactly(1)\r
+ 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\r
- it '閲覧許可を問い合わせている' do\r
- Author.any_instance.stub(:visible?).with(any_args).and_return(true)\r
- Author.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+ 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\r
- end\r
+ end
+ end
it '指定の作家を返す' do
r = Author.show @author.id, @author
r.should eq @author
end
- context '閲覧許可が出なかったとき' do\r
- it '403Forbidden例外を返す' do\r
- Author.any_instance.stub(:visible?).and_return(false)\r
- lambda{\r
- Author.show @author.id, @author\r
- }.should raise_error(ActiveRecord::Forbidden)\r
- end\r
- end\r
- context '存在しない作家を開こうとしたとき' do\r
- it '404RecordNotFound例外を返す' do\r
- lambda{\r
- Author.show 110, @author\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
+ 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\r
- it '単体取得オプションを利用している' do\r
- Author.stub(:show_opt).with(any_args).and_return({})\r
- Author.should_receive(:show_opt).with(any_args).exactly(1)\r
+ 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\r
- it '所持判定を問い合わせている' do\r
- Author.any_instance.stub(:own?).with(any_args).and_return(true)\r
- Author.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+ 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\r
- end\r
+ end
+ end
it '指定の作家を返す' do
Author.any_instance.stub(:own?).and_return(true)
r = Author.edit @author.id, @author.id
end
end
describe 'json単体出力オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = Author.show_json_opt
- r.has_key?(:include).should be_true
- end
- it '1つの項目を含んでいる' do
- r = Author.show_json_opt[:include]
- r.should have(1).items
+ before do
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
end
it '絵師を含んでいる' do
- r = Author.show_json_opt[:include]
- r.has_key?(:artist).should be_true
+ r = Author.show(@author.id, @author).to_json Author.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('artist').should be_true
end
end
describe 'マイリストページ制御パラメータに於いて' do
before do
end
+ context 'スクロールpage_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.scroll_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_scroll_page_sizeになる' do
+ Author.scroll_page_size().should eq Author.default_scroll_page_size
+ end
+ it '0以下の場合はAuthor.default_scroll_page_sizeになる' do
+ Author.scroll_page_size('0').should eq Author.default_scroll_page_size
+ end
+ it 'Author.scroll_max_page_sizeを超えた場合はAuthor.scroll_max_page_sizeになる' do
+ Author.scroll_page_size('1000').should eq Author.scroll_max_page_size
+ end
+ end
+ context 'スクコマpage_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.scroll_panel_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_scroll_panel_page_sizeになる' do
+ Author.scroll_panel_page_size().should eq Author.default_scroll_panel_page_size
+ end
+ it '0以下の場合はAuthor.default_scroll_panel_page_sizeになる' do
+ Author.scroll_panel_page_size('0').should eq Author.default_scroll_panel_page_size
+ end
+ it 'Author.scroll_panel_max_page_sizeを超えた場合はAuthor.scroll_panel_max_page_sizeになる' do
+ Author.scroll_panel_page_size('1000').should eq Author.scroll_panel_max_page_size
+ end
+ end
context 'コミックpage_size補正について' do
it '文字列から数値に変換される' do
Author.comic_page_size('7').should eq 7
Author.story_page_size('1000').should eq Author.story_max_page_size
end
end
- context 'コマ絵page_size補正について' do
+ context 'スト紙page_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.story_sheet_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_story_sheet_page_sizeになる' do
+ Author.story_sheet_page_size().should eq Author.default_story_sheet_page_size
+ end
+ it '0以下の場合はAuthor.default_story_sheet_page_sizeになる' do
+ Author.story_sheet_page_size('0').should eq Author.default_story_sheet_page_size
+ end
+ it 'Author.story_sheet_max_page_sizeを超えた場合はAuthor.story_sheet_max_page_sizeになる' do
+ Author.story_sheet_page_size('1000').should eq Author.story_sheet_max_page_size
+ end
+ end
+ context '用紙page_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.sheet_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_sheet_page_sizeになる' do
+ Author.sheet_page_size().should eq Author.default_sheet_page_size
+ end
+ it '0以下の場合はAuthor.default_sheet_page_sizeになる' do
+ Author.sheet_page_size('0').should eq Author.default_sheet_page_size
+ end
+ it 'Author.sheet_max_page_sizeを超えた場合はAuthor.sheet_max_page_sizeになる' do
+ Author.sheet_page_size('1000').should eq Author.sheet_max_page_size
+ end
+ end
+ context '紙コマpage_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.sheet_panel_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_sheet_panel_page_sizeになる' do
+ Author.sheet_panel_page_size().should eq Author.default_sheet_panel_page_size
+ end
+ it '0以下の場合はAuthor.default_sheet_panel_page_sizeになる' do
+ Author.sheet_panel_page_size('0').should eq Author.default_sheet_panel_page_size
+ end
+ it 'Author.sheet_panel_max_page_sizeを超えた場合はAuthor.sheet_panel_max_page_sizeになる' do
+ Author.sheet_panel_page_size('1000').should eq Author.sheet_panel_max_page_size
+ end
+ end
+ context 'コマpage_size補正について' do
it '文字列から数値に変換される' do
Author.panel_page_size('7').should eq 7
end
Author.panel_page_size('1000').should eq Author.panel_max_page_size
end
end
- context '景色素材page_size補正について' do
+ context 'コマ素材page_size補正について' do
it '文字列から数値に変換される' do
Author.panel_picture_page_size('7').should eq 7
end
Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
end
end
+ context 'フキダシpage_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.speech_balloon_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_speech_balloon_page_sizeになる' do
+ Author.speech_balloon_page_size().should eq Author.default_speech_balloon_page_size
+ end
+ it '0以下の場合はAuthor.default_speech_balloon_page_sizeになる' do
+ Author.speech_balloon_page_size('0').should eq Author.default_speech_balloon_page_size
+ end
+ it 'Author.speech_balloon_max_page_sizeを超えた場合はAuthor.speech_balloon_max_page_sizeになる' do
+ Author.speech_balloon_page_size('1000').should eq Author.speech_balloon_max_page_size
+ end
+ end
context '景色カラーpage_size補正について' do
it '文字列から数値に変換される' do
Author.ground_picture_page_size('7').should eq 7
Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size
end
end
+ context '素材page_size補正について' do
+ it '文字列から数値に変換される' do
+ Author.resource_picture_page_size('7').should eq 7
+ end
+ it 'nilの場合はAuthor.default_resource_picture_page_sizeになる' do
+ Author.resource_picture_page_size().should eq Author.default_resource_picture_page_size
+ end
+ it '0以下の場合はAuthor.default_resource_picture_page_sizeになる' do
+ Author.resource_picture_page_size('0').should eq Author.default_resource_picture_page_size
+ end
+ it 'Author.resource_picture_max_page_sizeを超えた場合はAuthor.resource_picture_max_page_sizeになる' do
+ Author.resource_picture_page_size('1000').should eq Author.resource_picture_max_page_size
+ end
+ end
end
end