=end
end
+ describe 'md5検索の一覧に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ sign_in @user
+ Picture.stub(:list_by_md5).with(any_args).and_return([@p, @p, @p])
+ end
+ context 'つつがなく終わるとき' do
+ it '実素材モデルにmd5検索を問い合わせている' do
+ Picture.should_receive(:list_by_md5).exactly(1)
+ get :md5, :md5 => 'a'*32
+ end
+ it '@picturesにリストを取得している' do
+ get :md5, :md5 => 'a'*32
+ assigns(:pictures).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :md5, :md5 => 'a'*32
+ response.should be_success
+ end
+ it 'md5テンプレートを描画する' do
+ get :md5, :md5 => 'a'*32
+ response.should render_template("md5")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :md5, :md5 => 'a'*32, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :md5, :md5 => 'a'*32, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがリスト構造になっている' do
+ get :md5, :md5 => 'a'*32, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいは実素材っぽいものであって欲しい' do
+ get :md5, :md5 => 'a'*32, :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 :md5, :md5 => 'a'*32
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :md5, :md5 => 'a'*32
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :md5, :md5 => 'a'*32, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :md5, :md5 => 'a'*32, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ Author.any_instance.stub(:artist?).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :md5, :md5 => 'a'*32
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :md5, :md5 => 'a'*32
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ get :md5, :md5 => 'a'*32, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ end
+
end