1 # -*- encoding: utf-8 -*-
5 describe PanelPicturesController do
7 FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = @user.author
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
18 @attr = {:picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height}
21 describe '一覧表示に於いて' do
23 @pp = FactoryGirl.create :panel_picture, @attr
25 PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
27 context 'パラメータpageについて' do
29 get :index, :page => 5
30 assigns(:page).should eq 5
32 it '省略されると@pageに1値が入る' do
34 assigns(:page).should eq 1
36 it '与えられたpage_sizeがセットされている' do
37 get :index, :page_size => 15
38 assigns(:page_size).should eq 15
40 it '省略されると@page_sizeにデフォルト値が入る' do
42 assigns(:page_size).should eq PanelPicture.default_page_size
44 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 1500
46 assigns(:page_size).should eq PanelPicture.max_page_size
48 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
49 get :index, :page_size => 0
50 assigns(:page_size).should eq PanelPicture.default_page_size
53 context 'つつがなく終わるとき' do
54 it 'ステータスコード200 OKを返す' do
56 response.should be_success
58 it 'コマ絵モデルに一覧を問い合わせている' do
59 PanelPicture.should_receive(:list).exactly(1)
62 it '@panel_picturesにリストを取得している' do
64 assigns(:panel_pictures).should have_at_least(3).items
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
78 PanelPicture.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("link").should be_true
90 json.first.has_key?("x").should be_true
91 json.first.has_key?("y").should be_true
95 context '作家権限がないとき' do
100 it 'ステータスコード302 Foundを返す' do
102 response.status.should eq 302
104 it 'サインインページへ遷移する' do
106 response.should redirect_to '/users/sign_in'
110 it 'ステータスコード401 Unauthorizedを返す' do
111 get :index, :format => :json
112 response.status.should eq 401
114 it '応答メッセージにUnauthorizedを返す' do
115 get :index, :format => :json
116 response.message.should match(/Unauthorized/)