X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fresource_pictures_controller_spec.rb;fp=spec%2Fcontrollers%2Fresource_pictures_controller_spec.rb;h=0854814d7a9377e9d7a5cff2b905976c5e3005a6;hb=2bd8e046bbbdd6d620af0637c3291cc7d787b0c5;hp=d46e807e0c213ecce3aef79b2b4f917d8f83b1ca;hpb=c1ce32fbd93b9412ac557fe4d2e53887708caafd;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/resource_pictures_controller_spec.rb b/spec/controllers/resource_pictures_controller_spec.rb index d46e807e..0854814d 100644 --- a/spec/controllers/resource_pictures_controller_spec.rb +++ b/spec/controllers/resource_pictures_controller_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper' describe ResourcePicturesController 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 end @@ -317,103 +317,103 @@ describe ResourcePicturesController do end end - describe 'クレジット表示に於いて' do - before do + 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, @author).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 + 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 + 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/) + 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 -=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 + 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 +=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 @@ -588,29 +588,29 @@ describe ResourcePicturesController do end end end - context '対象ライセンスグループがないとき' do - before do + 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 => '{}' }} - end - context 'html形式' do - it '例外404 not_foundを返す' do - lambda{ + end + context 'html形式' do + it '例外404 not_foundを返す' do + lambda{ get :new, @attr - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - context 'json形式' do + }.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 + it '例外404 not_foundを返す' do + lambda{ + get :new, @attr + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end end describe '新規作成に於いて' do @@ -711,9 +711,9 @@ describe ResourcePicturesController do assigns(:resource_picture).settings.should eq '{"new":1}' end it "作成された素材がDBにある" do - lambda{ + lambda{ post :create, @newattr - }.should change(ResourcePicture, :count) + }.should change(ResourcePicture, :count) end context 'html形式' do it 'ステータスコード302 Foundを返す' do @@ -744,7 +744,7 @@ describe ResourcePicturesController do it 'データがアレになっている' do post :create, @newattr json = JSON.parse response.body - json["ext"].should match(/png/) + json["ext"].should match(/png/) json["md5"].should_not be_nil json["picture_id"].should_not be_nil end @@ -777,12 +777,12 @@ describe ResourcePicturesController do it "素材が更新される" do post :create, @attr r = ResourcePicture.find(@rp.id) - r.settings.should eq '{"new":0}' + r.settings.should eq '{"new":0}' end it "上書きなので件数は変化しない" do - lambda{ + lambda{ post :create, @attr - }.should_not change(ResourcePicture, :count) + }.should_not change(ResourcePicture, :count) end end context '作家権限がないとき' do