1 # -*- encoding: utf-8 -*-
5 describe GroundPicturesController do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @sp = FactoryGirl.create :system_picture
10 @lg = FactoryGirl.create :license_group, :name => 'peta'
11 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
15 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
16 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
17 @panel = FactoryGirl.create :panel, :author_id => @author.id
20 describe '一覧表示に於いて' do
23 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
24 GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
26 context 'パラメータpageについて' do
28 get :index, :page => 5
29 assigns(:page).should eq 5
31 it '省略されると@pageに1値が入る' do
33 assigns(:page).should eq 1
35 it '与えられたpage_sizeがセットされている' do
36 get :index, :page_size => 15
37 assigns(:page_size).should eq 15
39 it '省略されると@page_sizeにデフォルト値が入る' do
41 assigns(:page_size).should eq GroundPicture.default_page_size
43 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
44 get :index, :page_size => 1500
45 assigns(:page_size).should eq GroundPicture.max_page_size
47 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
48 get :index, :page_size => 0
49 assigns(:page_size).should eq GroundPicture.default_page_size
52 context 'つつがなく終わるとき' do
53 it 'ステータスコード200 OKを返す' do
55 response.should be_success
57 it 'コマの画像背景モデルに一覧を問い合わせている' do
58 GroundPicture.should_receive(:list).exactly(1)
61 it '@ground_picturesにリストを取得している' do
63 assigns(:ground_pictures).should have_at_least(3).items
66 it 'indexテンプレートを描画する' do
68 response.should render_template("index")
73 get :index, :format => :json
74 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
76 it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
77 GroundPicture.should_receive(:list_json_opt).exactly(1)
78 get :index, :format => :json
80 it 'データがリスト構造になっている' do
81 get :index, :format => :json
82 json = JSON.parse response.body
83 json.should have_at_least(3).items
85 it 'リストの先頭くらいは画像背景っぽいものであって欲しい' do
86 get :index, :format => :json
87 json = JSON.parse response.body
88 json.first.has_key?("panel_id").should be_true
89 json.first.has_key?("picture_id").should be_true
90 json.first.has_key?("z").should be_true
94 context '作家権限がないとき' do
99 it 'ステータスコード302 Foundを返す' do
101 response.status.should eq 302
103 it 'サインインページへ遷移する' do
105 response.should redirect_to '/users/sign_in'
109 it 'ステータスコード401 Unauthorizedを返す' do
110 get :index, :format => :json
111 response.status.should eq 401
113 it '応答メッセージにUnauthorizedを返す' do
114 get :index, :format => :json
115 response.message.should match(/Unauthorized/)