OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / app_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス
3 require 'spec_helper'
4
5 describe SystemController do
6   before do
7   end
8
9   describe 'システム初期化要請に於いて' do
10     context '要請の必要がないとき' do
11       before do
12         #要請の必要がない=管理者登録済み かつ ライセンス登録済み
13         @admin = FactoryGirl.create :admin
14         @sp = FactoryGirl.create :system_picture
15         @lg = FactoryGirl.create :license_group
16         @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17       end
18       it 'リクエスト通りのページを開く' do
19         get :index
20         response.should_not redirect_to 'system/start'
21       end
22       context 'userがサインインしているなら' do
23         before do
24           @user = FactoryGirl.create( :user_yas)
25           @author = FactoryGirl.create :author, :user_id => @user.id
26           sign_in @user
27         end
28         it 'userにサインイン中のアカウントをセットしている' do
29           get :index
30           assigns(:user).should eq @user
31         end
32         it 'authorに作家をセットしている' do
33           get :index
34           assigns(:author).should eq @author
35         end
36         it 'artistに絵師をセットしている' do
37           @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
38           get :index
39           assigns(:artist).should eq @artist
40         end
41         it 'ただし、絵師登録されてなければnilをセットしている' do
42           get :index
43           assigns(:artist).should be_nil
44         end
45       end
46       context 'userがサインインしていないなら' do
47         before do
48           @user = FactoryGirl.create( :user_yas)
49           @author = FactoryGirl.create :author, :user_id => @user.id
50           @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
51         end
52         it 'userが空になっている' do
53           get :index
54           assigns(:user).should eq nil
55         end
56         it 'authorが空になっている' do
57           get :index
58           assigns(:author).should eq nil
59         end
60         it 'artistが空になっている' do
61           get :index
62           assigns(:artist).should eq nil
63         end
64       end
65     end
66     #要請の必要がある=管理者がいない または ライセンスがない
67     context '管理者がいないとき' do
68       before do
69         @sp = FactoryGirl.create :system_picture
70         @lg = FactoryGirl.create :license_group
71         @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
72       end
73       context '本機能を開こうとしているなら' do
74         it '初期化要請ページに遷移する' do
75           get :index
76           response.should redirect_to '/system/start'
77         end
78         it 'ステータスコード302 Foundを返す' do
79           get :index
80           response.status.should eq 302
81         end
82       end
83       context '初期化要請ページを開こうとしているなら' do
84         it '遷移しない' do
85           get :start
86           response.should_not redirect_to 'system/start'
87         end
88         it 'ステータスOkを返す' do
89           get :start
90           response.status.should eq 200
91         end
92         it '初期化要請ページを描画する' do
93           get :start
94           response.should render_template("system/start")
95         end
96       end
97     end
98     context 'ライセンスがないとき' do
99       before do
100         @admin = FactoryGirl.create :admin
101       end
102       context '本機能を開こうとしているなら' do
103         it '初期化要請ページに遷移する' do
104           get :index
105           response.should redirect_to '/system/start'
106         end
107         it 'ステータスコード302 Foundを返す' do
108           get :index
109           response.status.should eq 302
110         end
111       end
112       context '初期化要請ページを開こうとしているなら' do
113         it '遷移しない' do
114           get :start
115           response.should_not redirect_to 'system/start'
116         end
117         it 'ステータスOkを返す' do
118           get :start
119           response.status.should eq 200
120         end
121         it '初期化要請ページを描画する' do
122           get :start
123           response.should render_template("system/start")
124         end
125       end
126     end
127   end
128 end