+# -*- encoding: utf-8 -*-
+#原画
require 'spec_helper'
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
describe OriginalPicturesController do
-
- # This should return the minimal set of attributes required to create a valid
- # OriginalPicture. As you add validations to OriginalPicture, be sure to
- # update the return value of this method accordingly.
- def valid_attributes
- {}
+ before do
+ @admin = FactoryGirl.create :admin
+ @user = FactoryGirl.create( :user_yas)
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+ @sp = FactoryGirl.create :system_picture
+ @lg = FactoryGirl.create :license_group
+ @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
- describe "GET index" do
- it "assigns all original_pictures as @original_pictures" do
- original_picture = OriginalPicture.create! valid_attributes
- get :index
- assigns(:original_pictures).should eq([original_picture])
+if MagicNumber['run_mode'] == 1
+ describe '一覧表示に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
+ end
+ context 'パラメータpageについて' 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 OriginalPicture.default_page_size
+ 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
+ get :index
+ response.should be_success
+ end
+ it '原画モデルにマイリストを問い合わせている' do
+ OriginalPicture.should_receive(:mylist).exactly(1)
+ get :index
+ end
+ it '@original_picturesにリストを取得している' do
+ get :index
+ assigns(:original_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 '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 '原画モデルにjson一覧出力オプションを問い合わせている' do
+ OriginalPicture.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ 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?("ext").should be_true
+ json.first.has_key?("md5").should be_true
+ json.first.has_key?("artist_id").should be_true
+ json.first.has_key?("width").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
+ get :index, :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
+ get :index
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :index
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :index
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :index
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ get :index, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
end
end
-
- describe "GET show" do
- it "assigns the requested original_picture as @original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- get :show, :id => original_picture.id
- assigns(:original_picture).should eq(original_picture)
+
+ describe '単体表示に於いて' do
+ before do
+ @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@pic)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @pic.id
+ response.should be_success
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@original_pictureにアレを取得している' do
+ get :show, :id => @pic.id
+ assigns(:original_picture).id.should eq(@pic.id)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @pic.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @pic.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '原画モデルにjson単体出力オプションを問い合わせている' do
+ OriginalPicture.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @pic.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @pic.id, :format => :json
+ json = JSON.parse response.body
+ json["ext"].should match(/png/)
+ json["md5"].should be_true
+ json["artist_id"].should be_true
+ json["width"].should be_true
+ end
+ end
+ #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
+ #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
+ #スタブをおいてsend_dataがデータを返す体裁でテストする。
+ context 'png形式' do
+ before do
+ OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
+ OriginalPicture.any_instance.stub(:restore).and_return('aaa')
+ end
+ it '画像モデルに画像データを問い合わせる' do
+ OriginalPicture.any_instance.should_receive(:restore).exactly(1)
+ get :show, :id => @pic.id, :format => :png
+ end
+ it '画像モデルにMimeTypeを問い合わせる' do
+ OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
+ get :show, :id => @pic.id, :format => :png
+ end
+ it '画像を送信する' do
+ get :show, :id => @pic.id, :format => :png
+ response.body.should eq 'aaa'
+ end
+ end
+ context 'gif形式' do
+ before do
+ OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
+ OriginalPicture.any_instance.stub(:restore).and_return('bbb')
+ end
+ it '画像モデルに画像データを問い合わせる' do
+ OriginalPicture.any_instance.should_receive(:restore).exactly(1)
+ get :show, :id => @pic.id, :format => :gif
+ end
+ it '画像モデルにMimeTypeを問い合わせる' do
+ OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
+ get :show, :id => @pic.id, :format => :gif
+ end
+ it '画像を送信する' do
+ get :show, :id => @pic.id, :format => :gif
+ response.body.should eq 'bbb'
+ end
+ end
+ context 'jpeg形式' do
+ before do
+ OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
+ OriginalPicture.any_instance.stub(:restore).and_return('ccc')
+ end
+ it '画像モデルに画像データを問い合わせる' do
+ OriginalPicture.any_instance.should_receive(:restore).exactly(1)
+ get :show, :id => @pic.id, :format => :jpeg
+ end
+ it '画像モデルにMimeTypeを問い合わせる' do
+ OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
+ get :show, :id => @pic.id, :format => :jpeg
+ end
+ it '画像を送信する' do
+ get :show, :id => @pic.id, :format => :jpeg
+ response.body.should eq 'ccc'
+ end
+ end
end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @pic.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
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @pic.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 => @pic.id
+ response.should be_success
+ end
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @pic.id
+ response.should be_success
+ end
+ end
+=begin
+ context '対象原画がないとき' do
+ before do
+ OriginalPicture.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
+ context '他人の原画を見ようとしたとき' do
+ before do
+ OriginalPicture.stub(:show).and_return(@pic)
+ OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
+ end
+ context 'html形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ get :show, :id => @pic.id
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ get :show, :id => @pic.id, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+=end
end
- describe "GET new" do
- it "assigns a new original_picture as @original_picture" do
- get :new
- assigns(:original_picture).should be_a_new(OriginalPicture)
+ describe '履歴一覧表示に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+ :original_picture_id => @op.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@op)
+ OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :history, :id => @op.id
+ response.should be_success
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.should_receive(:show).exactly(1)
+ get :history, :id => @op.id
+ end
+ it '自身に履歴一覧を問い合わせている' do
+ OriginalPicture.any_instance.should_receive(:history).exactly(1)
+ get :history, :id => @op.id
+ end
+ it '@historyにリストを取得している' do
+ get :history, :id => @op.id
+ assigns(:history).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'historyテンプレートを描画する' do
+ get :history, :id => @op.id
+ response.should render_template("history")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :history, :id => @op.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがリスト構造になっている' do
+ get :history, :id => @op.id, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいは原画っぽいものであって欲しい' do
+ get :history, :id => @op.id, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("ext").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :history, :id => @op.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :history, :id => @op.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :history, :id => @op.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :history, :id => @op.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 :history, :id => @op.id
+ response.should be_success
+ end
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :history, :id => @op.id
+ response.should be_success
+ end
end
end
-
- describe "GET edit" do
- it "assigns the requested original_picture as @original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- get :edit, :id => original_picture.id
- assigns(:original_picture).should eq(original_picture)
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it '@original_pictureに新規データを用意している' do
+ get :new
+ assigns(:original_picture).should be_a_new(OriginalPicture)
+ end
+ it '原画モデルにデフォルト値補充を依頼している' do
+ OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
+ get :new
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ it 'ページテンプレートnewを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :js
+ response.should be_success
+ end
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '原画モデルにjson単体出力オプションを問い合わせている' do
+ OriginalPicture.should_receive(:show_json_opt).exactly(1)
+ get :new, :format => :json
+ 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
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ 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
+ end
+ context 'ユーザが絵師でないとき' do
+ before do
+ @artist.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :new
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ get :new, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
end
end
- describe "POST create" do
- describe "with valid params" do
- it "creates a new OriginalPicture" do
- expect {
- post :create, :original_picture => valid_attributes
- }.to change(OriginalPicture, :count).by(1)
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+ end
+ context '事前チェックしておく' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
end
-
- it "assigns a newly created original_picture as @original_picture" do
- post :create, :original_picture => valid_attributes
+ it '画像ライブラリをロードする' do
+ PettanImager.should_receive(:load).with(any_args()).exactly(1)
+ post :create, @attr
+ end
+ it '原画モデルにデフォルト値補充を依頼している' do
+ OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
+ post :create, @attr
+ end
+ it '原画モデルに上書き補充を依頼している' do
+ OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
+ post :create, @attr
+ end
+ it 'モデルに保存依頼する' do
+ OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
+ post :create, @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ end
+ it "@original_pictureに作成された原画を保持している" do
+ post :create, @attr
assigns(:original_picture).should be_a(OriginalPicture)
- assigns(:original_picture).should be_persisted
end
-
- it "redirects to the created original_picture" do
- post :create, :original_picture => valid_attributes
- response.should redirect_to(OriginalPicture.last)
+ 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(OriginalPicture.last)
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.should be_success
+ end
+ it '作成された原画をjsonデータで返す' do
+ post :create, @attr
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '原画モデルにjson単体出力オプションを問い合わせている' do
+ OriginalPicture.should_receive(:show_json_opt).exactly(1)
+ post :create, @attr
+ end
+ it 'データがアレになっている' do
+ post :create, @attr
+ json = JSON.parse response.body
+ json["ext"].should match(/png/)
+ json["md5"].should be_true
+ json["artist_id"].should be_true
+ json["width"].should be_true
+ end
end
end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved original_picture as @original_picture" do
- # Trigger the behavior that occurs when invalid params are submitted
- OriginalPicture.any_instance.stub(:save).and_return(false)
- post :create, :original_picture => {}
+ 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 => :json})
+ 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
+ @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
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it '例外403 forbiddenを返す' do
+ @attr.merge!({:format => :json})
+ lambda{
+ post :create, @attr
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
+ end
+ it "未保存の原画を保持している" do
+ post :create, @attr
+ assigns(:original_picture).should be_a_new(OriginalPicture)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ post :create, @attr
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ post :create, @attr
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ context 'ファイルが指定されていないとき' do
+ before do
+ @attr = {}
+ PettanImager.stub(:load).and_return(nil)
+ end
+ it "未保存の原画を保持している" do
+ post :create, @attr
assigns(:original_picture).should be_a_new(OriginalPicture)
end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ post :create, @attr
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ post :create, @attr
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@pic)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @pic.id
+ response.should be_success
+ end
+ it '原画モデルに編集取得を問い合わせている' do
+ OriginalPicture.should_receive(:edit).exactly(1)
+ get :edit, :id => @pic.id
+ end
+ it '@original_pictureにデータを用意している' do
+ get :edit, :id => @pic.id
+ assigns(:original_picture).should eq @pic
+ end
+ context 'html形式' do
+ it 'ページテンプレートeditを描画する' do
+ get :edit, :id => @pic.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it '部分テンプレートedit.jsを描画する' do
+ get :edit, :id => @pic.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 => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @pic.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @pic.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @pic.id, :format => :js
+ 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 :edit, :id => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @pic.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
+ get :edit, :id => @pic.id
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :edit, :id => @pic.id
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ get :edit, :id => @pic.id, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ end
- it "re-renders the 'new' template" do
- # Trigger the behavior that occurs when invalid params are submitted
- OriginalPicture.any_instance.stub(:save).and_return(false)
- post :create, :original_picture => {}
- response.should render_template("new")
+ describe '更新に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+ sign_in @user
+ @attr = {:file => "abc\ndef\nghi"}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context '事前チェックしておく' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
+ end
+ it '画像ライブラリをロードする' do
+ PettanImager.should_receive(:load).with(any_args()).exactly(1)
+ put :update, :id => @op.id, :original_picture => @attr
+ end
+ it '原画モデルに編集取得を問い合わせている' do
+ OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
+ put :update, :id => @op.id, :original_picture => @attr
+ end
+ it '原画モデルに上書き補充を依頼している' do
+ OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
+ put :update, :id => @op.id, :original_picture => @attr
+ end
+ it 'モデルに更新を依頼する' do
+ OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
+ put :update, :id => @op.id, :original_picture => @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ end
+ it '@original_pictureにアレを取得している' do
+ put :update, :id => @op.id, :original_picture => @attr
+ assigns(:original_picture).should eq(@op)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it '更新された原画の表示ページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should redirect_to(@pic)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :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
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @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
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 Okを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ context 'ファイルが指定されていないとき' do
+ before do
+ @attr = {}
+ PettanImager.stub(:load).and_return(nil)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 Okを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
end
end
end
- describe "PUT update" do
- describe "with valid params" do
- it "updates the requested original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- # Assuming there are no other original_pictures in the database, this
- # specifies that the OriginalPicture created on the previous line
- # receives the :update_attributes message with whatever params are
- # submitted in the request.
- OriginalPicture.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :id => original_picture.id, :original_picture => {'these' => 'params'}
+ describe '削除に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ OriginalPicture.stub(:edit).with(any_args()).and_return @op
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
end
+ it '原画モデルに編集取得を問い合わせている' do
+ OriginalPicture.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @op.id
+ end
+ it 'モデルに削除を依頼する' do
+ OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
+ delete :destroy, :id => @op.id
+ end
+ it '@original_pictureにアレを取得している' do
+ delete :destroy, :id => @op.id
+ assigns(:original_picture).id.should eq(@op.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ it '原画の一覧ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to(original_pictures_path)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @op.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 => @op.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @op.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 => @op.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @op.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 => @op.id
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ delete :destroy, :id => @op.id, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ it 'その原画の詳細ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to(original_picture_path(@op))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
- it "assigns the requested original_picture as @original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- put :update, :id => original_picture.id, :original_picture => valid_attributes
- assigns(:original_picture).should eq(original_picture)
+else
+ describe '一覧表示に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ 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
+ 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
+ get :index, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@pic)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @pic.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @pic.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @pic.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 'ステータスコード302 Foundを返す' do
+ get :show, :id => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @pic.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
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @pic.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
- it "redirects to the original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- put :update, :id => original_picture.id, :original_picture => valid_attributes
- response.should redirect_to(original_picture)
+ describe '履歴一覧表示に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+ :original_picture_id => @op.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@op)
+ OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :history, :id => @op.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'historyテンプレートを描画する' do
+ get :history, :id => @op.id
+ response.should render_template("history")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :history, :id => @op.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 'ステータスコード302 Foundを返す' do
+ get :history, :id => @op.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :history, :id => @op.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :history, :id => @op.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :history, :id => @op.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
end
end
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ it 'ページテンプレートnewを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :js
+ response.should be_success
+ end
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :new, :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 'ステータスコード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 "with invalid params" do
- it "assigns the original_picture as @original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- OriginalPicture.any_instance.stub(:save).and_return(false)
- put :update, :id => original_picture.id, :original_picture => {}
- assigns(:original_picture).should eq(original_picture)
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ 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(OriginalPicture.last)
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.should be_success
+ end
+ it '作成された原画をjsonデータで返す' do
+ post :create, @attr
+ 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, @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 => :json})
+ 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
+ end
- it "re-renders the 'edit' template" do
- original_picture = OriginalPicture.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- OriginalPicture.any_instance.stub(:save).and_return(false)
- put :update, :id => original_picture.id, :original_picture => {}
- response.should render_template("edit")
+ describe '編集フォーム表示に於いて' do
+ before do
+ @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@pic)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @pic.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'ページテンプレートeditを描画する' do
+ get :edit, :id => @pic.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it '部分テンプレートedit.jsを描画する' do
+ get :edit, :id => @pic.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 => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @pic.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @pic.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @pic.id, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
end
end
end
- describe "DELETE destroy" do
- it "destroys the requested original_picture" do
- original_picture = OriginalPicture.create! valid_attributes
- expect {
- delete :destroy, :id => original_picture.id
- }.to change(OriginalPicture, :count).by(-1)
+ describe '更新に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+ sign_in @user
+ @attr = {:file => "abc\ndef\nghi"}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it '更新された原画の表示ページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should redirect_to(@pic)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
end
+ context '検証、保存に失敗した' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 Okを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
- it "redirects to the original_pictures list" do
- original_picture = OriginalPicture.create! valid_attributes
- delete :destroy, :id => original_picture.id
- response.should redirect_to(original_pictures_url)
+ describe '削除に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ OriginalPicture.stub(:edit).with(any_args()).and_return @op
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+ end
+ it '原画モデルに編集取得を問い合わせている' do
+ OriginalPicture.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @op.id
+ end
+ it 'モデルに削除を依頼する' do
+ OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
+ delete :destroy, :id => @op.id
+ end
+ it '@original_pictureにアレを取得している' do
+ delete :destroy, :id => @op.id
+ assigns(:original_picture).id.should eq(@op.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ it '原画の一覧ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to(original_pictures_path)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @op.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 => @op.id
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ it 'その原画の詳細ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to(original_picture_path(@op))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
end
end
+end
end