1 # -*- encoding: utf-8 -*-
5 describe PanelColorsController 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 @panel = FactoryGirl.create :panel, :author_id => @author.id
17 describe '一覧表示に於いて' do
20 @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
21 PanelColor.stub(:list).and_return([@pc, @pc, @pc])
23 context 'パラメータpageについて' do
25 get :index, :page => 5
26 assigns(:page).should eq 5
28 it '省略されると@pageに1値が入る' do
30 assigns(:page).should eq 1
32 it '与えられたpage_sizeがセットされている' do
33 get :index, :page_size => 15
34 assigns(:page_size).should eq 15
36 it '省略されると@page_sizeにデフォルト値が入る' do
38 assigns(:page_size).should eq PanelColor.default_page_size
40 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 1500
42 assigns(:page_size).should eq PanelColor.max_page_size
44 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 0
46 assigns(:page_size).should eq PanelColor.default_page_size
49 context 'つつがなく終わるとき' do
50 it 'ステータスコード200 OKを返す' do
52 response.should be_success
54 it '色背景モデルに一覧を問い合わせている' do
55 PanelColor.should_receive(:list).exactly(1)
58 it '@panel_colorsにリストを取得している' do
60 assigns(:panel_colors).should have_at_least(3).items
63 it 'indexテンプレートを描画する' do
65 response.should render_template("index")
70 get :index, :format => :json
71 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
73 it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
74 PanelColor.should_receive(:list_json_opt).exactly(1)
75 get :index, :format => :json
77 it 'データがリスト構造になっている' do
78 get :index, :format => :json
79 json = JSON.parse response.body
80 json.should have_at_least(3).items
82 it 'リストの先頭くらいは色背景っぽいものであって欲しい' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.first.has_key?("panel_id").should be_true
86 json.first.has_key?("code").should be_true
87 json.first.has_key?("z").should be_true
91 context '作家権限がないとき' do
96 it 'ステータスコード302 Foundを返す' do
98 response.status.should eq 302
100 it 'サインインページへ遷移する' do
102 response.should redirect_to '/users/sign_in'
106 it 'ステータスコード401 Unauthorizedを返す' do
107 get :index, :format => :json
108 response.status.should eq 401
110 it '応答メッセージにUnauthorizedを返す' do
111 get :index, :format => :json
112 response.message.should match(/Unauthorized/)