From: yasushiito Date: Sat, 21 Jul 2012 00:29:37 +0000 (+0900) Subject: merge v04 X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=d06c85598de5091129d22bfdcc650fae261a6219 merge v04 --- d06c85598de5091129d22bfdcc650fae261a6219 diff --cc app/models/original_picture.rb index 1363cc9a,96740f90..19c993d2 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@@ -56,9 -59,15 +56,15 @@@ class OriginalPicture < ActiveRecord::B pic end + def self.edit cid, artist, opt = {} + pic = OriginalPicture.find(cid, :include => self.show_include_opt(opt)) + raise ActiveRecord::Forbidden unless pic.own?(artist) + pic + end + def self.show_include_opt opt = {} - res = [:license, :resource_picture] - res.push(opt[:include]) if opt[:include] + res = {:resource_picture => {}} + res.merge!(opt[:include]) if opt[:include] res end diff --cc app/models/panel_picture.rb index 8b8c515a,eab88aa1..13f7a3b1 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@@ -2,7 -2,8 +2,7 @@@ class PanelPicture < ActiveRecord::Bas belongs_to :panel belongs_to :resource_picture - validates :panel_id, :presence => true, :numericality => true, :existence => true + validates :panel_id, :numericality => {:allow_blank => true} - validates :resource_picture_id, :presence => true, :numericality => true, :existence => true validates :link, :length => {:maximum => 200} validates :x, :presence => true, :numericality => true validates :y, :presence => true, :numericality => true diff --cc app/views/resource_pictures/index.html.erb index 211045d5,4c3d4646..859041c1 --- a/app/views/resource_pictures/index.html.erb +++ b/app/views/resource_pictures/index.html.erb @@@ -1,11 -1,10 +1,11 @@@

Listing resource_pictures

<% @resource_pictures.each do |resource_picture| %> + <% @resource_picture = resource_picture %>
- <%= resource_picture.filename %> - + <%= link_to resource_picture.filename, resource_picture_path(resource_picture) %> - ++ <%= resource_picture.width %>x<%= resource_picture.height %> <%= resource_picture.filesize %>bytes - 画:<%= h resource_picture.original_picture.artist.name %> + <%= render resource_picture.credit_template %>
<% end %> diff --cc config/routes.rb index 79088cb5,7761f237..353343b2 --- a/config/routes.rb +++ b/config/routes.rb @@@ -88,8 -86,13 +88,11 @@@ Pettanr::Application.routes.draw d get :list get :browse end - member do - end end resources :original_pictures do + new do + get :new + end collection do get :index get :show diff --cc spec/cli/u/comics/create.json index 00000000,7b8fabea..c780055a mode 000000,100644..100644 --- a/spec/cli/u/comics/create.json +++ b/spec/cli/u/comics/create.json @@@ -1,0 -1,9 +1,9 @@@ + { + "comic": { + "title": "コミック作るテスト", + "width": 400, + "height": 200, + "visible": 3 + }, - "auth_token": "Qr2cveaLKqMHA8dME7CN" ++ "auth_token": "vX7rc33zxVJSQPKjp2vc" + } diff --cc spec/cli/u/original_pictures/create.json index 00000000,b5f7c8bf..6020ade1 mode 000000,100644..100644 --- a/spec/cli/u/original_pictures/create.json +++ b/spec/cli/u/original_pictures/create.json @@@ -1,0 -1,6 +1,6 @@@ + { + "original_picture": { + "file": + "iVBORw0KGgoAAAANSUhEUgAAAWIAAAF7CAYAAADohYEpAAAcW0lEQVR4nO3dTW4cx7KG4ewLz0gYGgmCVsGleBEeHJ+zAQ489IArEDS4i7hL4SoIgSPBIMd9BzolF4tVWfkTmRGR+T4AAdkkm93183V0VGbW5Xq9BgCAnv/RfgIAMDuCGACUEcQAoIwgBgBlBDEAKCOI0d3lcrnydfwVQgj/+eMPhjNN5MLwNbSyhAr6ul6vF+3ngDwEMUQRvrYQyj4QxKhC8PpAINtGECMZoTsGQtkeghiHCN7xEco2EMT4qXfw3t/f9/xzbjw8PHT/mwSyLoJ4Uj1Cl6Dt5+/v30MIIXz5+rX4MQhjPQTxJKh2x7eEcQgh/PrhQ3FlTSD3RxAPSKO3S/DaQSD7QxAPgGoXW+sw3sppXxDGfRDEDhG8SHUUyISxLQSxcbQZIGUbyoSxHQSxMVS7aEWiXUEgt0EQG9ErgAneucXCOIS0QCaM5f2i/QRm1zKACV1s/frhw2kYn7lcLlfCWBYVsYJW4UvwIhVtClsI4s4kQ5jgRamUqpg2RT8EcUc1IUzoogWJQCaM69Ej7qAk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aj1ywlJLhjDOo31sanMdxIvZAtnrTKOz/VSzPyyF8NrsgWzhuPNgiCBeyz3wPYVx6VVvSydDizC2GsI5egS29W0wM1c94hS5fTov/WNvbYgeRgjghZfniTaGq4i3SioNjVCWHONp/aSWqIpHCmFg+CAOYY4+nbfQKV3ciSF6GNEUQbwYMZA9B06r/eF5m2BO5u/QIWm0E9T762nx/L1vE8xpqop4zXN1PFrYSO2L0bYL5jFtEC88BfLIQVOzH0beLpjD9EG8RyucZw+Uku0++zbDGAhimJITxoQwRjHchA74RrhiRlONmgAAiwhiAFBGEAOAMoIYAJQRxACgjCAGAGUEMQAoI4gBQBlBDADKCGIAUEYQA4AyghgAlBHEAKCMIAYAZQQxACgjiAFAGUEMAMoIYgBQRhADgDKCGACUEcQAoIwgBgBlBDEAKCOIAUAZQQwAyghiAFBGEAOAMoIYAJQRxACgjCAGAGUEMQAoI4gBQBlBDADKCGIAUEYQA4AyghgAlP0/Bxl7hN5Zu0EAAAAASUVORK5CYII=" }, - "auth_token": "Qr2cveaLKqMHA8dME7CN" ++ "auth_token": "vX7rc33zxVJSQPKjp2vc" + } diff --cc spec/cli/u/panels/create.json index 00000000,9eba8b65..9b610c9b mode 000000,100644..100644 --- a/spec/cli/u/panels/create.json +++ b/spec/cli/u/panels/create.json @@@ -1,0 -1,23 +1,23 @@@ + { + "panel": { + "width": 400, + "height": 200, + "border": 1, + "x": 0, + "y": 0, + "z": 1, + "publish": 1, + "panel_pictures_attributes": { + "new1": { + "resource_picture_id": 3, + "x": 10, + "y": 135, + "z": 3, + "t": 0, + "width": 100, + "height": 103 + } + } + }, - "auth_token": "Qr2cveaLKqMHA8dME7CN" ++ "auth_token": "vX7rc33zxVJSQPKjp2vc" + } diff --cc spec/cli/u/stories/create.json index 00000000,577fff47..75d07d2d mode 000000,100644..100644 --- a/spec/cli/u/stories/create.json +++ b/spec/cli/u/stories/create.json @@@ -1,0 -1,7 +1,7 @@@ + { + "story": { + "comic_id": 1, + "panel_id": 1 + }, - "auth_token": "Qr2cveaLKqMHA8dME7CN" ++ "auth_token": "vX7rc33zxVJSQPKjp2vc" + } diff --cc spec/controllers/comics_controller_spec.rb index 20dfcc3d,7ae248d5..88796104 --- a/spec/controllers/comics_controller_spec.rb +++ b/spec/controllers/comics_controller_spec.rb @@@ -1,653 -1,548 +1,550 @@@ # -*- encoding: utf-8 -*- -require 'spec_helper' - -describe ComicsController do - before do - Factory :admin - @license = Factory :license +require 'spec_helper' + +describe ComicsController do + before do + Factory :admin + @sp = Factory :system_picture + @lg = Factory :license_group + @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @user = Factory :user_yas - @author = @user.author #ユーザ作成時に連動して作成される - end - - describe '一覧表示に於いて' do - before do - @comic = Factory :normal_comic, :author_id => @user.author.id - Comic.stub(:list).and_return([@comic, @comic, @comic]) - sign_in @user - end - context '事前チェックする' do - it '与えられたpageがセットされている' do - get :index, :page => 5 - assigns(:page).should eq 5 - end - it '省略されると@pageに1値が入る' do - get :index - assigns(:page).should eq 1 - end - it '与えられたpage_sizeがセットされている' do - get :index, :page_size => 15 - assigns(:page_size).should eq 15 - end - it '省略されると@page_sizeにデフォルト値が入る' do - get :index + @author = @user.author #ユーザ作成時に連動して作成される + end + + describe '一覧表示に於いて' do + before do + @comic = Factory :comic, :author_id => @user.author.id + Comic.stub(:list).and_return([@comic, @comic, @comic]) + sign_in @user + end + context '事前チェックする' do + it '与えられたpageがセットされている' do + get :index, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :index + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :index, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :index + assigns(:page_size).should eq Comic.default_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :index, :page_size => 1500 + assigns(:page_size).should eq Comic.max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :index, :page_size => 0 assigns(:page_size).should eq Comic.default_page_size - end - it '最大を超えると@page_sizeにデフォルト最大値が入る' do - get :index, :page_size => 1500 - assigns(:page_size).should eq Comic.max_page_size - end - it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do - get :index, :page_size => 0 - assigns(:page_size).should eq Comic.default_page_size - end - end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :index - response.should be_success - end - it 'コミックモデルに一覧を問い合わせている' do + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + it 'コミックモデルに一覧を問い合わせている' do Comic.should_receive(:list).exactly(1) - get :index - end - it '@comicsにリストを取得している' do - get :index - assigns(:comics).should have_at_least(3).items - end - context 'html形式' do - it 'indexテンプレートを描画する' do - get :index - response.should render_template("index") - end - end - context 'json形式' do - it 'jsonデータを返す' do - get :index, :format => :json - lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) - end - it 'データがリスト構造になっている' do - get :index, :format => :json + get :index + end + it '@comicsにリストを取得している' do + get :index + assigns(:comics).should have_at_least(3).items + end + context 'html形式' do + it 'indexテンプレートを描画する' do + get :index + response.should render_template("index") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :index, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'データがリスト構造になっている' do + get :index, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはコミックっぽいものであって欲しい' do + get :index, :format => :json json = JSON.parse response.body - json.should have_at_least(3).items - end - it 'リストの先頭くらいはコミックっぽいものであって欲しい' do - get :index, :format => :json - json = JSON.parse response.body - json.first.has_key?("title").should be_true - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - get :index - response.status.should eq 302 - end - it 'サインインページへ遷移する' do - get :index - response.should redirect_to '/users/sign_in' - end - end - context 'json形式' do - it 'ステータスコード401 Unauthorizedを返す' do - get :index, :format => :json - response.status.should eq 401 - end - it '応答メッセージにUnauthorizedを返す' do + json.first.has_key?("title").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :index + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :index + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do get :index, :format => :json - response.message.should match(/Unauthorized/) - end - end - end - end - - describe '単体表示に於いて' do - before do - @comic = Factory :normal_comic, :author_id => @user.author.id - Comic.stub(:show).and_return(@comic) - sign_in @user - end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :show, :id => @comic.id - response.should be_success - end - it 'コミックモデルに単体取得を問い合わせている' do + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :index, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '単体表示に於いて' do + before do + @comic = Factory :comic, :author_id => @user.author.id, :title => 'normal' + Comic.stub(:show).and_return(@comic) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @comic.id + response.should be_success + end + it 'コミックモデルに単体取得を問い合わせている' do Comic.should_receive(:show).exactly(1) - get :show - end - it '@comicにアレを取得している' do - get :show, :id => @comic.id - assigns(:comic).id.should eq(@comic.id) - end - context 'html形式' do - it 'showテンプレートを描画する' do - get :show, :id => @comic.id - response.should render_template("show") - end - end - context 'json形式' do - it 'jsonデータを返す' do - get :show, :id => @comic.id, :format => :json - lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) - end - it 'データがアレになっている' do - get :show, :id => @comic.id, :format => :json - json = JSON.parse response.body - json["title"].should match(/normal/) - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - get :show, :id => @comic.id - response.status.should eq 302 - end - it 'サインインページへ遷移する' do - get :show, :id => @comic.id - response.body.should redirect_to '/users/sign_in' - end - end - context 'json形式' do - it 'ステータスコード401 Unauthorizedを返す' do - get :show, :id => @comic.id, :format => :json - response.status.should eq 401 - end - it '応答メッセージにUnauthorizedを返す' do - get :show, :id => @comic.id, :format => :json - response.message.should match(/Unauthorized/) - end - end - end - =begin - context '対象コミックがないとき' do - context 'html形式' do - it '例外404 not_foundを返す' do + get :show + end + it '@comicにアレを取得している' do + get :show, :id => @comic.id + assigns(:comic).id.should eq(@comic.id) + end + context 'html形式' do + it 'showテンプレートを描画する' do + get :show, :id => @comic.id + response.should render_template("show") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :show, :id => @comic.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'データがアレになっている' do + get :show, :id => @comic.id, :format => :json + json = JSON.parse response.body + json["title"].should match(/normal/) + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :show, :id => @comic.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :show, :id => @comic.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :show, :id => @comic.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :show, :id => @comic.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + =begin + context '対象コミックがないとき' do + context 'html形式' do + it '例外404 not_foundを返す' do lambda{ - get :show, :id => 0 - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - context 'json形式' do - it '例外404 not_foundを返す' do + get :show, :id => 0 + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + context 'json形式' do + it '例外404 not_foundを返す' do lambda{ - get :show, :id => 0, :format => :json - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - context '非公開コミックを見ようとしたとき' do - context 'html形式' do - it '例外403 forbiddenを返す' do - Comic.any_instance.stub(:visible?).with(any_args()).and_return(false) - hidden = Factory :hidden_comic, :author_id => @author.id + get :show, :id => 0, :format => :json + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + context '非公開コミックを見ようとしたとき' do + context 'html形式' do + it '例外403 forbiddenを返す' do + Comic.any_instance.stub(:visible?).with(any_args()).and_return(false) + hidden = Factory :hidden_comic, :author_id => @author.id lambda{ - get :show, :id => hidden - }.should raise_error(ActiveRecord::Forbidden) - end - end - context 'json形式' do - it '例外403 forbiddenを返す' do - Comic.any_instance.stub(:visible?).with(any_args()).and_return(false) - hidden = Factory :hidden_comic, :author_id => @author.id + get :show, :id => hidden + }.should raise_error(ActiveRecord::Forbidden) + end + end + context 'json形式' do + it '例外403 forbiddenを返す' do + Comic.any_instance.stub(:visible?).with(any_args()).and_return(false) + hidden = Factory :hidden_comic, :author_id => @author.id lambda{ - get :show, :id => hidden, :format => :json - }.should raise_error(ActiveRecord::Forbidden) - end - end - end - =end - end - describe '閲覧に於いて' do - before do - @comic = Factory :normal_comic, :author_id => @user.author.id - Comic.stub(:show).and_return(@comic) - sign_in @user - end - context '事前チェックする' do - before do - Panel.stub(:count).and_return(10) - end - it '与えられたoffsetがセットされている' do - get :play, :id => @comic.id, :offset => 7 - assigns(:offset).should eq 7 - end - it '省略されると@offsetに0値が入る' do - get :play, :id => @comic.id - assigns(:offset).should eq 0 - end - it 'コマ数以上が与えられるとコマ数-1が入る' do - get :play, :id => @comic.id, :offset => 10 - assigns(:offset).should eq 9 - end - it '負の値が与えられると末尾(コマ数)からさかのぼった値が入る' do - get :play, :id => @comic.id, :offset => -3 - assigns(:offset).should eq 7 - end - it 'コマ数以上の負の値が与えられると計算できないので0値が入る' do - get :play, :id => @comic.id, :offset => -13 - assigns(:offset).should eq 0 - end - it '与えられたcountがセットされている' do - get :play, :id => @comic.id, :count => 18 - assigns(:panel_count).should eq 18 - end - it '省略されると@countにデフォルト値が入る' do - get :play, :id => @comic.id - assigns(:panel_count).should eq Comic.default_panel_size - end - it '最大を超えると@countにデフォルト最大値が入る' do - get :play, :id => @comic.id, :count => 1500 - assigns(:panel_count).should eq Comic.max_panel_size - end - it '不正な値が入ると@countにデフォルト最大値が入る' do - get :play, :id => @comic.id, :page_size => 0 - assigns(:panel_count).should eq Comic.default_panel_size - end - end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :play, :id => @comic.id - response.should be_success - end - it 'コミックモデルに単体取得を問い合わせている' do - Comic.should_receive(:show).exactly(1) - get :play, :id => @comic.id - end - it '@comicにアレを取得している' do - get :play, :id => @comic.id - assigns(:comic).id.should eq(@comic.id) - end - context 'html形式' do - it 'playテンプレートを描画する' do - get :play, :id => @comic.id - response.should render_template("play") - end - end - context 'json形式' do - it 'jsonデータを返す' do - get :play, :id => @comic.id, :format => :json - lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) - end - it 'データがアレになっている' do - get :play, :id => @comic.id, :format => :json - json = JSON.parse response.body - json["title"].should match(/normal/) - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - get :play, :id => @comic.id - response.status.should eq 302 - end - it 'サインインページへ遷移する' do - get :play, :id => @comic.id - response.body.should redirect_to '/users/sign_in' - end - end - context 'json形式' do - it 'ステータスコード401 Unauthorizedを返す' do - get :play, :id => @comic.id, :format => :json - response.status.should eq 401 - end - it '応答メッセージにUnauthorizedを返す' do - get :play, :id => @comic.id, :format => :json - response.message.should match(/Unauthorized/) - end - end - end - end - - describe 'コミック数取得に於いて' do - before do - Comic.should_receive(:visible_count).and_return(3) - # sign_in @user - end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :count, :format => :json - response.should be_success - end - context 'json形式' do - it 'jsonデータを返す' do - get :count, :format => :json - lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) - end - it 'データがHash構造になっていてコミック数が1である' do - get :count, :format => :json - json = JSON.parse response.body - json["count"].should == 3 - end - end - end - end - - describe '新規作成フォーム表示に於いて' do - before do - sign_in @user - end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :new - response.should be_success - end - it '@comicに新規データを用意している' do - get :new - assigns(:comic).should be_a_new(Comic) - end - it 'コミックモデルにデフォルト値補充を依頼している' do + get :show, :id => hidden, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + =end + end + describe 'コミック数取得に於いて' do + before do + Comic.should_receive(:visible_count).and_return(3) + # sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :count, :format => :json + response.should be_success + end + context 'json形式' do + it 'jsonデータを返す' do + get :count, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'データがHash構造になっていてコミック数が1である' do + get :count, :format => :json + json = JSON.parse response.body + json["count"].should == 3 + end + end + end + end + + describe '新規作成フォーム表示に於いて' do + before do + sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :new + response.should be_success + end + it '@comicに新規データを用意している' do + get :new + assigns(:comic).should be_a_new(Comic) + end + it 'コミックモデルにデフォルト値補充を依頼している' do Comic.any_instance.should_receive(:supply_default).exactly(1) - get :new - end - context 'html形式' do - it 'newテンプレートを描画する' do - get :new - response.should render_template("new") - end - end - context 'js形式' do - it 'new.jsテンプレートを描画する' do - get :new, :format => :js - response.should render_template("new") - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - get :new - response.status.should eq 302 - end - it 'サインインページへ遷移する' do - get :new - response.body.should redirect_to '/users/sign_in' - end - end - context 'js形式' do - it 'ステータスコード401 Unauthorizedを返す' do - get :new, :format => :js - response.status.should eq 401 - end - it '応答メッセージにUnauthorizedを返す' do - get :new, :format => :js - response.message.should match(/Unauthorized/) - end - end - end - end - - describe '新規作成に於いて' do - before do - sign_in @user - end - context 'つつがなく終わるとき' do - it 'モデルに保存依頼する' do - Comic.any_instance.should_receive(:save).exactly(1) - post :create, :comic => Factory.attributes_for(:normal_comic) - end - it "@comicに作成されたコミックを保持していて、それがDBにある" do - post :create, :comic => Factory.attributes_for(:normal_comic) - assigns(:comic).should be_a(Comic) - assigns(:comic).should be_persisted - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - Comic.any_instance.stub(:save).and_return(true) - post :create, :comic => Factory.attributes_for(:normal_comic) - response.status.should eq 302 - end - it '作成されたコミックの表示ページへ遷移する' do - # Comic.any_instance.stub(:save).and_return(true) - post :create, :comic => Factory.attributes_for(:normal_comic) - response.should redirect_to(Comic.last) - end - end - context 'json形式' do - it 'ステータスコード200 OKを返す' do - # Comic.any_instance.stub(:save).and_return(true) - post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json - response.should be_success - end - it '作成されたコミックをjsonデータで返す' do - post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json - lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) - end - it 'データがアレになっている' do - post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json - json = JSON.parse response.body - json["title"].should match(/normal/) - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - post :create, :comic => Factory.attributes_for(:normal_comic) - response.status.should eq 302 - end - it 'サインインページへ遷移する' do - post :create, :comic => Factory.attributes_for(:normal_comic) - response.body.should redirect_to '/users/sign_in' - end - end - context 'json形式' do - it 'ステータスコード401 Unauthorizedを返す' do - post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json - response.status.should eq 401 - end - it '応答メッセージにUnauthorizedを返す' do - post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json - response.message.should match(/Unauthorized/) - end - end - end - context '検証、保存に失敗した' do - before do - Comic.any_instance.stub(:save).and_return(false) - end - it "未保存のコミックを保持している" do - post :create, :comic => {} - assigns(:comic).should be_a_new(Comic) - end - context 'html形式' do - it 'ステータスコード200 OKを返す' do - post :create, :comic => {} - response.status.should eq 200 - end - it '新規ページを描画する' do - post :create, :comic => {} - response.should render_template("new") - end - end - context 'json形式' do - it 'ステータスコード422 unprocessable_entity を返す' do - post :create, :comic => {}, :format => :json - response.status.should eq 422 - end - it '応答メッセージUnprocessable Entityを返す' do - post :create, :comic => {}, :format => :json - response.message.should match(/Unprocessable/) - end - end - end - end - - describe '編集フォーム表示に於いて' do - before do - @comic = Factory :normal_comic, :author_id => @user.author.id - sign_in @user - Comic.stub(:show).and_return(@comic) - end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :edit, :id => @comic.id - response.should be_success - end - it 'コミックモデルに単体取得を問い合わせている' do + get :new + end + context 'html形式' do + it 'newテンプレートを描画する' do + get :new + response.should render_template("new") + end + end + context 'js形式' do + it 'new.jsテンプレートを描画する' do + get :new, :format => :js + response.should render_template("new") + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :new + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :new, :format => :js + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :new, :format => :js + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '新規作成に於いて' do + before do + sign_in @user + @attr = Factory.attributes_for(:comic, :author_id => @author.id, :title => 'normal') + end + context 'つつがなく終わるとき' do + it 'モデルに保存依頼する' do + Comic.any_instance.should_receive(:save).exactly(1) + post :create, :comic => @attr + end + it "@comicに作成されたコミックを保持していて、それがDBにある" do + post :create, :comic => @attr + assigns(:comic).should be_a(Comic) + assigns(:comic).should be_persisted + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Comic.any_instance.stub(:save).and_return(true) + post :create, :comic => @attr + response.status.should eq 302 + end + it '作成されたコミックの表示ページへ遷移する' do + # Comic.any_instance.stub(:save).and_return(true) + post :create, :comic => @attr + response.should redirect_to(Comic.last) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + # Comic.any_instance.stub(:save).and_return(true) + post :create, :comic => @attr, :format => :json + response.should be_success + end + it '作成されたコミックをjsonデータで返す' do + post :create, :comic => @attr, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'データがアレになっている' do + post :create, :comic => @attr, :format => :json + json = JSON.parse response.body + json["title"].should match(/normal/) + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, :comic => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, :comic => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + post :create, :comic => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + post :create, :comic => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '検証、保存に失敗した' do + before do + Comic.any_instance.stub(:save).and_return(false) + end + it "未保存のコミックを保持している" do + post :create, :comic => {} + assigns(:comic).should be_a_new(Comic) + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + post :create, :comic => {} + response.status.should eq 200 + end + it '新規ページを描画する' do + post :create, :comic => {} + response.should render_template("new") + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + post :create, :comic => {}, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + post :create, :comic => {}, :format => :json + response.message.should match(/Unprocessable/) + end + end + end + end + + describe '編集フォーム表示に於いて' do + before do + @comic = Factory :comic, :author_id => @user.author.id + sign_in @user + Comic.stub(:show).and_return(@comic) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @comic.id + response.should be_success + end + it 'コミックモデルに単体取得を問い合わせている' do Comic.should_receive(:show).exactly(1) - get :edit, :id => @comic.id - end - it '@comicにデータを用意している' do - get :edit, :id => @comic.id - assigns(:comic).should eq @comic - end - context 'html形式' do - it 'editテンプレートを描画する' do - get :edit, :id => @comic.id - response.should render_template("edit") - end - end - context 'js形式' do - it 'edit.jsテンプレートを描画する' do - get :edit, :id => @comic.id, :format => :js - response.should render_template("edit") - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - get :edit, :id => @comic.id - response.status.should eq 302 - end - it 'サインインページへ遷移する' do - get :edit, :id => @comic.id - response.body.should redirect_to '/users/sign_in' - end - end - context 'js形式' do - it 'ステータスコード401 Unauthorizedを返す' do - get :edit, :id => @comic.id, :format => :js - response.status.should eq 401 - end - it '応答メッセージにUnauthorizedを返す' do - get :edit, :id => @comic.id, :format => :js - response.message.should match(/Unauthorized/) - end - end - end - end - - describe '更新に於いて' do + get :edit, :id => @comic.id + end + it '@comicにデータを用意している' do + get :edit, :id => @comic.id + assigns(:comic).should eq @comic + end + context 'html形式' do + it 'editテンプレートを描画する' do + get :edit, :id => @comic.id + response.should render_template("edit") + end + end + context 'js形式' do + it 'edit.jsテンプレートを描画する' do + get :edit, :id => @comic.id, :format => :js + response.should render_template("edit") + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :edit, :id => @comic.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :edit, :id => @comic.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :edit, :id => @comic.id, :format => :js + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :edit, :id => @comic.id, :format => :js + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '更新に於いて' do before do - @comic = Factory :normal_comic, :author => @author - sign_in @user - end - context '事前チェックしておく' do - it 'コミックモデルに単体取得を問い合わせている' do + @comic = Factory :comic, :author => @author + @attr = Factory.attributes_for(:comic, :author_id => @author.id, :title => 'updated title', :visible => 0) + sign_in @user + end + context '事前チェックしておく' do + it 'コミックモデルに単体取得を問い合わせている' do Comic.stub(:show).with(any_args()).and_return @comic Comic.should_receive(:show).exactly(1) - put :update, :id => @comic.id, :comic => Factory.attributes_for(:normal_comic) - end - it 'モデルに更新を依頼する' do - Comic.any_instance.should_receive(:update_attributes).with(any_args) - put :update, :id => @comic.id, :comic => Factory.attributes_for(:normal_comic) - end - it '@comicにアレを取得している' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:normal_comic) - assigns(:comic).id.should eq(@comic.id) - end - end - context 'つつがなく終わるとき' do + put :update, :id => @comic.id, :comic => @attr + end + it 'モデルに更新を依頼する' do + Comic.any_instance.should_receive(:update_attributes).with(any_args) + put :update, :id => @comic.id, :comic => @attr + end + it '@comicにアレを取得している' do + put :update, :id => @comic.id, :comic => @attr + assigns(:comic).id.should eq(@comic.id) + end + end + context 'つつがなく終わるとき' do it '更新される' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - Comic.find(@comic.id).visible.should eq 0 - end - context 'html形式' do - it 'ステータスコード302 Foundを返す' do - Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true) - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - response.status.should eq 302 - end - it '更新されたコミックの表示ページへ遷移する' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - response.should redirect_to(@comic) - end - end - context 'json形式' do - it 'ステータスコード200 OKを返す' do - Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true) - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json - response.should be_success - end - it 'ページ本体は特に返さない' do - Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true) - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json - response.body.should match /./ - end - end - end - context '作家権限がないとき' do - before do - sign_out @user - end - it 'ステータスコード302 Foundを返す' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - response.status.should eq 302 - end - context 'html形式' do - it 'サインインページへ遷移する' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - response.body.should redirect_to '/users/sign_in' - end - end - context 'json形式' do - it '応答メッセージにUnauthorizedを返す' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json - response.message.should match(/Unauthorized/) - end - end - end - context '検証、保存に失敗したとき' do - before do - Comic.any_instance.stub(:update_attributes).and_return(false) - end - context 'html形式' do - it 'ステータスコード200 Okを返す' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - response.status.should eq 200 - end - it '編集ページを描画する' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic) - response.should render_template("edit") - end - end - context 'json形式' do - it 'ステータスコード422 unprocessable_entity を返す' do - Comic.any_instance.stub(:update_attributes).and_return(false) - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json - response.status.should eq 422 - end - it '応答メッセージUnprocessable Entityを返す' do - put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json - response.message.should match(/Unprocessable/) - end - end - end - end - - - end + put :update, :id => @comic.id, :comic => @attr + Comic.find(@comic.id).visible.should eq 0 + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true) + put :update, :id => @comic.id, :comic => @attr + response.status.should eq 302 + end + it '更新されたコミックの表示ページへ遷移する' do + put :update, :id => @comic.id, :comic => @attr + response.should redirect_to(@comic) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true) + put :update, :id => @comic.id, :comic => @attr, :format => :json + response.should be_success + end + it 'ページ本体は特に返さない' do + Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true) + put :update, :id => @comic.id, :comic => @attr, :format => :json + response.body.should match /./ + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + it 'ステータスコード302 Foundを返す' do + put :update, :id => @comic.id, :comic => @attr + response.status.should eq 302 + end + context 'html形式' do + it 'サインインページへ遷移する' do + put :update, :id => @comic.id, :comic => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it '応答メッセージにUnauthorizedを返す' do + put :update, :id => @comic.id, :comic => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '検証、保存に失敗したとき' do + before do + Comic.any_instance.stub(:update_attributes).and_return(false) + end + context 'html形式' do + it 'ステータスコード200 Okを返す' do + put :update, :id => @comic.id, :comic => @attr + response.status.should eq 200 + end + it '編集ページを描画する' do + put :update, :id => @comic.id, :comic => @attr + response.should render_template("edit") + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + Comic.any_instance.stub(:update_attributes).and_return(false) + put :update, :id => @comic.id, :comic => @attr, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + put :update, :id => @comic.id, :comic => @attr, :format => :json + response.message.should match(/Unprocessable/) + end + end + end + end + + + end diff --cc spec/controllers/original_pictures_controller_spec.rb index 5d0fec05,4eb1e8d5..d020400b --- a/spec/controllers/original_pictures_controller_spec.rb +++ b/spec/controllers/original_pictures_controller_spec.rb @@@ -594,8 -591,8 +594,8 @@@ describe OriginalPicturesController d describe '更新に於いて' do before do - @pic = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id + @pic = Factory :original_picture, :artist_id => @artist.id - OriginalPicture.stub(:show).with(any_args()).and_return(@pic) + OriginalPicture.stub(:edit).with(any_args()).and_return(@pic) sign_in @user end context '事前チェックしておく' do diff --cc spec/controllers/panel_pictures_controller_spec.rb index 53a448cd,5e8d308e..6ec4aa4d --- a/spec/controllers/panel_pictures_controller_spec.rb +++ b/spec/controllers/panel_pictures_controller_spec.rb @@@ -11,11 -9,8 +11,11 @@@ describe PanelPicturesController d @user = Factory( :user_yas) @author = @user.author @artist = Factory :artist_yas, :author_id => @author.id - @op = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id - @rp = Factory :resource_picture, :artist_id => @artist.id , :license_id => @license.id, :original_picture_id => @op.id + @op = Factory :original_picture, :artist_id => @artist.id + @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id - @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - @attr = {:resource_picture_id => @rp.id, :panel_id => @panel} ++ @panel = Factory :panel, :author_id => @author.id ++ @attr = {:resource_picture_id => @rp.id, :panel_id => @panel.id} end describe '一覧表示に於いて' do diff --cc spec/controllers/panels_controller_spec.rb index 2b3f17ff,ff4c0907..283feb17 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@@ -4,12 -4,9 +4,11 @@@ require 'spec_helper describe PanelsController do before do Factory :admin - @license = Factory :license + @sp = Factory :system_picture + @lg = Factory :license_group + @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @user = Factory :user_yas @author = @user.author #ユーザ作成時に連動して作成される - @comic = Factory :comic, :author_id => @author.id end describe '一覧表示に於いて' do diff --cc spec/controllers/stories_controller_spec.rb index 00000000,51244820..22c1f7b5 mode 000000,100644..100644 --- a/spec/controllers/stories_controller_spec.rb +++ b/spec/controllers/stories_controller_spec.rb @@@ -1,0 -1,434 +1,436 @@@ + # -*- encoding: utf-8 -*- + require 'spec_helper' + #ストーリー + describe StoriesController do + before do + Factory :admin - @license = Factory :license ++ @sp = Factory :system_picture ++ @lg = Factory :license_group ++ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id + @user = Factory :user_yas + @author = @user.author #ユーザ作成時に連動して作成される + @comic = Factory :comic, :author_id => @user.author.id + @panel = Factory :panel, :author_id => @author.id + end + + + describe '閲覧に於いて' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Comic.stub(:show).and_return(@comic) + sign_in @user + end + context '事前チェックする' do + end + context 'つつがなく終わるとき' do + end + context '作家権限がないとき' do + end + end + + describe '新規作成フォーム表示に於いて' do + before do + sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :new + response.should be_success + end + it '@storyに新規データを用意している' do + get :new + assigns(:story).should be_a_new(Story) + end + it 'モデルにデフォルト値補充を依頼している' do + Story.any_instance.should_receive(:supply_default).exactly(1) + get :new + end + context 'html形式' do + it 'newテンプレートを描画する' do + get :new + response.should render_template("new") + end + end + context 'js形式' do + it 'new.jsテンプレートを描画する' do + get :new, :format => :js + response.should render_template("new") + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :new + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :new, :format => :js + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :new, :format => :js + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '新規作成に於いて' do + before do + @attr = Factory.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'デフォルト値補充を依頼する' do + Story.any_instance.should_receive(:supply_default).exactly(1) + post :create, :story => @attr + end + it 'POSTデータから、カラム値を復元している' do + Story.any_instance.stub(:store).and_return(true) + Story.any_instance.should_receive(:attributes=).exactly(1) + post :create, :story => @attr + end + it '上書き補充を依頼する' do + Story.any_instance.should_receive(:overwrite).exactly(1) + post :create, :story => @attr + end + it 'モデルに保存依頼する' do + Story.any_instance.should_receive(:store).exactly(1) + post :create, :story => @attr + end + it "@storyに作成されたコマを保持していて、それがDBにある" do + post :create, :story => @attr + assigns(:story).should be_a(Story) + assigns(:story).should be_persisted + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Story.any_instance.stub(:store).and_return(true) + post :create, :story => @attr + response.status.should eq 302 + end + it 'コミックのストーリー表示へ遷移する' do + # Story.any_instance.stub(:store).and_return(true) + post :create, :story => @attr + response.should redirect_to(:action => :show, :id => @attr[:comic_id]) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + # Story.any_instance.stub(:store).and_return(true) + post :create, :story => @attr, :format => :json + response.should be_success + end + it '作成されたコマをjsonデータで返す' do + post :create, :story => @attr, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'データがアレになっている' do + post :create, :story => @attr, :format => :json + json = JSON.parse response.body + json["t"].should eq 0 + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, :story => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, :story => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + post :create, :story => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + post :create, :story => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '検証、保存に失敗した' do + before do + Story.any_instance.stub(:store).and_return(false) + end + it "未保存のコマを保持している" do + post :create, :story => @attr + assigns(:story).should be_a_new(Story) + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + post :create, :story => @attr + response.status.should eq 200 + end + it '新規ページを描画する' do + post :create, :story => @attr + response.should render_template("new") + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + post :create, :story => @attr, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + post :create, :story => @attr, :format => :json + response.message.should match(/Unprocessable/) + end + end + end + end + + describe '編集フォーム表示に於いて' do + before do + @story = Factory :story, :author_id => @author.id + sign_in @user + Story.stub(:show).and_return(@story) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @story.id + response.should be_success + end + it 'コマモデルに単体取得を問い合わせている' do + Story.should_receive(:show).exactly(1) + get :edit, :id => @story.id + end + it '@storyにデータを用意している' do + get :edit, :id => @story.id + assigns(:story).should eq @story + end + context 'html形式' do + it 'editテンプレートを描画する' do + get :edit, :id => @story.id + response.should render_template("edit") + end + end + context 'js形式' do + it 'edit.jsテンプレートを描画する' do + get :edit, :id => @story.id, :format => :js + response.should render_template("edit") + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :edit, :id => @story.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :edit, :id => @story.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :edit, :id => @story.id, :format => :js + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :edit, :id => @story.id, :format => :js + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '更新に於いて' do + before do + @story = Factory :story, :author_id => @user.author.id + @attr = Factory.attributes_for(:story, :author_id => @author.id) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'モデルに編集取得依頼する' do + Story.stub(:edit).with(any_args).and_return(@story) + Story.should_receive(:edit).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it 'POSTデータから、カラム値を復元している' do + Story.any_instance.stub(:store).and_return(true) + Story.any_instance.should_receive(:attributes=).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it '上書き補充を依頼する' do + Story.any_instance.should_receive(:overwrite).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it 'モデルに保存依頼する' do + Story.any_instance.should_receive(:store).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it "@storyに作成されたストーリーを保持していて、それがDBにある" do + put :update, :id => @story.id, :story => @attr + assigns(:story).should be_a(Story) + assigns(:story).should be_persisted + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Story.any_instance.stub(:store).and_return(true) + put :update, :id => @story.id, :story => @attr + response.status.should eq 302 + end + it 'コミックのストーリー表示へ遷移する' do + # Story.any_instance.stub(:store).and_return(true) + put :update, :id => @story.id, :story => @attr + response.should redirect_to(:action => :show, :id => @attr[:comic_id]) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + # Story.any_instance.stub(:store).and_return(true) + put :update, :id => @story.id, :story => @attr, :format => :json + response.should be_success + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + put :update, :id => @story.id, :story => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + put :update, :id => @story.id, :story => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '検証、保存に失敗した' do + before do + Story.any_instance.stub(:store).and_return(false) + end + it "指定のコマを保持している" do + put :update, :id => @story.id, :story => @attr + assigns(:story).should eq @story + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + put :update, :id => @story.id, :story => @attr + response.status.should eq 200 + end + it '編集ページを描画する' do + put :update, :id => @story.id, :story => @attr + response.should render_template("edit") + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.message.should match(/Unprocessable/) + end + end + end + end + + describe '削除に於いて' do + before do + @story = Factory :story, :author_id => @author.id + sign_in @user + Story.stub(:edit).and_return(@story) + end + context 'つつがなく終わるとき' do + it 'ストーリーモデルに編集取得を問い合わせている' do + Story.should_receive(:edit).exactly(1) + delete :destroy, :id => @story.id + end + it '@storyにアレを取得している' do + delete :destroy, :id => @story.id + assigns(:story).id.should eq(@story.id) + end + it 'そのストーリーを一つのトランザクションで削除する' do + lambda { + delete :destroy, :id => @story.id + }.should change(Story, :count) + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @story.id + response.status.should eq 302 + end + it 'ストーリー一覧ページへ遷移する' do + delete :destroy, :id => @story.id + response.should redirect_to(story_path(@story.comic_id)) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + delete :destroy, :id => @story.id, :format => :json + response.should be_success + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @story.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + delete :destroy, :id => @story.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + delete :destroy, :id => @story.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + delete :destroy, :id => @story.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + =begin + context '対象ストーリーがないとき' do + end + context '他人のストーリーだったとき' do + end + =end + end + + end diff --cc spec/models/balloon_spec.rb index fe027ace,e3cb45e5..2d8bf45a --- a/spec/models/balloon_spec.rb +++ b/spec/models/balloon_spec.rb @@@ -27,6 -28,6 +27,7 @@@ describe Balloon d before do @balloon = Factory.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id end ++ #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @balloon.speech_balloon_id = @speech_balloon.id @balloon.should be_valid diff --cc spec/models/comic_spec.rb index 36aa9211,b9abac2f..79142f73 --- a/spec/models/comic_spec.rb +++ b/spec/models/comic_spec.rb @@@ -4,6 -4,7 +4,9 @@@ require 'spec_helper describe Comic do before do Factory :admin - @license = Factory :license ++ @sp = Factory :system_picture ++ @lg = Factory :license_group ++ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @user = Factory( :user_yas) @author = @user.author @artist = Factory :artist_yas, :author_id => @author.id diff --cc spec/models/original_picture_spec.rb index 2fa0f8ed,dd685eae..333fd64a --- a/spec/models/original_picture_spec.rb +++ b/spec/models/original_picture_spec.rb @@@ -193,41 -224,46 +193,42 @@@ describe OriginalPicture d end end end - describe '関連テーブルプションに於いて' do - context 'オプションがないとき' do - it '1つの項目を含んでいる' do - r = OriginalPicture.show_include_opt - r.should have(1).items - end - it '素材を含んでいる' do - r = OriginalPicture.show_include_opt - r.has_key?(:resource_picture).should be_true - end - end - context 'オプションでtestを含ませたとき' do - it '2つの項目を含んでいる' do - r = OriginalPicture.show_include_opt(:include => {:test => {}}) - r.should have(2).items - end - it 'testを含んでいる' do - r = OriginalPicture.show_include_opt(:include => {:test => {}}) - r.has_key?(:test).should be_true - end - end + describe '編集取得に於いて' do + before do + @op = Factory :original_picture, :artist_id => @artist.id + end + it '指定の原画を返す' do + pic = OriginalPicture.edit @op.id, @artist + pic.should eq @op + end - context '関連テーブルオプションがないとき' do - it 'ライセンスと素材を含んでいる' do - r = OriginalPicture.show_include_opt - r.should eq [:license, :resource_picture] - end - end - context '関連テーブルオプションで絵師を含ませたとき' do - it 'ライセンスと素材と作者データを含んでいる' do - r = OriginalPicture.show_include_opt(:include => :artist) - r.should eq [:license, :resource_picture, :artist] - end - end + context '他人の原画を開こうとしたとき' do + it '403Forbidden例外を返す' do + lambda{ + pic = OriginalPicture.edit @op.id, @other_artist + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない原画を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + pic = OriginalPicture.edit 0, @artist + }.should raise_error(ActiveRecord::RecordNotFound) + end + end end describe 'json単体出力オプションに於いて' do - it 'includeキーがライセンスと素材を含んでいる' do - r = OriginalPicture.show_json_include_opt - r[:include].should eq [:license, :resource_picture] - end + it 'includeキーを含んでいる' do + r = OriginalPicture.show_json_include_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = OriginalPicture.show_json_include_opt[:include] + r.should have(1).items + end + it '素材を含んでいる' do + r = OriginalPicture.show_json_include_opt[:include] + r.has_key?(:resource_picture).should be_true + end end describe '一覧取得に於いて' do before do diff --cc spec/models/panel_picture_spec.rb index e393f673,15203821..8842c558 --- a/spec/models/panel_picture_spec.rb +++ b/spec/models/panel_picture_spec.rb @@@ -29,6 -26,6 +29,7 @@@ describe PanelPicture d before do @pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id end ++ #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @pp.panel_id = @panel.id @pp.should be_valid @@@ -37,11 -34,28 +38,7 @@@ @pp.panel_id = 'a' @pp.should_not be_valid end - it '存在するコマでなければ失敗する' do - @pp.panel_id = 0 - @pp.should_not be_valid - end end - context 'resource_picture_idを検証するとき' do - before do - @pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id - end - it 'テストデータの確認' do - @pp.resource_picture_id = @rp.id - @pp.should be_valid - end - it 'nullなら失敗する' do - @pp.resource_picture_id = nil - @pp.should_not be_valid - end - it '数値でなければ失敗する' do - @pp.resource_picture_id = 'a' - @pp.should_not be_valid - end - it '存在するフキダシテンプレートでなければ失敗する' do - @pp.resource_picture_id = 0 - @pp.should_not be_valid - end - end context 'linkを検証するとき' do before do @pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id diff --cc spec/models/speech_balloon_spec.rb index 69455900,c7392fb5..b3c9c92a --- a/spec/models/speech_balloon_spec.rb +++ b/spec/models/speech_balloon_spec.rb @@@ -26,6 -27,6 +26,7 @@@ describe SpeechBalloon d before do @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id end ++ #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @sb.panel_id = @panel.id @sb.should be_valid diff --cc spec/models/speech_spec.rb index 47c0e29f,821f4360..2b22724c --- a/spec/models/speech_spec.rb +++ b/spec/models/speech_spec.rb @@@ -25,6 -23,6 +25,7 @@@ describe Speech d before do @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end ++ #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @speech.speech_balloon_id = @speech_balloon.id @speech.should be_valid diff --cc spec/models/story_spec.rb index 00000000,1f9a23e9..f655870c mode 000000,100644..100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@@ -1,0 -1,1341 +1,1343 @@@ + # -*- encoding: utf-8 -*- + require 'spec_helper' + #ストーリー + describe Story do + before do + Factory :admin - @license = Factory :license ++ @sp = Factory :system_picture ++ @lg = Factory :license_group ++ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id + @user = Factory( :user_yas) + @author = @user.author + @artist = Factory :artist_yas, :author_id => @author.id + @other_user = Factory( :user_yas) + @other_author = @other_user.author + end + + describe '検証に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + + it 'オーソドックスなデータなら通る' do + @story.should be_valid + end + + context 'comic_idを検証するとき' do + it 'テストデータの確認' do + @story.comic_id = @comic.id + @story.should be_valid + end + it 'nullなら失敗する' do + @story.comic_id = nil + @story.should_not be_valid + end + it '数値でなければ失敗する' do + @story.comic_id = 'a' + @story.should_not be_valid + end + it '存在するコミックでなければ失敗する' do + @story.comic_id = 0 + @story.should_not be_valid + end + end + + context 'panel_idを検証するとき' do + it 'テストデータの確認' do + @story.panel_id = @panel.id + @story.should be_valid + end + it 'nullなら失敗する' do + @story.panel_id = nil + @story.should_not be_valid + end + it '数値でなければ失敗する' do + @story.panel_id = 'a' + @story.should_not be_valid + end + it '存在するコマでなければ失敗する' do + @story.panel_id = 0 + @story.should_not be_valid + end + end + + context 'tを検証するとき' do + before do + end + it 'テストデータの確認' do + @story.t = 0 + @story.should be_valid + end + it 'nullなら失敗する' do + @story.t = nil + @story.should_not be_valid + end + it '数値でなければ失敗する' do + @story.t = 'a' + @story.should_not be_valid + end + it '負なら失敗する' do + @story.t = -1 + @story.should_not be_valid + end + end + + context 'author_idを検証するとき' do + it 'テストデータの確認' do + @story.author_id = @author.id + @story.should be_valid + end + it 'nullなら失敗する' do + @story.author_id = nil + @story.should_not be_valid + end + it '数値でなければ失敗する' do + @story.author_id = 'a' + @story.should_not be_valid + end + it '存在する作家でなければ失敗する' do + @story.author_id = 0 + @story.should_not be_valid + end + end + context '全体を検証するとき' do + before do + @story = Factory :story, :author_id => @author.id + end + end + end + + describe 'デフォルト値補充に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + + #dbのデフォルト値が0だから明示的にnilにしないと追加ができない + it 'tをnilにする' do + @story = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id + @story.supply_default + @story.t.should be_nil + end + + end + + describe '上書き補充に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + + context 'author_idを補充' do + it '問答無用でauthor_idを補充する' do + @story = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id + @story.author_id = nil + @story.overwrite @author + @story.author_id.should eq @author.id + end + end + + end + + describe '作者判定に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + @comico = Factory :comic, :author_id => @other_author.id + @panelo = Factory :panel, :author_id => @other_author.id + @storyo = Factory :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id + end + it '自分のストーリーならyes' do + @story.own?(@author).should == true + end + it '他人のストーリーならno' do + @storyo.own?(@author).should == false + end + it '作家が不明ならno' do + @story.own?(nil).should == false + end + end + describe '単体取得に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + end + it '指定のストーリーを返す' do + l = Story.edit @story.id, @author + l.should eq @story + end + context '他人のストーリーを開こうとしたとき' do + it '403Forbidden例外を返す' do + Story.any_instance.stub(:own?).and_return(false) + lambda{ + Story.edit @story.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しないストーリーを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Story.edit 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + + describe '一覧取得に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + @panel2 = Factory :panel, :author_id => @author.id, :publish => 0 + end + context 'offset補正について' do + it '文字列から数値に変換される' do + Story.offset(100, '8').should eq 8 + end + it 'nilの場合は0になる' do + Story.offset(100).should eq 0 + end + #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる + #最後のコマとは、コマ数‐1. + it '1件のときオフセット1なら0になる' do + Story.offset(1, '1').should eq 0 + end + it '5件のときオフセット5なら4になる' do + Story.offset(5, '5').should eq 4 + end + # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。 + #-4のときは、最後から4つのコマを表示する。 + it '2件のときオフセット-1なら1になる' do + Story.offset(2, '-1').should eq 1 + end + it '5件のときオフセット-2なら3になる' do + Story.offset(5, '-2').should eq 3 + end + # 最終的なが負になるなど、不正な値が入ったときは0となる。 + it '2件のときオフセット-5なら0になる' do + Story.offset(2, '-5').should eq 0 + end + end + context 'panel_count補正について' do + it '文字列から数値に変換される' do + Story.panel_count(100, '7').should eq 7 + end + it 'nilの場合はStory.default_panel_sizeになる' do + Story.panel_count(100).should eq Story.default_panel_size + end + it '0以下の場合はStory.default_panel_sizeになる' do + Story.panel_count(100, '0').should eq Story.default_panel_size + end + it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do + Story.panel_count(100, '1000').should eq Story.max_panel_size + end + end + it 'リストを返す' do + c = Story.list @comic, @author + c.should eq [@story] + end + it 't順で並んでいる' do + v = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1 + c = Story.list @comic, @author + c.should eq [ @story, v] + end + it '非公開のコマは含まない' do + h = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1 + c = Story.list @comic, @author + c.should eq [ @story] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @story2 = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1 + @story3 = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2 + @story4 = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3 + @story5 = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4 + end + it 'offset=0なら末尾2件を返す' do + #時系列で並んでいる + c = Story.list( @comic, @author, 0, 2) + c.should eq [@story, @story2] + end + it 'offset=2なら中間2件を返す' do + c = Story.list(@comic, @author, 2, 2) + c.should eq [@story3, @story4] + end + it 'offset=4なら先頭1件を返す' do + c = Story.list(@comic, @author, 4, 2) + c.should eq [@story5] + end + end + end + describe 'list関連テーブルプションに於いて' do + it 'includeキーを含んでいる' do + r = Story.list_opt + r.has_key?(:include).should be_true + end + it '3つの項目を含んでいる' do + r = Story.list_opt[:include] + r.should have(3).items + end + it 'コミックを含んでいる' do + r = Story.list_opt[:include] + r.has_key?(:comic).should be_true + end + it 'コミックは作家を含んでいる' do + r = Story.list_opt[:include] + r[:comic].has_key?(:author).should be_true + end + it '作家を含んでいる' do + r = Story.list_opt[:include] + r.has_key?(:author).should be_true + end + it 'コマを含んでいる' do + r = Story.list_opt[:include] + r.has_key?(:panel).should be_true + end + it 'コマは作家を含んでいる' do + r = Story.list_opt[:include] + r[:panel].has_key?(:author).should be_true + end + it 'コマはコマ絵を含んでいる' do + r = Story.list_opt[:include] + r[:panel].has_key?(:panel_pictures).should be_true + end + it 'コマはフキダシを含んでいる' do + r = Story.list_opt[:include] + r[:panel].has_key?(:speech_balloons).should be_true + end + end + describe 'json一覧出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = Story.list_json_opt + r.has_key?(:include).should be_true + end + it '3つの項目を含んでいる' do + r = Story.list_json_opt[:include] + r.should have(3).items + end + it 'コミックを含んでいる' do + r = Story.list_json_opt[:include] + r.has_key?(:comic).should be_true + end + it 'コミックは作家を含んでいる' do + r = Story.list_json_opt[:include] + r[:comic].has_key?(:author).should be_true + end + it '作家を含んでいる' do + r = Story.list_json_opt[:include] + r.has_key?(:author).should be_true + end + it 'コマを含んでいる' do + r = Story.list_json_opt[:include] + r.has_key?(:panel).should be_true + end + it 'コマは作家を含んでいる' do + r = Story.list_json_opt[:include] + r[:panel].has_key?(:author).should be_true + end + it 'コマはコマ絵を含んでいる' do + r = Story.list_json_opt[:include] + r[:panel].has_key?(:panel_pictures).should be_true + end + it 'コマはフキダシを含んでいる' do + r = Story.list_json_opt[:include] + r[:panel].has_key?(:speech_balloons).should be_true + end + end + describe 't補充値に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + + context 'コミック初のコマなら' do + it '0を補充値とする' do + @story = Factory.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + @story.t = nil + r = Story.new_t @story.comic_id + r.should eq 0 + end + end + context 'コミックに一個コマがあるとき' do + it '1を補充値とする' do + Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0 + @story = Factory.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + @story.t = nil + r = Story.new_t @story.comic_id + r.should eq 1 + end + end + context 'コミックに2個コマがあるとき' do + it '2を補充値とする' do + Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0 + Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1 + @story = Factory.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + @story.t = nil + r = Story.new_t @story.comic_id + r.should eq 2 + end + end + end + describe 'シリアライズチェックに於いて' do + context 'つつがなく終わるとき' do + it '0からシリアライズされているならTrueを返す' do + r = Story.serial? [0, 1, 2] + r.should be_true + end + it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do + r = Story.serial? [0, 2, 1] + r.should be_true + end + it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do + r = Story.serial? [ 2, 1, 4, 3, 0] + r.should be_true + end + end + context '異常なとき' do + it '0から始まらないならFalseを返す' do + r = Story.serial? [1, 2, 3] + r.should be_false + end + it '連続していないならFalseを返す' do + r = Story.serial? [0, 1, 2, 4] + r.should be_false + end + it '連続していないならFalseを返す' do + r = Story.serial? [0, 1, 2, 4, 5] + r.should be_false + end + end + end + describe 't収集に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @comic2 = Factory :comic, :author_id => @author.id + @c2story = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it 'ストーリーから同一コミックのtだけを収集している' do + r = Story.collect_t @story + r.should eq [0] + end + end + context '複数コマのとき' do + it 'ストーリーから同一コミックのtだけを収集している' do + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + r = Story.collect_t @story + r.sort.should eq [0, 1] + end + end + context '複数コマでヨソのコミックも混じっているとき' do + it 'ストーリーから同一コミックのtだけを収集している' do + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + r = Story.collect_t @story + r.sort.should eq [0, 1] + end + end + end + describe 'tチェックに於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it 't収集を依頼している' do + Story.should_receive(:collect_t).with(any_args).exactly(1) + Story.stub(:collect_t).with(any_args).and_return([]) + Story.stub(:serial?).with(any_args).and_return(true) + r = Story.validate_t @story + end + it '収集したtをシリアライズチェック依頼している' do + Story.stub(:collect_t).with(any_args).and_return([]) + Story.should_receive(:serial?).with(any_args).exactly(1) + Story.stub(:serial?).with(any_args).and_return(true) + r = Story.validate_t @story + end + end + #実データでチェック + #依頼チェックだけでは不安なので最低限のチェックを + context '新規のとき' do + it '一件だけで正常通過している' do + @story = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0 + r = Story.validate_t @story + r.should be_true + end + end + context '既存のとき' do + it '2件目を作っても正常通過している' do + @story = Factory :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0 + @story2 = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1 + r = Story.validate_t @story2 + r.should be_true + end + end + end + describe '挿入シフトに於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + context '依頼チェック' do + #テーブルが空で0に挿入 + it 'Updateを依頼している' do + Story.stub(:update_all).with(any_args) + Story.should_receive(:update_all).with(any_args).exactly(1) + @story = Factory.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story.insert_shift + end + end + context 'テーブルに1件(t:0)で0に挿入したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '既存の行を1にシフトしている' do + @story2.insert_shift + l = Story.find :all + l.first.t.should eq 1 + end + it 'これから挿入するt(0)が欠番になっている' do + @story2.insert_shift + l = Story.find(:all).map {|s| s.t } + l.include?(0).should_not be_true + end + end + context 'テーブルに2件(t:0,1)で1に挿入したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do + @story3.insert_shift + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 2] + end + end + context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story6 = Factory.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do + @story6.insert_shift + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 1, 3, 4, 5] + end + end + context '先ほどのケース+他のコミック1件で挿入したとき' do + before do + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story6 = Factory.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do + @story6.insert_shift + l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t } + l.sort.should eq [0, 1, 3, 4, 5] + end + it '他のコミックに影響がない' do + ot = @storyc2.t + @story6.insert_shift + @storyc2.reload + @storyc2.t.should eq ot + end + end + end + describe '少ない方に移動に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + context '依頼チェック' do + it 'Updateを依頼している' do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Story.stub(:update_all).with(any_args) + Story.should_receive(:update_all).with(any_args).exactly(1) + ot = @story2.t + @story2.t = 0 + @story2.lesser_shift ot + end + end + context 'テーブルに2件(t:0,1)で1を0に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story2.t + @story2.t = 0 + end + it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do + #移動させたい行はそのまま残る + @story2.lesser_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [1, 1] + end + it '既存のt0を1にシフトしている' do + @story2.lesser_shift @ot + @story.reload + @story.t.should eq 1 + end + end + context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story3.t + @story3.t = 1 + end + it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do + #移動させたい行はそのまま残る + @story3.lesser_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 2, 2] + end + it '既存のt1を2にシフトしている' do + @story3.lesser_shift @ot + @story2.reload + @story2.t.should eq 2 + end + end + context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story4.t + @story4.t = 1 + end + it 'これから挿入するt(1)が欠番になっている' do + #移動させたい行はそのまま残る + @story4.lesser_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 2, 3, 3, 4] + end + it '既存のt0には変化がない' do + @story4.lesser_shift @ot + @story.reload + @story.t.should eq 0 + end + it '既存のt4には変化がない' do + @story4.lesser_shift @ot + @story5.reload + @story5.t.should eq 4 + end + it '既存のt1を2にシフトしている' do + @story4.lesser_shift @ot + @story2.reload + @story2.t.should eq 2 + end + it '既存のt2を3にシフトしている' do + @story4.lesser_shift @ot + @story3.reload + @story3.t.should eq 3 + end + end + context '先ほどのケース+他のコミック1件で挿入したとき' do + before do + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story4.t + @story4.t = 1 + end + it 'これから挿入するt(1)が欠番になっている' do + @story4.lesser_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 0, 2, 3, 3, 4] + end + it '既存のt0には変化がない' do + @story4.lesser_shift @ot + @story.reload + @story.t.should eq 0 + end + it '既存のt4には変化がない' do + @story4.lesser_shift @ot + @story5.reload + @story5.t.should eq 4 + end + it '既存のt1を2にシフトしている' do + @story4.lesser_shift @ot + @story2.reload + @story2.t.should eq 2 + end + it '既存のt2を3にシフトしている' do + @story4.lesser_shift @ot + @story3.reload + @story3.t.should eq 3 + end + it '他のコミックに影響がない' do + @story4.lesser_shift @ot + @storyc2.reload + @storyc2.t.should eq 0 + end + end + #例外ケース。 + #負のときは0として正常扱い + context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story2.t + @story2.t = -1 + end + it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do + #移動させたい行はそのまま残る + @story2.lesser_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [1, 1] + end + it '既存のt0を1にシフトしている' do + @story2.lesser_shift @ot + @story.reload + @story.t.should eq 1 + end + it '既存のt1は0に補正されている' do + @story2.lesser_shift @ot + @story2.t.should eq 0 + end + end + end + describe '大きい方に移動に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + context '依頼チェック' do + it 'Updateを依頼している' do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Story.stub(:update_all).with(any_args) + Story.should_receive(:update_all).with(any_args).exactly(1) + ot = @story.t + @story.t = 1 + @story.higher_shift ot + end + end + context 'テーブルに2件(t:0,1)で0を1に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story.t + @story.t = 1 + end + it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do + #移動させたい行はそのまま残る + @story.higher_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 0] + end + it '既存のt1を0にシフトしている' do + @story.higher_shift @ot + @story2.reload + @story2.t.should eq 0 + end + end + context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story.t + @story.t = 1 + end + it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do + #移動させたい行はそのまま残る + @story.higher_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 0, 2] + end + it '既存のt1を0にシフトしている' do + @story.higher_shift @ot + @story2.reload + @story2.t.should eq 0 + end + end + context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story2.t + @story2.t = 3 + end + it 'これから挿入するt(3)が欠番になっている' do + #移動させたい行はそのまま残る + @story2.higher_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 1, 1, 2, 4] + end + it '既存のt0には変化がない' do + @story2.higher_shift @ot + @story.reload + @story.t.should eq 0 + end + it '既存のt4には変化がない' do + @story2.higher_shift @ot + @story5.reload + @story5.t.should eq 4 + end + it '既存のt2を1にシフトしている' do + @story2.higher_shift @ot + @story3.reload + @story3.t.should eq 1 + end + it '既存のt3を2にシフトしている' do + @story2.higher_shift @ot + @story4.reload + @story4.t.should eq 2 + end + end + context '先ほどのケース+他のコミック1件で挿入したとき' do + before do + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story2.t + @story2.t = 3 + end + it 'これから挿入するt(3)が欠番になっている' do + #移動させたい行はそのまま残る + @story2.higher_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 0, 1, 1, 2, 4] + end + it '既存のt0には変化がない' do + @story2.higher_shift @ot + @story.reload + @story.t.should eq 0 + end + it '既存のt4には変化がない' do + @story2.higher_shift @ot + @story5.reload + @story5.t.should eq 4 + end + it '既存のt2を1にシフトしている' do + @story2.higher_shift @ot + @story3.reload + @story3.t.should eq 1 + end + it '既存のt3を2にシフトしている' do + @story2.higher_shift @ot + @story4.reload + @story4.t.should eq 2 + end + it '他のコミックに影響がない' do + @story2.higher_shift @ot + @storyc2.reload + @storyc2.t.should eq 0 + end + end + #例外ケース。 + #max超えたときはmaxとして正常扱い + context 'テーブルに2件(t:0,1)で0を2に移動したとき' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story.t + @story.t = 2 + end + it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do + #移動させたい行はそのまま残る + @story.higher_shift @ot + l = Story.find(:all).map {|s| s.t } + l.sort.should eq [0, 0] + end + it '既存のt1を0にシフトしている' do + @story.higher_shift @ot + @story2.reload + @story2.t.should eq 0 + end + it '既存のt0は1に補正されている' do + @story.higher_shift @ot + @story.t.should eq 1 + end + end + end + describe '入れ替えに於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + context '新tが旧tより小さいとき' do + it '少ない方に移動を依頼している' do + Story.any_instance.stub(:lesser_shift).with(any_args) + Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1) + ot = @story2.t + @story2.t = 0 + @story2.update_shift ot + end + end + context '新tが旧tより大きいとき' do + it '大きい方に移動を依頼している' do + Story.any_instance.stub(:higher_shift).with(any_args) + Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1) + ot = @story.t + @story.t = 1 + @story.update_shift ot + end + end + end + describe '順序入れ替えに於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + end + context 'オブジェクトが新規でtが空のとき' do + it '末尾追加としてtを補充依頼している' do + @story = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Story.stub(:new_t).with(any_args).and_return(0) + Story.should_receive(:new_t).with(any_args).exactly(1) + @story.t = nil + r = @story.rotate + end + end + context 'オブジェクトが新規でtが設定されているとき' do + it '挿入追加として挿入シフトを依頼している' do + @story = Factory.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Story.any_instance.stub(:insert_shift).with(any_args) + Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1) + @story.t = 0 + r = @story.rotate + end + end + context 'オブジェクトが新規でなくtが設定されているとき' do + it 'コマ移動として入れ替えを依頼している' do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Story.any_instance.stub(:update_shift).with(any_args) + Story.any_instance.should_receive(:update_shift).with(1).exactly(1) + @story2.t = 0 + r = @story.rotate 1 + end + end + context 'オブジェクトが新規でなくtが空のとき' do + it '入れ替えもシフトもせず、tを空のままにしている' do + #結果、tに欠番が生じてシリアライズチェックでひっかかる + end + end + end + describe '編集許可に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it 'trueを返す' do + r = @story.allow? + r.should be_true + end + end + context 'コミックで引っかかるとき' do + it 'falseを返す' do + @story.comic_id = nil + r = @story.allow? + r.should be_false + end + it 'falseを返す' do + Comic.any_instance.stub(:own?).with(any_args).and_return(false) + r = @story.allow? + r.should be_false + end + end + context 'コマで引っかかるとき' do + it 'falseを返す' do + @story.panel_id = nil + r = @story.allow? + r.should be_false + end + it 'falseを返す' do + Panel.any_instance.stub(:usable?).with(any_args).and_return(false) + r = @story.allow? + r.should be_false + end + end + end + describe '保存に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it '編集許可チェックを依頼している' do + Story.any_instance.stub(:allow?).with(any_args).and_return(true) + Story.any_instance.should_receive(:allow?).with(any_args).exactly(1) + r = @story.store + end + it '順序入れ替えを依頼している' do + Story.any_instance.stub(:rotate).with(any_args).and_return(0) + Story.any_instance.should_receive(:rotate).with(any_args).exactly(1) + Story.any_instance.stub(:save).with(any_args).and_return(true) + Story.stub(:validate_t).with(any_args).and_return(true) + r = @story.store + end + it '保存を依頼している' do + Story.stub(:new_t).with(any_args).and_return(0) + Story.any_instance.stub(:save).with(any_args).and_return(true) + Story.any_instance.should_receive(:save).with(any_args).exactly(1) + Story.stub(:validate_t).with(any_args).and_return(true) + r = @story.store + end + it 'tのシリアライズチェックを依頼している' do + Story.stub(:new_t).with(any_args).and_return(0) + Story.any_instance.stub(:save).with(any_args).and_return(true) + Story.stub(:validate_t).with(any_args).and_return(true) + Story.should_receive(:validate_t).with(any_args).exactly(1) + r = @story.store + end + end + #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている + context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do + before do + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story6 = Factory.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '既存のt0には変化がない' do + @story6.store + @story.reload + @story.t.should eq 0 + end + it '既存のt1には変化がない' do + @story6.store + @story2.reload + @story2.t.should eq 1 + end + it '既存のt2を3にシフトしている' do + @story6.store + @story3.reload + @story3.t.should eq 3 + end + it '既存のt3を4にシフトしている' do + @story6.store + @story4.reload + @story4.t.should eq 4 + end + it '既存のt5を5にシフトしている' do + @story6.store + @story5.reload + @story5.t.should eq 5 + end + it '新規のt2が作成されている' do + @story6.store + @story6.reload + @story6.t.should eq 2 + end + it '他のコミックに影響がない' do + @ot = @storyc2.t + @story6.store + @storyc2.reload + @storyc2.t.should eq @ot + end + end + context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do + before do + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story4.t + @story4.t = 1 + end + it '既存のt0には変化がない' do + @story4.store @ot + @story.reload + @story.t.should eq 0 + end + it '既存のt4には変化がない' do + @story4.store @ot + @story5.reload + @story5.t.should eq 4 + end + it '既存のt1を2にシフトしている' do + @story4.store @ot + @story2.reload + @story2.t.should eq 2 + end + it '既存のt2を3にシフトしている' do + @story4.store @ot + @story3.reload + @story3.t.should eq 3 + end + it '既存のt3を1にシフトしている' do + @story4.store @ot + @story4.reload + @story4.t.should eq 1 + end + it '他のコミックに影響がない' do + @story4.store @ot + @storyc2.reload + @storyc2.t.should eq 0 + end + end + context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do + before do + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story2.t + @story2.t = 3 + end + it '既存のt0には変化がない' do + @story2.store @ot + @story.reload + @story.t.should eq 0 + end + it '既存のt4には変化がない' do + @story2.store @ot + @story5.reload + @story5.t.should eq 4 + end + it '既存のt1を3にシフトしている' do + @story2.store @ot + @story2.reload + @story2.t.should eq 3 + end + it '既存のt2を1にシフトしている' do + @story2.store @ot + @story3.reload + @story3.t.should eq 1 + end + it '既存のt3を2にシフトしている' do + @story2.store @ot + @story4.reload + @story4.t.should eq 2 + end + it '他のコミックに影響がない' do + @story2.store @ot + @storyc2.reload + @storyc2.t.should eq 0 + end + end + #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する + context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do + before do + Story.any_instance.stub(:save).with(any_args).and_return(false) + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story6 = Factory.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '既存のtに変化がない' do + @story6.store + @story.reload + @story.t.should eq 0 + @story2.reload + @story2.t.should eq 1 + @story3.reload + @story3.t.should eq 2 + @story4.reload + @story4.t.should eq 3 + @story5.reload + @story5.t.should eq 4 + @storyc2.reload + @storyc2.t.should eq 0 + end + it 'falseを返す' do + r = @story6.store + r.should be_false + end + end + context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do + before do + Story.stub(:validate_t).with(any_args).and_return(false) + @comic2 = Factory :comic, :author_id => @author.id + @storyc2 = Factory :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @ot = @story4.t + @story4.t = 1 + end + it '既存のtに変化がない' do + @story4.store @ot + @story.reload + @story.t.should eq 0 + @story2.reload + @story2.t.should eq 1 + @story3.reload + @story3.t.should eq 2 + @story4.reload + @story4.t.should eq 3 + @story5.reload + @story5.t.should eq 4 + @storyc2.reload + @storyc2.t.should eq 0 + end + it 'falseを返す' do + r = @story4.store @ot + r.should be_false + end + it 'tにエラーメッセージが入っている' do + @story4.store @ot + @story4.errors[:t].should_not be_empty + @story4.valid?.should be_true + end + end + context '編集不可だったとき' do + before do + @story = Factory.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Story.any_instance.stub(:allow?).and_return(false) + end + it '403Forbidden例外を返す' do + lambda{ + @story.store + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + describe '切り詰め処理つき削除に於いて' do + before do + @comic = Factory :comic, :author_id => @author.id + @panel = Factory :panel, :author_id => @author.id + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it '削除される' do + lambda{ + @story.destroy_and_shorten + }.should change(Story, :count ).by(-1) + end + end + #連携テスト。切り詰めが直接DBをいじる + context '2件で先頭を削除したとき' do + before do + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '行が削除される' do + lambda{ + @story.destroy_and_shorten + }.should change(Story, :count ).by(-1) + end + it '先頭は削除される' do + @story.destroy_and_shorten + lambda{ + Story.find @story.id + }.should raise_error(ActiveRecord::RecordNotFound) + end + it '2件目は前に詰められる' do + @story.destroy_and_shorten + @story2.reload + @story2.t.should eq 0 + end + end + context '3件で先頭を削除したとき' do + before do + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '行が削除される' do + lambda{ + @story.destroy_and_shorten + }.should change(Story, :count ).by(-1) + end + it '先頭は削除される' do + @story.destroy_and_shorten + lambda{ + Story.find @story.id + }.should raise_error(ActiveRecord::RecordNotFound) + end + it '2件目は前に詰められる' do + @story.destroy_and_shorten + @story2.reload + @story2.t.should eq 0 + end + it '3件目は前に詰められる' do + @story.destroy_and_shorten + @story3.reload + @story3.t.should eq 1 + end + end + context '5件で3件目を削除したとき' do + before do + @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story3 = Factory :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story4 = Factory :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + @story5 = Factory :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + end + it '行が削除される' do + lambda{ + @story3.destroy_and_shorten + }.should change(Story, :count ).by(-1) + end + it '1件目は変化がない' do + @story3.destroy_and_shorten + @story.reload + @story.t.should eq 0 + end + it '2件目は変化がない' do + @story3.destroy_and_shorten + @story2.reload + @story2.t.should eq 1 + end + it '3件目は削除される' do + @story3.destroy_and_shorten + lambda{ + Story.find @story3.id + }.should raise_error(ActiveRecord::RecordNotFound) + end + it '4件目は前に詰められる' do + @story3.destroy_and_shorten + @story4.reload + @story4.t.should eq 2 + end + it '5件目は前に詰められる' do + @story3.destroy_and_shorten + @story5.reload + @story5.t.should eq 3 + end + end + #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する + end + end