OSDN Git Service

pass test
[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         Factory :admin
14         Factory :license
15       end
16       it 'リクエスト通りのページを開く' do
17         get :index
18         response.should_not redirect_to 'system/start'
19       end
20       context 'userがサインインしているなら' do
21         before do
22           @user = Factory( :user_yas)
23           @author = @user.author
24           sign_in @user
25         end
26         it 'userにサインイン中のアカウントをセットしている' do
27           get :index
28           assigns(:user).should eq @user
29         end
30         it 'authorに作家をセットしている' do
31           get :index
32           assigns(:author).should eq @author
33         end
34         it 'artistに絵師をセットしている' do
35           @artist = Factory :artist_yas, :author_id => @author.id
36           get :index
37           assigns(:artist).should eq @artist
38         end
39         it 'ただし、絵師登録されてなければ新規の絵師をセットしている' do
40           get :index
41           assigns(:artist).should be_a_new(Artist)
42         end
43       end
44       context 'userがサインインしていないなら' do
45         before do
46           @user = Factory( :user_yas)
47           @author = @user.author
48           @artist = Factory :artist_yas, :author_id => @author.id
49         end
50         it 'userが空になっている' do
51           get :index
52           assigns(:user).should eq nil
53         end
54         it 'authorが空になっている' do
55           get :index
56           assigns(:author).should eq nil
57         end
58         it 'artistが空になっている' do
59           get :index
60           assigns(:artist).should eq nil
61         end
62       end
63     end
64     #要請の必要がある=管理者がいない または ライセンスがない
65     context '管理者がいないとき' do
66       before do
67         Factory :license
68       end
69       context '本機能を開こうとしているなら' do
70         it '初期化要請ページに遷移する' do
71           get :index
72           response.should redirect_to '/system/start'
73         end
74         it 'ステータスコード302 Foundを返す' do
75           get :index
76           response.status.should eq 302
77         end
78       end
79       context '初期化要請ページを開こうとしているなら' do
80         it '遷移しない' do
81           get :start
82           response.should_not redirect_to 'system/start'
83         end
84         it 'ステータスOkを返す' do
85           get :start
86           response.status.should eq 200
87         end
88         it '初期化要請ページを描画する' do
89           get :start
90           response.should render_template("system/start")
91         end
92       end
93     end
94     context 'ライセンスがないとき' do
95       before do
96         Factory :admin
97       end
98       context '本機能を開こうとしているなら' do
99         it '初期化要請ページに遷移する' do
100           get :index
101           response.should redirect_to '/system/start'
102         end
103         it 'ステータスコード302 Foundを返す' do
104           get :index
105           response.status.should eq 302
106         end
107       end
108       context '初期化要請ページを開こうとしているなら' do
109         it '遷移しない' do
110           get :start
111           response.should_not redirect_to 'system/start'
112         end
113         it 'ステータスOkを返す' do
114           get :start
115           response.status.should eq 200
116         end
117         it '初期化要請ページを描画する' do
118           get :start
119           response.should render_template("system/start")
120         end
121       end
122     end
123   end
124 end