1 # -*- encoding: utf-8 -*-
5 describe GroundColorsController 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
15 @color = FactoryGirl.create :color
18 describe '一覧表示に於いて' do
21 @gc = FactoryGirl.create :ground_color
22 GroundColor.stub(:list).and_return([@gc, @gc, @gc])
24 context 'パラメータpageについて' do
26 get :index, :page => 5
27 assigns(:page).should eq 5
29 it '省略されると@pageに1値が入る' do
31 assigns(:page).should eq 1
33 it '与えられたpage_sizeがセットされている' do
34 get :index, :page_size => 15
35 assigns(:page_size).should eq 15
37 it '省略されると@page_sizeにデフォルト値が入る' do
39 assigns(:page_size).should eq GroundColor.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq GroundColor.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq GroundColor.default_page_size
50 context 'つつがなく終わるとき' do
51 it 'ステータスコード200 OKを返す' do
53 response.should be_success
55 it '選択色地モデルに一覧を問い合わせている' do
56 GroundColor.should_receive(:list).exactly(1)
59 it '@ground_colorsにリストを取得している' do
61 assigns(:ground_colors).should have_at_least(3).items
64 it 'indexテンプレートを描画する' do
66 response.should render_template("index")
71 get :index, :format => :json
72 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
74 it '選択色地モデルにjson一覧出力オプションを問い合わせている' do
75 GroundColor.should_receive(:list_json_opt).exactly(1)
76 get :index, :format => :json
78 it 'データがリスト構造になっている' do
79 get :index, :format => :json
80 json = JSON.parse response.body
81 json.should have_at_least(3).items
83 it 'リストの先頭くらいは選択色地っぽいものであって欲しい' do
84 get :index, :format => :json
85 json = JSON.parse response.body
86 json.first.has_key?("panel_id").should be_true
87 json.first.has_key?("color_id").should be_true
88 json.first.has_key?("z").should be_true
92 context '作家権限がないとき' do
97 it 'ステータスコード302 Foundを返す' do
99 response.status.should eq 302
101 it 'サインインページへ遷移する' do
103 response.should redirect_to '/users/sign_in'
107 it 'ステータスコード401 Unauthorizedを返す' do
108 get :index, :format => :json
109 response.status.should eq 401
111 it '応答メッセージにUnauthorizedを返す' do
112 get :index, :format => :json
113 response.message.should match(/Unauthorized/)
119 describe '単体表示に於いて' do
122 @gc = FactoryGirl.create :ground_color
123 GroundColor.stub(:show).and_return(@gc)
125 context 'つつがなく終わるとき' do
126 it 'ステータスコード200 OKを返す' do
127 get :show, :id => @gc.id
128 response.should be_success
130 it '選択色地モデルに単体取得を問い合わせている' do
131 GroundColor.should_receive(:show).exactly(1)
134 it '@ground_colorにアレを取得している' do
135 get :show, :id => @gc.id
136 assigns(:ground_color).should eq(@gc)
139 it 'showテンプレートを描画する' do
140 get :show, :id => @gc.id
141 response.should render_template("show")
146 get :show, :id => @gc.id, :format => :json
147 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
149 it '選択色地モデルにjson単体出力オプションを問い合わせている' do
150 GroundColor.should_receive(:show_json_opt).exactly(1)
151 get :show, :id => @gc.id, :format => :json
154 get :show, :id => @gc.id, :format => :json
155 json = JSON.parse response.body
156 json["panel_id"].should_not be_nil
157 json["z"].should_not be_nil
158 json["color_id"].should_not be_nil
162 context '作家権限がないとき' do
167 it 'ステータスコード302 Foundを返す' do
168 get :show, :id => @gc.id
169 response.status.should eq 302
171 it 'サインインページへ遷移する' do
172 get :show, :id => @gc.id
173 response.body.should redirect_to '/users/sign_in'
177 it 'ステータスコード401 Unauthorizedを返す' do
178 get :show, :id => @gc.id, :format => :json
179 response.status.should eq 401
181 it '応答メッセージにUnauthorizedを返す' do
182 get :show, :id => @gc.id, :format => :json
183 response.message.should match(/Unauthorized/)