describe PanelPicturesController do
before do
- FactoryGirl.create :admin
+ @admin = FactoryGirl.create :admin
@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 = @user.author
+ @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
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
@attr = {:picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height}
end
+if MagicNumber['run_mode'] == 1
describe '一覧表示に於いて' do
before do
@pp = FactoryGirl.create :panel_picture, @attr
assigns(:panel_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")
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
+ PanelPicture.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?("link").should be_true
+ json.first.has_key?("x").should be_true
+ json.first.has_key?("y").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
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @panel_picture = FactoryGirl.create :panel_picture, @attr
+ PanelPicture.stub(:show).and_return(@panel_picture)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @panel_picture.id
+ response.should be_success
+ end
+ it 'コマ絵モデルに単体取得を問い合わせている' do
+ PanelPicture.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@panel_pictureにアレを取得している' do
+ get :show, :id => @panel_picture.id
+ assigns(:panel_picture).should eq(@panel_picture)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @panel_picture.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @panel_picture.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'コマ絵モデルにjson単体出力オプションを問い合わせている' do
+ PanelPicture.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @panel_picture.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @panel_picture.id, :format => :json
+ json = JSON.parse response.body
+ json["link"].should_not be_nil
+ json["x"].should_not be_nil
+ json["y"].should_not be_nil
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @panel_picture.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @panel_picture.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @panel_picture.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @panel_picture.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 => @panel_picture.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @panel_picture.id
+ response.should be_success
+ end
+ end
end
+else
+ describe '一覧表示に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, @attr
+ sign_in @user
+ PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
+ 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
+ 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
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @panel_picture = FactoryGirl.create :panel_picture, @attr
+ PanelPicture.stub(:show).and_return(@panel_picture)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @panel_picture.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @panel_picture.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @panel_picture.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
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @panel_picture.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @panel_picture.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @panel_picture.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+end
end