]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/clients_controller_spec.rb
wiki_pages: Run script/misc/update-wiki-pages
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / clients_controller_spec.rb
1 require File.dirname(__FILE__) + '/../spec_helper'
2 require File.dirname(__FILE__) + '/oauth_controller_spec_helper'
3 require 'oauth/client/action_controller_request'
4
5 describe OauthClientsController, "index" do
6   include OAuthControllerSpecHelper
7   before(:each) do
8     login_as_application_owner
9   end
10   
11   def do_get
12     get :index
13   end
14   
15   it "should be successful" do
16     do_get
17     response.should be_success
18   end
19   
20   it "should query current_users client applications" do
21     @user.should_receive(:client_applications).and_return(@client_applications)
22     do_get
23   end
24   
25   it "should assign client_applications" do
26     do_get
27     assigns[:client_applications].should equal(@client_applications)
28   end
29   
30   it "should render index template" do
31     do_get
32     response.should render_template('index')
33   end
34 end
35
36 describe OauthClientsController, "show" do
37   include OAuthControllerSpecHelper
38   before(:each) do
39     login_as_application_owner
40   end
41   
42   def do_get
43     get :show, :id => '3'
44   end
45   
46   it "should be successful" do
47     do_get
48     response.should be_success
49   end
50   
51   it "should query current_users client applications" do
52     @user.should_receive(:client_applications).and_return(@client_applications)
53     @client_applications.should_receive(:find).with('3').and_return(@client_application)
54     do_get
55   end
56   
57   it "should assign client_applications" do
58     do_get
59     assigns[:client_application].should equal(@client_application)
60   end
61   
62   it "should render show template" do
63     do_get
64     response.should render_template('show')
65   end
66   
67 end
68
69 describe OauthClientsController, "new" do
70   include OAuthControllerSpecHelper
71   before(:each) do
72     login_as_application_owner
73     ClientApplication.stub!(:new).and_return(@client_application)
74   end
75   
76   def do_get
77     get :new
78   end
79   
80   it "should be successful" do
81     do_get
82     response.should be_success
83   end
84   
85   it "should assign client_applications" do
86     do_get
87     assigns[:client_application].should equal(@client_application)
88   end
89   
90   it "should render show template" do
91     do_get
92     response.should render_template('new')
93   end
94   
95 end
96
97 describe OauthClientsController, "edit" do
98   include OAuthControllerSpecHelper
99   before(:each) do
100     login_as_application_owner
101   end
102   
103   def do_get
104     get :edit, :id => '3'
105   end
106   
107   it "should be successful" do
108     do_get
109     response.should be_success
110   end
111   
112   it "should query current_users client applications" do
113     @user.should_receive(:client_applications).and_return(@client_applications)
114     @client_applications.should_receive(:find).with('3').and_return(@client_application)
115     do_get
116   end
117   
118   it "should assign client_applications" do
119     do_get
120     assigns[:client_application].should equal(@client_application)
121   end
122   
123   it "should render edit template" do
124     do_get
125     response.should render_template('edit')
126   end
127   
128 end
129
130 describe OauthClientsController, "create" do
131   include OAuthControllerSpecHelper
132   
133   before(:each) do
134     login_as_application_owner
135     @client_applications.stub!(:build).and_return(@client_application)
136     @client_application.stub!(:save).and_return(true)
137   end
138   
139   def do_valid_post
140     @client_application.should_receive(:save).and_return(true)
141     post :create, 'client_application'=>{'name' => 'my site'}
142   end
143
144   def do_invalid_post
145     @client_application.should_receive(:save).and_return(false)
146     post :create, :client_application=>{:name => 'my site'}
147   end
148   
149   it "should query current_users client applications" do
150     @client_applications.should_receive(:build).and_return(@client_application)
151     do_valid_post
152   end
153   
154   it "should redirect to new client_application" do
155     do_valid_post
156     response.should be_redirect
157     response.should redirect_to(:action => "show", :id => @client_application.id)
158   end
159   
160   it "should assign client_applications" do
161     do_invalid_post
162     assigns[:client_application].should equal(@client_application)
163   end
164   
165   it "should render show template" do
166     do_invalid_post
167     response.should render_template('new')
168   end
169 end
170
171 describe OauthClientsController, "destroy" do
172   include OAuthControllerSpecHelper
173   before(:each) do
174     login_as_application_owner
175     @client_application.stub!(:destroy)
176   end
177   
178   def do_delete
179     delete :destroy, :id => '3'
180   end
181     
182   it "should query current_users client applications" do
183     @user.should_receive(:client_applications).and_return(@client_applications)
184     @client_applications.should_receive(:find).with('3').and_return(@client_application)
185     do_delete
186   end
187
188   it "should destroy client applications" do
189     @client_application.should_receive(:destroy)
190     do_delete
191   end
192     
193   it "should redirect to list" do
194     do_delete
195     response.should be_redirect
196     response.should redirect_to(:action => 'index')
197   end
198   
199 end
200
201 describe OauthClientsController, "update" do
202   include OAuthControllerSpecHelper
203   
204   before(:each) do
205     login_as_application_owner
206   end
207   
208   def do_valid_update
209     @client_application.should_receive(:update_attributes).and_return(true)
210     put :update, :id => '1', 'client_application'=>{'name' => 'my site'}
211   end
212
213   def do_invalid_update
214     @client_application.should_receive(:update_attributes).and_return(false)
215     put :update, :id => '1', 'client_application'=>{'name' => 'my site'}
216   end
217   
218   it "should query current_users client applications" do
219     @user.should_receive(:client_applications).and_return(@client_applications)
220     @client_applications.should_receive(:find).with('1').and_return(@client_application)
221     do_valid_update
222   end
223   
224   it "should redirect to new client_application" do
225     do_valid_update
226     response.should be_redirect
227     response.should redirect_to(:action => "show", :id => @client_application.id)
228   end
229   
230   it "should assign client_applications" do
231     do_invalid_update
232     assigns[:client_application].should equal(@client_application)
233   end
234   
235   it "should render show template" do
236     do_invalid_update
237     response.should render_template('edit')
238   end
239 end