describe ResourcePicturesController 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
- @artist = Factory :artist_yas, :author_id => @author.id
- @op = Factory :original_picture, :artist_id => @artist.id
+ @admin = FactoryGirl.create :admin
+ @demand_user = FactoryGirl.create :demand_user
+ @sp = FactoryGirl.create :system_picture
+ @lg = FactoryGirl.create :license_group
+ @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @user = FactoryGirl.create( :user_yas)
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
+if MagicNumber['run_mode'] == 1
describe '一覧表示に於いて' do
before do
- @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
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
sign_in @user
ResourcePicture.stub(:list).and_return([@rp, @rp, @rp])
end
end
end
context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
- end
it '素材モデルに一覧を問い合わせている' do
ResourcePicture.should_receive(:list).exactly(1)
get :index
assigns(:resource_pictures).should have_at_least(3).items
end
context 'html形式' do
+ it '@paginateにページ制御を取得している' do
+ get :index
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
it 'indexテンプレートを描画する' do
get :index
response.should render_template("index")
end
end
context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index, :format => :json
+ response.should be_success
+ end
it 'jsonデータを返す' do
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it '素材モデルにjson一覧出力オプションを問い合わせている' do
+ ResourcePicture.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
it 'データがリスト構造になっている' do
get :index, :format => :json
json = JSON.parse response.body
get :index, :format => :json
json = JSON.parse response.body
json.first.has_key?("ext").should be_true
+ json.first.has_key?("md5").should be_true
+ json.first.has_key?("picture_id").should be_true
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
end
describe '単体表示に於いて' do
before do
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
- @pic = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
sign_in @user
- ResourcePicture.stub(:show).and_return(@pic)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
end
context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :show, :id => @pic.id
- response.should be_success
- end
it '素材モデルに単体取得を問い合わせている' do
ResourcePicture.should_receive(:show).exactly(1)
- get :show
+ get :show, :id => @rp.id
end
it '@resource_pictureにアレを取得している' do
- get :show, :id => @pic.id
- assigns(:resource_picture).id.should eq(@pic.id)
+ get :show, :id => @rp.id
+ assigns(:resource_picture).id.should eq(@rp.id)
end
context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id
+ response.should be_success
+ end
it 'showテンプレートを描画する' do
- get :show, :id => @pic.id
+ get :show, :id => @rp.id
response.should render_template("show")
end
end
context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id, :format => :json
+ response.should be_success
+ end
it 'jsonデータを返す' do
- get :show, :id => @pic.id, :format => :json
+ get :show, :id => @rp.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it '素材モデルにjson単体出力オプションを問い合わせている' do
+ ResourcePicture.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @rp.id, :format => :json
+ end
it 'データがアレになっている' do
- get :show, :id => @pic.id, :format => :json
+ get :show, :id => @rp.id, :format => :json
json = JSON.parse response.body
json["ext"].should match(/png/)
+ json["md5"].should_not be_nil
+ json["picture_id"].should_not be_nil
end
end
#画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
#renderが働かず、エラーとなってしまう。そこで、素材のファイル取得部分に
#スタブをおいてsend_dataがデータを返す体裁でテストする。
context 'png形式' do
+ before do
+ ResourcePicture.any_instance.stub(:mime_type).and_return('image/png')
+ ResourcePicture.any_instance.stub(:restore).and_return('aaa')
+ end
it '画像モデルに画像データを問い合わせる' do
ResourcePicture.any_instance.should_receive(:restore).exactly(1)
- get :show, :id => @pic.id, :format => :png
+ get :show, :id => @rp.id, :format => :png
+ end
+ it '画像モデルにMimeTypeを問い合わせる' do
+ ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
+ get :show, :id => @rp.id, :format => :png
end
it '画像を送信する' do
- ResourcePicture.any_instance.stub(:restore).and_return('aaa')
- get :show, :id => @pic.id, :format => :png
+ get :show, :id => @rp.id, :format => :png
response.body.should eq 'aaa'
end
end
context 'gif形式' do
+ before do
+ ResourcePicture.any_instance.stub(:mime_type).and_return('image/gif')
+ ResourcePicture.any_instance.stub(:restore).and_return('bbb')
+ end
it '画像モデルに画像データを問い合わせる' do
ResourcePicture.any_instance.should_receive(:restore).exactly(1)
- get :show, :id => @pic.id, :format => :gif
+ get :show, :id => @rp.id, :format => :gif
+ end
+ it '画像モデルにMimeTypeを問い合わせる' do
+ ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
+ get :show, :id => @rp.id, :format => :png
end
it '画像を送信する' do
- ResourcePicture.any_instance.stub(:restore).and_return('bbb')
- get :show, :id => @pic.id, :format => :gif
+ get :show, :id => @rp.id, :format => :gif
response.body.should eq 'bbb'
end
end
context 'jpeg形式' do
+ before do
+ ResourcePicture.any_instance.stub(:mime_type).and_return('image/jpeg')
+ ResourcePicture.any_instance.stub(:restore).and_return('ccc')
+ end
it '画像モデルに画像データを問い合わせる' do
ResourcePicture.any_instance.should_receive(:restore).exactly(1)
- get :show, :id => @pic.id, :format => :jpeg
+ get :show, :id => @rp.id, :format => :jpeg
+ end
+ it '画像モデルにMimeTypeを問い合わせる' do
+ ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
+ get :show, :id => @rp.id, :format => :png
end
it '画像を送信する' do
- ResourcePicture.any_instance.stub(:restore).and_return('ccc')
- get :show, :id => @pic.id, :format => :jpeg
+ get :show, :id => @rp.id, :format => :jpeg
response.body.should eq 'ccc'
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
- get :show, :id => @pic.id
+ get :show, :id => @rp.id
response.status.should eq 302
end
it 'サインインページへ遷移する' do
- get :show, :id => @pic.id
+ get :show, :id => @rp.id
response.body.should redirect_to '/users/sign_in'
end
end
context 'json形式' do
it 'ステータスコード401 Unauthorizedを返す' do
- get :show, :id => @pic.id, :format => :json
+ get :show, :id => @rp.id, :format => :json
response.status.should eq 401
end
it '応答メッセージにUnauthorizedを返す' do
- get :show, :id => @pic.id, :format => :json
+ get :show, :id => @rp.id, :format => :json
response.message.should match(/Unauthorized/)
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id
+ response.should be_success
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id
+ response.should be_success
+ end
+ end
=begin
context '対象素材がないとき' do
before do
end
context '他人の素材を見ようとしたとき' do
before do
- ResourcePicture.stub(:show).and_return(@pic)
+ ResourcePicture.stub(:show).and_return(@rp)
ResourcePicture.any_instance.stub(:own?).with(any_args()).and_return(false)
end
context 'html形式' do
it '例外403 forbiddenを返す' do
lambda{
- get :show, :id => @pic.id
+ get :show, :id => @rp.id
}.should raise_error(ActiveRecord::Forbidden)
end
end
context 'json形式' do
it '例外403 forbiddenを返す' do
lambda{
- get :show, :id => @pic.id, :format => :json
+ get :show, :id => @rp.id, :format => :json
}.should raise_error(ActiveRecord::Forbidden)
end
end
end
end
- describe 'クレジット表示に於いて' do\r
- before do\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
- @pic = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ describe 'クレジット表示に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
+ end
+ context 'つつがなく終わるとき' do
+ it '素材モデルに単体取得を問い合わせている' do
+ ResourcePicture.should_receive(:show).exactly(1)
+ get :credit, :id => @rp.id
+ end
+ it '@resource_pictureにアレを取得している' do
+ get :credit, :id => @rp.id
+ assigns(:resource_picture).id.should eq(@rp.id)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id
+ response.should be_success
+ end
+ it 'creditテンプレートを描画する' do
+ get :credit, :id => @rp.id
+ response.should render_template("credit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '素材モデルにjson単体出力オプションを問い合わせている' do
+ ResourcePicture.should_receive(:show_json_opt).exactly(1)
+ get :credit, :id => @rp.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :credit, :id => @rp.id, :format => :json
+ json = JSON.parse response.body
+ json["ext"].should match(/png/)
+ json["md5"].should_not be_nil
+ json["picture_id"].should_not be_nil
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :credit, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :credit, :id => @rp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id
+ response.should be_success
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id
+ response.should be_success
+ end
+ end
+=begin
+ context '対象素材がないとき' do
+ before do
+ ResourcePicture.unstub(:show)
+ end
+ 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
+ lambda{
+ get :show, :id => 0, :format => :json
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+=end
+ end
+
+ #原画にライセンスを与えるため際の確認フォーム
+ describe '新規作成フォーム表示に於いて' do
+ before do
sign_in @user
- ResourcePicture.stub(:show).and_return(@pic)
- end\r
- context 'つつがなく終わるとき' do\r
- it 'ステータスコード200 OKを返す' do\r
- get :credit, :id => @pic.id\r
- response.should be_success\r
- end\r
- it '素材モデルに単体取得を問い合わせている' do\r
- ResourcePicture.should_receive(:show).exactly(1)\r
- get :credit, :id => @pic.id\r
- end\r
- it '@resource_pictureにアレを取得している' do\r
- get :credit, :id => @pic.id\r
- assigns(:resource_picture).id.should eq(@pic.id)\r
- end\r
- context 'html形式' do\r
- it 'creditテンプレートを描画する' do\r
- get :credit, :id => @pic.id\r
- response.should render_template("credit")\r
- end\r
- end\r
- context 'json形式' do\r
- it 'jsonデータを返す' do\r
- get :credit, :id => @pic.id, :format => :json\r
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
- end\r
- it 'データがアレになっている' do\r
- get :credit, :id => @pic.id, :format => :json\r
- json = JSON.parse response.body\r
- json["ext"].should match(/png/)\r
- end\r
- end\r
- end\r
- context '作家権限がないとき' do\r
- before do\r
- sign_out @user\r
- end\r
- context 'html形式' do\r
- it 'ステータスコード302 Foundを返す' do\r
- get :credit, :id => @pic.id\r
- response.status.should eq 302\r
- end\r
- it 'サインインページへ遷移する' do\r
- get :credit, :id => @pic.id\r
- response.body.should redirect_to '/users/sign_in'\r
- end\r
- end\r
- context 'json形式' do\r
- it 'ステータスコード401 Unauthorizedを返す' do\r
- get :credit, :id => @pic.id, :format => :json\r
- response.status.should eq 401\r
- end\r
- it '応答メッセージにUnauthorizedを返す' do\r
- get :credit, :id => @pic.id, :format => :json\r
- response.message.should match(/Unauthorized/)\r
- end\r
- end\r
- end\r
-=begin\r
- context '対象素材がないとき' do\r
- before do\r
- ResourcePicture.unstub(:show)\r
- end\r
- context 'html形式' do\r
- it '例外404 not_foundを返す' do\r
- lambda{\r
- get :show, :id => 0\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
- context 'json形式' do\r
- it '例外404 not_foundを返す' do\r
- lambda{ \r
- get :show, :id => 0, :format => :json\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
- end\r
-=end\r
- end\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
+ @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context '事前チェックしておく' do
+ before do
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
+ ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
+ end
+ it '原画モデルに編集取得を依頼してしている' do
+ OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
+ get :new, @attr
+ end
+ it '原画モデルに画像データを問い合わせている' do
+ OriginalPicture.any_instance.should_receive(:restore).with(any_args()).exactly(1)
+ get :new, @attr
+ end
+ it '画像ライブラリをロードしている' do
+ PettanImager.should_receive(:load).with(any_args()).exactly(1)
+ get :new, @attr
+ end
+ it 'ライセンスグループモデルに単体取得を依頼している' do
+ LicenseGroup.should_receive(:show).with(any_args()).exactly(1)
+ get :new, @attr
+ end
+ context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
+ it '素材モデルにデフォルト値補充を依頼している' do
+ ResourcePicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
+ get :new, @newattr
+ end
+ end
+ context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
+ it '素材モデルにデフォルト値補充を依頼してない' do
+ ResourcePicture.any_instance.should_not_receive(:supply_default).with(any_args())
+ get :new, @attr
+ end
+ end
+ it '素材モデルに上書き補充を依頼している' do
+ ResourcePicture.any_instance.should_receive(:overwrite).with(@op).exactly(1)
+ get :new, @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
+ ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
+ end
+ it '@original_pictureに原画を取得している' do
+ get :new, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '@imagerに画像ライブラリをロードしている' do
+ get :new, @attr
+ assigns(:imager).should eq @imager
+ end
+ it '@original_picture_license_groupに新規原画ライセンスグループデータを用意している' do
+ get :new, @attr
+ assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
+ end
+ it '@license_groupにライセンスグループを取得している' do
+ get :new, @attr
+ assigns(:license_group).should eq @lg
+ end
+ context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
+ it '@resource_pictureに新規素材データを用意している' do
+ get :new, @newattr
+ assigns(:resource_picture).should be_a_new(ResourcePicture)
+ end
+ end
+ context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
+ it '@resource_pictureに素材データを用意している' do
+ get :new, @attr
+ assigns(:resource_picture).is_a?(ResourcePicture).should be_true
+ assigns(:resource_picture).should_not be_a_new(ResourcePicture)
+ end
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it 'ページテンプレートnewを描画する' do
+ get :new, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, @attr
+ 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, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, @attr
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, @attr
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :new, @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'js形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it 'ステータスコード200 Okを返す' do
+ get :new, @attr
+ response.status.should eq 200
+ end
+ it '絵師登録部分テンプレートartists/new.jsを描画する' do
+ get :new, @attr
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ context '対象ライセンスグループがないとき' do
+ before do
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => 0},
+ :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ end
+ context 'html形式' do
+ it '例外404 not_foundを返す' do
+ lambda{
+ get :new, @attr
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it '例外404 not_foundを返す' do
+ lambda{
+ get :new, @attr
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":0}' }}
+ @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":1}' }}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context '事前チェックしておく' do
+ before do
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
+ ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
+ ResourcePicture.any_instance.stub(:store).with(@imager).and_return(true)
+ end
+ it '原画モデルに編集取得を依頼してしている' do
+ OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
+ post :create, @attr
+ end
+ it '原画モデルに画像データを問い合わせている' do
+ OriginalPicture.any_instance.should_receive(:restore).with(any_args()).exactly(1)
+ post :create, @attr
+ end
+ it '画像ライブラリをロードしている' do
+ PettanImager.should_receive(:load).with(any_args()).exactly(1)
+ post :create, @attr
+ end
+ it 'ライセンスグループモデルに単体取得を依頼している' do
+ LicenseGroup.should_receive(:show).with(any_args()).exactly(1)
+ post :create, @attr
+ end
+ context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
+ it '素材モデルにデフォルト値補充を依頼している' do
+ ResourcePicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
+ post :create, @newattr
+ end
+ end
+ context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
+ it '素材モデルにデフォルト値補充を依頼してない' do
+ ResourcePicture.any_instance.should_not_receive(:supply_default).with(any_args())
+ post :create, @attr
+ end
+ end
+ it '素材モデルに上書き補充を依頼している' do
+ ResourcePicture.any_instance.should_receive(:overwrite).with(@op).exactly(1)
+ post :create, @attr
+ end
+ it '素材モデルに保存を依頼している' do
+ ResourcePicture.any_instance.should_receive(:store).with(@imager).exactly(1)
+ post :create, @attr
+ end
+ end
+ context 'つつがなく終わるとき[ライセンスを与えようとしている原画が素材を作成してない]' do
+ before do
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
+ assigns(:resource_picture).attributes = @newattr[:resource_picture]
+ assigns(:resource_picture).overwrite @newop
+ assigns(:resource_picture).picture_id = @p.id
+ assigns(:resource_picture).save!
+ true
+ }
+ end
+ it '@original_pictureに原画を取得している' do
+ post :create, @newattr
+ assigns(:original_picture).should eq @newop
+ end
+ it '@imagerに画像ライブラリをロードしている' do
+ post :create, @newattr
+ assigns(:imager).should eq @imager
+ end
+ it '@original_picture_license_groupに新規原画ライセンスグループデータを用意している' do
+ post :create, @newattr
+ assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
+ end
+ it '@license_groupにライセンスグループを取得している' do
+ post :create, @newattr
+ assigns(:license_group).should eq @lg
+ end
+ it '素材データにPOSTデータの素材情報を適用している' do
+ post :create, @newattr
+ assigns(:resource_picture).license_id.should eq @license.id
+ assigns(:resource_picture).artist_name.should eq @artist.name
+ assigns(:resource_picture).credit.should eq '{}'
+ assigns(:resource_picture).settings.should eq '{"new":1}'
+ end
+ it "作成された素材がDBにある" do
+ lambda{
+ post :create, @newattr
+ }.should change(ResourcePicture, :count)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @newattr
+ response.status.should eq 302
+ end
+ it '作成された素材の表示ページへ遷移する' do
+ post :create, @newattr
+ response.should redirect_to(ResourcePicture.last)
+ end
+ end
+ context 'json形式' do
+ before do
+ @newattr.merge!({:format => :json})
+ end
+ it 'ステータスコード200 OKを返す' do
+ post :create, @newattr
+ response.should be_success
+ end
+ it '作成された素材をjsonデータで返す' do
+ post :create, @newattr
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '素材モデルにjson単体出力オプションを問い合わせている' do
+ ResourcePicture.should_receive(:show_json_opt).exactly(1)
+ post :create, @newattr
+ end
+ it 'データがアレになっている' do
+ post :create, @newattr
+ json = JSON.parse response.body
+ json["ext"].should match(/png/)
+ json["md5"].should_not be_nil
+ json["picture_id"].should_not be_nil
+ end
+ end
+ end
+ context 'つつがなく終わるとき[ライセンスを与えようとしている原画が既に素材を作成している]' do
+ before do
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
+ assigns(:resource_picture).attributes = @attr[:resource_picture]
+ assigns(:resource_picture).overwrite @op
+ assigns(:resource_picture).save!
+ true
+ }
+ end
+ it '@original_pictureに原画を取得している' do
+ post :create, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '素材データにPOSTデータの素材情報を適用している' do
+ post :create, @attr
+ assigns(:resource_picture).license_id.should eq @license.id
+ assigns(:resource_picture).artist_name.should eq @artist.name
+ assigns(:resource_picture).credit.should eq '{}'
+ assigns(:resource_picture).settings.should eq '{"new":0}'
+ end
+ it "素材が更新される" do
+ post :create, @attr
+ r = ResourcePicture.find(@rp.id)
+ r.settings.should eq '{"new":0}'
+ end
+ it "上書きなので件数は変化しない" do
+ lambda{
+ post :create, @attr
+ }.should_not change(ResourcePicture, :count)
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, @attr
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, @attr
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ post :create, @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ @attr.merge!({:format => :json})
+ lambda{
+ post :create, @attr
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ ResourcePicture.any_instance.stub(:store).and_return(false)
+ end
+ it "未保存の素材を保持している" do
+ post :create, @newattr
+ assigns(:resource_picture).should be_a_new(ResourcePicture)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @newattr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @newattr
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ before do
+ @newattr.merge!({:format => :json})
+ end
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ post :create, @newattr
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ post :create, @newattr
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ ResourcePicture.stub(:edit).with(any_args()).and_return @rp
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
+ end
+ it '素材モデルに編集取得を問い合わせている' do
+ ResourcePicture.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @rp.id
+ end
+ it 'モデルに削除を依頼する' do
+ ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
+ delete :destroy, :id => @rp.id
+ end
+ it '@resource_pictureにアレを取得している' do
+ delete :destroy, :id => @rp.id
+ assigns(:resource_picture).id.should eq(@rp.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'マイ素材の一覧ページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.should redirect_to('/home/resource_picture')
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ delete :destroy, :id => @rp.id, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ ResourcePicture.any_instance.stub(:unpublish).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'その素材の詳細ページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.should redirect_to(resource_picture_path(@rp))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+else
+ describe '一覧表示に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ ResourcePicture.stub(:list).and_return([@rp, @rp, @rp])
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id
+ response.should be_success
+ end
+ it 'showテンプレートを描画する' do
+ get :show, :id => @rp.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :show, :id => @rp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id
+ response.should be_success
+ end
+ it 'showテンプレートを描画する' do
+ get :show, :id => @rp.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :show, :id => @rp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '素材数取得に於いて' do
+ before do
+ ResourcePicture.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
+ end
+ end
+ end
+
+ describe 'クレジット表示に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+ ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id
+ response.should be_success
+ end
+ it 'creditテンプレートを描画する' do
+ get :credit, :id => @rp.id
+ response.should render_template("credit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id
+ response.should be_success
+ end
+ it 'creditテンプレートを描画する' do
+ get :credit, :id => @rp.id
+ response.should render_template("credit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :credit, :id => @rp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ #原画にライセンスを与えるため際の確認フォーム
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
+ @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
+ ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it 'ページテンプレートnewを描画する' do
+ get :new, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, @attr
+ 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, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ before do
+ @attr.merge!({:format => :js})
+ end
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, @attr
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, @attr
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":0}' }}
+ @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
+ :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":1}' }}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context 'つつがなく終わるとき[ライセンスを与えようとしている原画が素材を作成してない]' do
+ before do
+ OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
+ LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
+ ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
+ assigns(:resource_picture).attributes = @newattr[:resource_picture]
+ assigns(:resource_picture).overwrite @newop
+ assigns(:resource_picture).picture_id = @p.id
+ assigns(:resource_picture).save!
+ true
+ }
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @newattr
+ response.status.should eq 302
+ end
+ it '作成された素材の表示ページへ遷移する' do
+ post :create, @newattr
+ response.should redirect_to(ResourcePicture.last)
+ end
+ end
+ context 'json形式' do
+ before do
+ @newattr.merge!({:format => :json})
+ end
+ it 'ステータスコード200 OKを返す' do
+ post :create, @newattr
+ response.should be_success
+ end
+ it '作成された素材をjsonデータで返す' do
+ post :create, @newattr
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @newattr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, @newattr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'マイ素材の一覧ページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.should redirect_to('/home/resource_picture')
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+end
end