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
end
end
- describe 'クレジット表示に於いて' do\r
- before do\r
+ 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\r
- context 'つつがなく終わるとき' do\r
- it '素材モデルに単体取得を問い合わせている' do\r
- ResourcePicture.should_receive(:show).exactly(1)\r
- get :credit, :id => @rp.id\r
- end\r
- it '@resource_pictureにアレを取得している' do\r
- get :credit, :id => @rp.id\r
- assigns(:resource_picture).id.should eq(@rp.id)\r
- end\r
- context 'html形式' do\r
- it 'ステータスコード200 OKを返す' do\r
- get :credit, :id => @rp.id\r
- response.should be_success\r
- end\r
- it 'creditテンプレートを描画する' do\r
- get :credit, :id => @rp.id\r
- response.should render_template("credit")\r
- end\r
- end\r
- context 'json形式' do\r
- it 'ステータスコード200 OKを返す' do\r
- get :credit, :id => @rp.id, :format => :json\r
- response.should be_success\r
- end\r
- it 'jsonデータを返す' do\r
- get :credit, :id => @rp.id, :format => :json\r
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
- end\r
+ 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\r
+ get :credit, :id => @rp.id, :format => :json
end
- it 'データがアレになっている' do\r
- get :credit, :id => @rp.id, :format => :json\r
- json = JSON.parse response.body\r
- json["ext"].should match(/png/)\r
+ 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\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 => @rp.id\r
- response.status.should eq 302\r
- end\r
- it 'サインインページへ遷移する' do\r
- get :credit, :id => @rp.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 => @rp.id, :format => :json\r
- response.status.should eq 401\r
- end\r
- it '応答メッセージにUnauthorizedを返す' do\r
- get :credit, :id => @rp.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
+ 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
- #原画にライセンスを与えるため際の確認フォーム\r
+ #原画にライセンスを与えるため際の確認フォーム
describe '新規作成フォーム表示に於いて' do
before do
sign_in @user
end
end
end
- context '対象ライセンスグループがないとき' do\r
- before do\r
+ 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\r
- context 'html形式' do\r
- it '例外404 not_foundを返す' do\r
- lambda{\r
+ end
+ context 'html形式' do
+ it '例外404 not_foundを返す' do
+ lambda{
get :new, @attr
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
- context 'json形式' do\r
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ context 'json形式' do
before do
@attr.merge!({:format => :js})
end
- it '例外404 not_foundを返す' do\r
- lambda{ \r
- get :new, @attr\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
- end\r
+ it '例外404 not_foundを返す' do
+ lambda{
+ get :new, @attr
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
end
describe '新規作成に於いて' do
assigns(:resource_picture).settings.should eq '{"new":1}'
end
it "作成された素材がDBにある" do
- lambda{\r
+ lambda{
post :create, @newattr
- }.should change(ResourcePicture, :count)\r
+ }.should change(ResourcePicture, :count)
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
it 'データがアレになっている' do
post :create, @newattr
json = JSON.parse response.body
- json["ext"].should match(/png/)\r
+ json["ext"].should match(/png/)
json["md5"].should_not be_nil
json["picture_id"].should_not be_nil
end
it "素材が更新される" do
post :create, @attr
r = ResourcePicture.find(@rp.id)
- r.settings.should eq '{"new":0}'\r
+ r.settings.should eq '{"new":0}'
end
it "上書きなので件数は変化しない" do
- lambda{\r
+ lambda{
post :create, @attr
- }.should_not change(ResourcePicture, :count)\r
+ }.should_not change(ResourcePicture, :count)
end
end
context '作家権限がないとき' do