X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fauthor_spec.rb;h=4557d512d6ef7b58183bf50fad33a0c2a0bfa69f;hb=c34883815450239ce7eb5d7f705695aa30fd2b44;hp=414b16112dace870e2c8ccd5f47bde37811da886;hpb=e3ed5d83fcbd2d94ea1f1d0af6d5b6a278bb201c;p=pettanr%2Fpettanr.git diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index 414b1611..4557d512 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -9,13 +9,83 @@ describe Author do @author = @user.author end - describe '自動補充に於いて' do - #作家はユーザ作成で自動作成されちゃってる + describe '検証に於いて' do + before do + end + + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @author.name = 'a' + @author.should be_valid + end + it '上限データが通る' do + @author.name = 'a'*30 + @author.save! + @author.should be_valid + end + end + + context 'nameを検証するとき' do + it 'nullなら失敗する' do + @author.name = nil + @author.should_not be_valid + end + it '30文字以上なら失敗する' do + @author.name = 'a'*31 + @author.should_not be_valid + end + end + context 'user_idを検証するとき' do + it 'nullなら失敗する' do + @author.user_id = nil + @author.should_not be_valid + end + it '数値でなければ失敗する' do + @author.user_id = 'a' + @author.should_not be_valid + end + it '存在するアカウントでなければ失敗する' do + @author.user_id = 0 + @author.should_not be_valid + end + end + end + + describe 'デフォルト値補充に於いて' do it '名前がno nameになっている' do + @author = FactoryGirl.build :author, :name => nil + @author.supply_default @author.name.should eq 'no name' end end + describe '上書き補充に於いて' do + end + + describe '所持判定に於いて' do + before do + @other_user = FactoryGirl.create :user_yas +#アカウントを作ると連動して作家ができる @other_author = FactoryGirl.create :author_yas, :user_id => @other_user.id + end + it '作家自身ならyes' do + @author.own?(@author).should == true + end + it '作家自身でなければno' do + @author.own?(@other_author).should == false + end + it '作家が不明ならno' do + @author.own?(nil).should == false + end + end + + describe '閲覧許可に於いて' do + before do + end + it '許可する' do + @author.visible?(@author).should == true + end + end + describe '絵師作家判定に於いて' do before do end @@ -32,4 +102,333 @@ describe Author do end end + describe '一覧取得に於いて' do + before do + end + context 'page補正について' do + it '文字列から数値に変換される' do + Author.page('8').should eq 8 + end + it 'nilの場合は1になる' do + Author.page().should eq 1 + end + it '0以下の場合は1になる' do + Author.page('0').should eq 1 + end + end + context 'page_size補正について' do + it '文字列から数値に変換される' do + Author.page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_page_sizeになる' do + Author.page_size().should eq Author.default_page_size + end + it '0以下の場合はAuthor.default_page_sizeになる' do + Author.page_size('0').should eq Author.default_page_size + end + it 'Author.max_page_sizeを超えた場合はAuthor.max_page_sizeになる' do + Author.page_size('1000').should eq Author.max_page_size + end + end + 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 + end + it 'リストを返す' do + r = Author.list + r.should eq [@author] + end + it '作成時系列で並んでいる' do + @other_user = FactoryGirl.create :user_yas + #アカウントを作ると連動して作家ができる + n = @other_user.author + n.created_at = Time.now + 100 + n.save + l = Author.list + l.should eq [n, @author] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' 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(2) + end + it '通常は2件を返す' do + r = Author.list + r.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + r = Author.list(1) + r.should eq [@author5, @author4] + end + it 'page=2なら中間2件を返す' do + r = Author.list(2) + r.should eq [@author3, @author2] + end + it 'page=3なら先頭1件を返す' do + r = Author.list(3) + 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 + 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.should have(1).items + end + it '絵師を含んでいる' do + r = Author.list_opt[:include] + 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 + end + it '絵師を含んでいる' do + r = Author.list_json_opt[:include] + r.has_key?(:artist).should be_true + end + end + + describe '単体取得に於いて' do + before do + end + 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 + 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 + end + it '指定の作家を返す' do + r = Author.show @author.id, @author + r.should eq @author + end + 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 + 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 + 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 + end + it '指定の作家を返す' do + Author.any_instance.stub(:own?).and_return(true) + r = Author.edit @author.id, @author.id + r.should eq @author + end + context '他人の作家を開こうとしたとき' do + it '403Forbidden例外を返す' do + Author.any_instance.stub(:own?).and_return(false) + lambda{ + Author.edit @author.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない作家を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Author.edit 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '単体取得オプションに於いて' do + it 'includeキーを含んでいる' do + r = Author.show_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = Author.show_opt[:include] + r.should have(1).items + end + it '絵師を含んでいる' do + r = Author.show_opt[:include] + r.has_key?(:artist).should be_true + 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 + end + it '絵師を含んでいる' do + r = Author.show_json_opt[:include] + r.has_key?(:artist).should be_true + end + end + + describe 'マイリストページ制御パラメータに於いて' do + before do + end + context 'コミックpage_size補正について' do + it '文字列から数値に変換される' do + Author.comic_page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_comic_page_sizeになる' do + Author.comic_page_size().should eq Author.default_comic_page_size + end + it '0以下の場合はAuthor.default_comic_page_sizeになる' do + Author.comic_page_size('0').should eq Author.default_comic_page_size + end + it 'Author.comic_max_page_sizeを超えた場合はAuthor.comic_max_page_sizeになる' do + Author.comic_page_size('1000').should eq Author.comic_max_page_size + end + end + context 'ストーリーpage_size補正について' do + it '文字列から数値に変換される' do + Author.story_page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_story_page_sizeになる' do + Author.story_page_size().should eq Author.default_story_page_size + end + it '0以下の場合はAuthor.default_story_page_sizeになる' do + Author.story_page_size('0').should eq Author.default_story_page_size + end + it 'Author.story_max_page_sizeを超えた場合はAuthor.story_max_page_sizeになる' do + Author.story_page_size('1000').should eq Author.story_max_page_size + end + end + context 'コマ絵page_size補正について' do + it '文字列から数値に変換される' do + Author.panel_page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_panel_page_sizeになる' do + Author.panel_page_size().should eq Author.default_panel_page_size + end + it '0以下の場合はAuthor.default_panel_page_sizeになる' do + Author.panel_page_size('0').should eq Author.default_panel_page_size + end + it 'Author.panel_max_page_sizeを超えた場合はAuthor.panel_max_page_sizeになる' do + Author.panel_page_size('1000').should eq Author.panel_max_page_size + end + end + context '景色素材page_size補正について' do + it '文字列から数値に変換される' do + Author.panel_picture_page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_panel_picture_page_sizeになる' do + Author.panel_picture_page_size().should eq Author.default_panel_picture_page_size + end + it '0以下の場合はAuthor.default_panel_picture_page_sizeになる' do + Author.panel_picture_page_size('0').should eq Author.default_panel_picture_page_size + end + it 'Author.panel_picture_max_page_sizeを超えた場合はAuthor.panel_picture_max_page_sizeになる' do + Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size + end + end + context '景色カラーpage_size補正について' do + it '文字列から数値に変換される' do + Author.ground_picture_page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_ground_picture_page_sizeになる' do + Author.ground_picture_page_size().should eq Author.default_ground_picture_page_size + end + it '0以下の場合はAuthor.default_ground_picture_page_sizeになる' do + Author.ground_picture_page_size('0').should eq Author.default_ground_picture_page_size + end + it 'Author.ground_picture_max_page_sizeを超えた場合はAuthor.ground_picture_max_page_sizeになる' do + Author.ground_picture_page_size('1000').should eq Author.ground_picture_max_page_size + end + end + context '景色カラーコードpage_size補正について' do + it '文字列から数値に変換される' do + Author.ground_color_page_size('7').should eq 7 + end + it 'nilの場合はAuthor.default_ground_color_page_sizeになる' do + Author.ground_color_page_size().should eq Author.default_ground_color_page_size + end + it '0以下の場合はAuthor.default_ground_color_page_sizeになる' do + Author.ground_color_page_size('0').should eq Author.default_ground_color_page_size + end + it 'Author.ground_color_max_page_sizeを超えた場合はAuthor.ground_color_max_page_sizeになる' do + Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size + end + end + end end