describe SystemPicturesController do
before do
@admin = FactoryGirl.create :admin
+ @demand_user = FactoryGirl.create :demand_user
@user = FactoryGirl.create( :user_yas)
- @author = @user.author
+ @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
+if MagicNumber['run_mode'] == 1
describe '一覧表示に於いて' do
before do
sign_in @user
- sign_in @admin
SystemPicture.stub(:list).and_return([@sp, @sp, @sp])
end
context 'パラメータpageについて' do
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
end
describe '単体表示に於いて' do
end
end
end
+ context '作家権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @sp.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 => @sp.id
+ response.should be_success
+ end
+ end
=begin
context '対象システム画像がないとき' do
before do
=end
end
- describe '新規作成フォーム表示に於いて' do
+else
+ describe '一覧表示に於いて' do
before do
sign_in @user
sign_in @admin
+ SystemPicture.stub(:list).and_return([@sp, @sp, @sp])
end
context 'つつがなく終わるとき' do
context 'html形式' do
it 'ステータスコード200 OKを返す' do
- get :new
+ get :index
response.should be_success
end
- it 'ページテンプレートnewを描画する' do
- get :new
- response.should render_template("new")
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
end
end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :new
- response.status.should eq 302
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index, :format => :json
+ response.should be_success
end
- it 'サインインページへ遷移する' do
- get :new
- response.body.should redirect_to '/admins/sign_in'
+ 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
- sign_in @admin
- sign_in @user
- @attr = {:system_picture => {:file => "abc\ndef\nghi"}}
- @imager = ImagerTest.load("abc\ndef\nghi")
- end
- context '事前チェックしておく' do
- before do
- PettanImager.stub(:load).with(any_args).and_return(@imager)
- SystemPicture.any_instance.stub(:store).with(@imager).and_return(true)
- end
- it "画像ライブラリをロードしている" do
- PettanImager.should_receive(:load).with(any_args).exactly(1)
- post :create, @attr
- end
- it 'システム画像モデルに保存依頼する' do
- SystemPicture.should_receive(:store).with(@imager).exactly(1)
- post :create, @attr
- end
- end
- context 'つつがなく終わるとき' do
+ context '作家権限がないとき' do
before do
- PettanImager.stub(:load).with(any_args).and_return(@imager)
- SystemPicture.stub(:store).with(@imager).and_return(@sp)
+ sign_out @user
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, @attr
- response.status.should eq 302
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
end
- it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82·ã\82¹ã\83\86ã\83 ç\94»å\83\8fã\81®è¡¨ç¤ºã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99ã\82\8b' do
- post :create, @attr
- response.should redirect_to(SystemPicture.last)
+ it 'indexã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88ã\82\92æ\8f\8fç\94»ã\81\99ã\82\8b' do
+ get :index
+ response.should render_template("index")
end
end
context 'json形式' do
- before do
- @attr.merge!({:format => :json})
- end
it 'ステータスコード200 OKを返す' do
- post :create, @attr
+ get :index, :format => :json
response.should be_success
end
- it '作成されたシステム画像をjsonデータで返す' do
- post :create, @attr
+ it 'jsonデータを返す' do
+ get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'システム画像モデルにjson単体出力オプションを問い合わせている' do
- SystemPicture.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["width"].should be_true
- end
end
end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ SystemPicture.stub(:show).and_return(@sp)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @sp.id
+ response.should be_success
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 '/admins/sign_in'
+ it 'showテンプレートを描画する' do
+ get :show, :id => @sp.id
+ response.should render_template("show")
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/)
+ it 'jsonデータを返す' do
+ get :show, :id => @sp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
end
end
- context '検証、保存に失敗した' do
+ context '作家権限がないとき' do
before do
- SystemPicture.stub(:store).and_return(nil)
+ sign_out @user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @sp.id
+ response.should be_success
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")
+ it 'showテンプレートを描画する' do
+ get :show, :id => @sp.id
+ response.should render_template("show")
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/)
+ it 'jsonデータを返す' do
+ get :show, :id => @sp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
end
end
end
end
+end