OSDN Git Service

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