OSDN Git Service

Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04license
[pettanr/pettanr.git] / spec / controllers / license_groups_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンスグループ
3 require 'spec_helper'
4
5 describe LicenseGroupsController do
6   before do
7     @admin = Factory :admin
8     @user = Factory( :user_yas)
9     @lg = Factory :license_group, :name => 'peta'
10   end
11
12   describe '一覧表示に於いて' do
13     before do
14       sign_in @user
15       LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
16     end
17     context 'つつがなく終わるとき' do
18       it 'ステータスコード200 OKを返す' do
19         get :index
20         response.should be_success 
21       end
22       it 'ライセンスモデルに一覧を問い合わせている' do
23         LicenseGroup.should_receive(:list).exactly(1)
24         get :index
25       end
26       it '@license_groupsにリストを取得している' do
27         get :index
28         assigns(:license_groups).should have_at_least(3).items
29       end
30       context 'html形式' do
31         it 'indexテンプレートを描画する' do
32           get :index
33           response.should render_template("index")
34         end
35       end
36       context 'json形式' do
37         it 'jsonデータを返す' do
38           get :index, :format => :json
39           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
40         end
41         it 'データがリスト構造になっている' do
42           get :index, :format => :json
43           json = JSON.parse response.body
44           json.should have_at_least(3).items
45         end
46         it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
47           get :index, :format => :json
48           json = JSON.parse response.body
49           json.first.has_key?("name").should be_true
50           json.first.has_key?("classname").should be_true
51           json.first.has_key?("caption").should be_true
52           json.first.has_key?("url").should be_true
53         end
54       end
55     end
56     context '作家権限がないとき' do
57       before do
58         sign_out @user
59       end
60       it 'ステータスコード200 okを返す' do
61         get :index
62         response.status.should eq 200
63       end
64     end
65   end
66   
67   describe '単体表示に於いて' do
68     before do
69       sign_in @user
70       LicenseGroup.stub(:show).and_return(@lg)
71     end
72     context 'つつがなく終わるとき' do
73       it 'ステータスコード200 OKを返す' do
74         get :show, :id => @lg.id
75         response.should be_success
76       end
77       it 'ライセンスモデルに単体取得を問い合わせている' do
78         LicenseGroup.should_receive(:show).exactly(1)
79         get :show
80       end
81       it '@license_groupにアレを取得している' do
82         get :show, :id => @lg.id
83         assigns(:license_group).id.should eq(@lg.id)
84       end
85       context 'html形式' do
86         it 'showテンプレートを描画する' do
87           get :show, :id => @lg.id
88           response.should render_template("show")
89         end
90       end
91       context 'json形式' do
92         it 'jsonデータを返す' do
93           get :show, :id => @lg.id, :format => :json
94           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
95         end
96         it 'データがアレになっている' do
97           get :show, :id => @lg.id, :format => :json
98           json = JSON.parse response.body
99           json["name"].should match(/peta/)
100         end
101       end
102     end
103     context '作家権限がないとき' do
104       before do
105         sign_out @user
106       end
107       it 'ステータスコード200 okを返す' do
108         get :show, :id => @lg.id
109         response.status.should eq 200
110       end
111     end
112   end
113   
114
115 end