# -*- encoding: utf-8 -*-
+#原画
require 'spec_helper'
describe OriginalPicturesController do
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
describe '一覧表示に於いて' do
before do
- @op = Factory :original_picture, :artist_id => @artist.id
+ @op = Factory :original_picture, :artist_id => @artist.id
sign_in @user
OriginalPicture.stub(:list).and_return([@op, @op, @op])
end
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 OriginalPicture.default_page_size\r
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 1500
+ assigns(:page_size).should eq OriginalPicture.max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 0
+ assigns(:page_size).should eq OriginalPicture.default_page_size
+ end
end
context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
describe '単体表示に於いて' do
before do
- @pic = Factory :original_picture, :artist_id => @artist.id
+ @pic = Factory :original_picture, :artist_id => @artist.id
sign_in @user
OriginalPicture.stub(:show).and_return(@pic)
end
end
end
end
+=begin
context '対象原画がないとき' do
before do
OriginalPicture.unstub(:show)
end
end
end
+=end
end
describe '新規作成フォーム表示に於いて' do
before do
sign_in @user
end
- context 'つつがなく終わるとき' do
+ context '事前チェックしておく' do
+ before do
+ OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
+ end
it 'モデルに保存依頼する' do
- OriginalPicture.any_instance.should_receive(:save).exactly(1)
+ OriginalPicture.any_instance.should_receive(:store).exactly(1)
post :create, :original_picture => Factory.attributes_for(:original_picture)
end
- it "@original_pictureã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9få\8e\9fç\94»ã\82\92ä¿\9dæ\8c\81ã\81\97ã\81¦ã\81\84ã\81¦ã\80\81ã\81\9dã\82\8cã\81\8cDBã\81«ã\81\82ã\82\8b" do
+ it "@original_pictureに作成された原画を保持している" do
post :create, :original_picture => Factory.attributes_for(:original_picture)
assigns(:original_picture).should be_a(OriginalPicture)
- assigns(:original_picture).should be_persisted
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
+ assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
+ assigns(:original_picture).save
+ true
+ }
+ end
+ it "作成された原画がDBにある" do
+ post :create, :original_picture => Factory.attributes_for(:original_picture)
+ assigns(:original_picture).should_not be_a_new OriginalPicture
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
post :create, :original_picture => Factory.attributes_for(:original_picture)
response.status.should eq 302
end
it '作成された原画の表示ページへ遷移する' do
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
post :create, :original_picture => Factory.attributes_for(:original_picture)
response.should redirect_to(OriginalPicture.last)
end
end
context 'json形式' do
it 'ステータスコード200 OKを返す' do
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
response.should be_success
end
it '作成された原画をjsonデータで返す' do
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
it 'データがアレになっている' do
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
- post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+ post :create, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg'), :format => :json
json = JSON.parse response.body
- json["ext"].should match(/png/)
+ json["ext"].should match(/jpeg/)
end
end
end
end
context '検証、保存に失敗した' do
before do
- OriginalPicture.any_instance.stub(:save).and_return(false)
+ OriginalPicture.any_instance.stub(:store).and_return(false)
end
it "未保存のコミックを保持している" do
post :create, :original_picture => Factory.attributes_for(:original_picture)
describe '編集フォーム表示に於いて' do
before do
- @pic = Factory :original_picture, :artist_id => @artist.id
+ @pic = Factory :original_picture, :artist_id => @artist.id
sign_in @user
OriginalPicture.stub(:show).and_return(@pic)
end
end
it '原画モデルに単体取得を問い合わせている' do
OriginalPicture.should_receive(:show).exactly(1)\r
- get :show
+ get :edit, :id => @pic.id
end
it '@original_pictureにデータを用意している' do
get :edit, :id => @pic.id
end
end
end
- context '対象コミックがないとき' do
- before do
- OriginalPicture.unstub(:show)
- end
- context 'html形式' do
- it '例外404 not_foundを返す' do
- lambda{
- get :edit, :id => 0
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- context 'js形式' do
- it '例外404 not_foundを返す' do
- lambda{
- get :edit, :id => 0, :format => :js
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- end
- context '他人の原画を見ようとしたとき' do
- before do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
- end
- context 'html形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- get :edit, :id => @pic.id
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- context 'js形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- get :edit, :id => @pic.id, :format => :js
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- end
end
describe '更新に於いて' do
before do
- @pic = Factory :original_picture, :artist_id => @artist.id
+ @pic = Factory :original_picture, :artist_id => @artist.id
+ OriginalPicture.stub(:show).with(any_args()).and_return(@pic)
sign_in @user
end
context '事前チェックしておく' do
+ before do
+ OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
+ end
it '原画モデルに単体取得を問い合わせている' do
OriginalPicture.should_receive(:show).exactly(1)\r
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
end
it 'モデルに更新を依頼する' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
- OriginalPicture.any_instance.should_receive(:save).exactly(1)
+ OriginalPicture.any_instance.should_receive(:store).exactly(1)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
end
it '@original_pictureにアレを取得している' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
- assigns(:original_picture).id.should eq(@pic.id)
+ assigns(:original_picture).should eq(@pic)
end
end
context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
+ assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
+ assigns(:original_picture).save
+ true
+ }
+ end
it '更新される' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg')
OriginalPicture.find(@pic.id).ext.should eq 'jpeg'
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
response.status.should eq 302
end
it '更新された原画の表示ページへ遷移する' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
response.should redirect_to(@pic)
end
end
context 'json形式' do
it 'ステータスコード200 OKを返す' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
response.should be_success
end
it 'ページ本体は特に返さない' do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
- OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
response.body.should match /./
end
end
end
end
- context '対象原画がないとき' do
- before do
- end
- context 'html形式' do
- it '例外404 not_foundを返す' do
- lambda{
- put :update, :id => 0, :original_picture => Factory.attributes_for(:original_picture)
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- context 'json形式' do
- it '例外404 not_foundを返す' do
- lambda{
- put :update, :id => 0, :original_picture => Factory.attributes_for(:original_picture), :format => :json
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- end
- context '他人の原画を見ようとしたとき' do
- before do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
- end
- context 'html形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- context 'json形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- end
context '検証、保存に失敗した' do
before do
- OriginalPicture.any_instance.stub(:save).and_return(false)
+ OriginalPicture.any_instance.stub(:store).and_return(false)
end
context 'html形式' do
it 'ステータスコード200 Okを返す' do