panjiva-oauth-plugin 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +12 -0
  3. data/CHANGELOG +178 -0
  4. data/Gemfile +27 -0
  5. data/Guardfile +8 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +531 -0
  8. data/Rakefile +2 -0
  9. data/UPGRADE.rdoc +21 -0
  10. data/generators/oauth_consumer/USAGE +10 -0
  11. data/generators/oauth_consumer/oauth_consumer_generator.rb +50 -0
  12. data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
  13. data/generators/oauth_consumer/templates/controller.rb +27 -0
  14. data/generators/oauth_consumer/templates/index.html.erb +29 -0
  15. data/generators/oauth_consumer/templates/index.html.haml +18 -0
  16. data/generators/oauth_consumer/templates/migration.rb +20 -0
  17. data/generators/oauth_consumer/templates/oauth_config.rb +73 -0
  18. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  19. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  20. data/generators/oauth_provider/USAGE +20 -0
  21. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  22. data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
  23. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  24. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  25. data/generators/oauth_provider/templates/access_token.rb +16 -0
  26. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  27. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  28. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  29. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  30. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  31. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  32. data/generators/oauth_provider/templates/client_application.rb +57 -0
  33. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  34. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  35. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  36. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  37. data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
  38. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  39. data/generators/oauth_provider/templates/controller.rb +23 -0
  40. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  41. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  42. data/generators/oauth_provider/templates/index.html.erb +43 -0
  43. data/generators/oauth_provider/templates/index.html.haml +39 -0
  44. data/generators/oauth_provider/templates/migration.rb +47 -0
  45. data/generators/oauth_provider/templates/new.html.erb +5 -0
  46. data/generators/oauth_provider/templates/new.html.haml +5 -0
  47. data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
  48. data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
  49. data/generators/oauth_provider/templates/oauth2_token.rb +20 -0
  50. data/generators/oauth_provider/templates/oauth2_token_spec.rb +52 -0
  51. data/generators/oauth_provider/templates/oauth2_verifier.rb +35 -0
  52. data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +44 -0
  53. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  54. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  55. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  56. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  57. data/generators/oauth_provider/templates/oauth_token.rb +30 -0
  58. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  59. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  60. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  61. data/generators/oauth_provider/templates/request_token.rb +40 -0
  62. data/generators/oauth_provider/templates/show.html.erb +27 -0
  63. data/generators/oauth_provider/templates/show.html.haml +30 -0
  64. data/init.rb +1 -0
  65. data/install.rb +2 -0
  66. data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
  67. data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
  68. data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
  69. data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
  70. data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
  71. data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
  72. data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
  73. data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +20 -0
  74. data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +35 -0
  75. data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
  76. data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
  77. data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
  78. data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
  79. data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
  80. data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
  81. data/lib/generators/erb/oauth_provider_generator.rb +23 -0
  82. data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
  83. data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
  84. data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
  85. data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
  86. data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
  87. data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
  88. data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
  89. data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
  90. data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
  91. data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
  92. data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
  93. data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
  94. data/lib/generators/haml/oauth_provider_generator.rb +28 -0
  95. data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
  96. data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
  97. data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
  98. data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
  99. data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
  100. data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
  101. data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
  102. data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
  103. data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
  104. data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
  105. data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +41 -0
  106. data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
  107. data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
  108. data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
  109. data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +20 -0
  110. data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +35 -0
  111. data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
  112. data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
  113. data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
  114. data/lib/generators/oauth_consumer/USAGE +11 -0
  115. data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +31 -0
  116. data/lib/generators/oauth_consumer/templates/controller.rb +59 -0
  117. data/lib/generators/oauth_consumer/templates/oauth_config.rb +68 -0
  118. data/lib/generators/oauth_inflections.rb +6 -0
  119. data/lib/generators/oauth_plugin.rb +0 -0
  120. data/lib/generators/oauth_provider/USAGE +18 -0
  121. data/lib/generators/oauth_provider/oauth_provider_generator.rb +37 -0
  122. data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
  123. data/lib/generators/oauth_provider/templates/controller.rb +23 -0
  124. data/lib/generators/rspec/oauth_provider_generator.rb +35 -0
  125. data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
  126. data/lib/generators/rspec/templates/client_applications.yml +23 -0
  127. data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
  128. data/lib/generators/rspec/templates/oauth2_token_spec.rb +52 -0
  129. data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +44 -0
  130. data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
  131. data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
  132. data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
  133. data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
  134. data/lib/generators/test_unit/oauth_provider_generator.rb +33 -0
  135. data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
  136. data/lib/generators/test_unit/templates/client_applications.yml +23 -0
  137. data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
  138. data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
  139. data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
  140. data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
  141. data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
  142. data/lib/oauth-plugin.rb +24 -0
  143. data/lib/oauth-plugin/version.rb +5 -0
  144. data/lib/oauth/controllers/application_controller_methods.rb +136 -0
  145. data/lib/oauth/controllers/consumer_controller.rb +150 -0
  146. data/lib/oauth/controllers/provider_controller.rb +181 -0
  147. data/lib/oauth/models/consumers/service_loader.rb +28 -0
  148. data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
  149. data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
  150. data/lib/oauth/models/consumers/services/google_token.rb +21 -0
  151. data/lib/oauth/models/consumers/services/oauth2_token.rb +27 -0
  152. data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
  153. data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
  154. data/lib/oauth/models/consumers/services/twitter_token.rb +24 -0
  155. data/lib/oauth/models/consumers/simple_client.rb +50 -0
  156. data/lib/oauth/models/consumers/token.rb +93 -0
  157. data/lib/oauth/provider/authorizer.rb +83 -0
  158. data/lib/oauth/rack/oauth_filter.rb +93 -0
  159. data/oauth-plugin.gemspec +39 -0
  160. data/rails/init.rb +1 -0
  161. data/spec/dummy_provider_models.rb +53 -0
  162. data/spec/oauth/provider/authorizer_spec.rb +202 -0
  163. data/spec/rack/oauth_filter_spec.rb +244 -0
  164. data/spec/spec_helper.rb +3 -0
  165. data/tasks/oauth_tasks.rake +4 -0
  166. data/uninstall.rb +1 -0
  167. metadata +362 -0
@@ -0,0 +1,17 @@
1
+ <%%= error_messages_for :client_application %>
2
+ <div class="field">
3
+ <label for="client_application_name">Name*</label><br/>
4
+ <%%= f.text_field :name %>
5
+ </div>
6
+ <div class="field">
7
+ <label for="client_application_url">Main Application URL*</label><br/>
8
+ <%%= f.text_field :url %>
9
+ </div>
10
+ <div class="field">
11
+ <label for="client_application_callback_url">Callback URL*</label><br/>
12
+ <%%= f.text_field :callback_url %>
13
+ </div>
14
+ <div class="field">
15
+ <label for="client_application_support_url">Support URL</label><br/>
16
+ <%%= f.text_field :support_url %>
17
+ </div>
@@ -0,0 +1,21 @@
1
+ =error_messages_for :client_application
2
+ .field
3
+ %label{:for=>"client_application_name"} Name*
4
+ %br
5
+ = f.text_field :name
6
+
7
+ .field
8
+ %label{:for=>"client_application_url"} Main Application URL*
9
+ %br
10
+ = f.text_field :url
11
+
12
+ .field
13
+ %label{:for=>"client_application_callback_url"} Callback URL*
14
+ %br
15
+ = f.text_field :callback_url
16
+
17
+ .field
18
+ %label{:for=>"client_application_support_url"} Support URL
19
+ %br
20
+ = f.text_field :support_url
21
+
@@ -0,0 +1,16 @@
1
+ class AccessToken < OauthToken
2
+ validates_presence_of :user, :secret
3
+ before_create :set_authorized_at
4
+
5
+ # Implement this to return a hash or array of the capabilities the access token has
6
+ # This is particularly useful if you have implemented user defined permissions.
7
+ # def capabilities
8
+ # {:invalidate=>"/oauth/invalidate",:capabilities=>"/oauth/capabilities"}
9
+ # end
10
+
11
+ protected
12
+
13
+ def set_authorized_at
14
+ self.authorized_at = Time.now
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ <h1>Authorize access to your account</h1>
2
+ <p>Would you like to authorize <%%= link_to @token.client_application.name,@token.client_application.url %> (<%%= link_to @token.client_application.url,@token.client_application.url %>) to access your account?</p>
3
+ <%% form_tag authorize_url do %>
4
+ <%%= hidden_field_tag "oauth_token", @token.token %>
5
+ <%%- if params[:oauth_callback] -%>
6
+ <%%= hidden_field_tag "oauth_callback", params[:oauth_callback] %>
7
+ <%%- end -%>
8
+ <p>
9
+ <%%= check_box_tag 'authorize' %> authorize access
10
+ </p>
11
+ <p>
12
+ <%%= submit_tag %>
13
+ </p>
14
+ <%% end %>
@@ -0,0 +1,16 @@
1
+ %h1 Authorize access to your account
2
+ %p
3
+ Would you like to authorize
4
+ = link_to @token.client_application.name,@token.client_application.url
5
+ (
6
+ = link_to @token.client_application.url,@token.client_application.url
7
+ ) to access your account?
8
+ - form_tag authorize_url do
9
+ = hidden_field_tag "oauth_token", @token.token
10
+ - if params[:oauth_callback]
11
+ = hidden_field_tag "oauth_callback", params[:oauth_callback]
12
+ %p
13
+ = check_box_tag 'authorize'
14
+ authorize access
15
+ %p
16
+ = submit_tag
@@ -0,0 +1 @@
1
+ <h1>You have disallowed this request</h1>
@@ -0,0 +1 @@
1
+ %h1 You have disallowed this request
@@ -0,0 +1 @@
1
+ <h1>You have allowed this request</h1>
@@ -0,0 +1 @@
1
+ %h1 You have allowed this request
@@ -0,0 +1,57 @@
1
+ require 'oauth'
2
+ class ClientApplication < ActiveRecord::Base
3
+ belongs_to :user
4
+ has_many :tokens, :class_name => "OauthToken"
5
+ has_many :access_tokens
6
+ has_many :oauth2_verifiers
7
+ has_many :oauth_tokens
8
+ validates_presence_of :name, :url, :key, :secret
9
+ validates_uniqueness_of :key
10
+ before_validation_on_create :generate_keys
11
+
12
+ validates_format_of :url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
13
+ validates_format_of :support_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
14
+ validates_format_of :callback_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
15
+
16
+ attr_accessor :token_callback_url
17
+
18
+ def self.find_token(token_key)
19
+ token = OauthToken.find_by_token(token_key, :include => :client_application)
20
+ if token && token.authorized?
21
+ token
22
+ else
23
+ nil
24
+ end
25
+ end
26
+
27
+ def self.verify_request(request, options = {}, &block)
28
+ begin
29
+ signature = OAuth::Signature.build(request, options, &block)
30
+ return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
31
+ value = signature.verify
32
+ value
33
+ rescue OAuth::Signature::UnknownSignatureMethod => e
34
+ false
35
+ end
36
+ end
37
+
38
+ def oauth_server
39
+ @oauth_server ||= OAuth::Server.new("http://your.site")
40
+ end
41
+
42
+ def credentials
43
+ @oauth_client ||= OAuth::Consumer.new(key, secret)
44
+ end
45
+
46
+ # If your application requires passing in extra parameters handle it here
47
+ def create_request_token(params={})
48
+ RequestToken.create :client_application => self, :callback_url=>self.token_callback_url
49
+ end
50
+
51
+ protected
52
+
53
+ def generate_keys
54
+ self.key = OAuth::Helper.generate_key(40)[0,40]
55
+ self.secret = OAuth::Helper.generate_key(40)[0,40]
56
+ end
57
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ describe ClientApplication do
3
+ fixtures :users, :client_applications, :oauth_tokens
4
+ before(:each) do
5
+ @application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
6
+ end
7
+
8
+ it "should be valid" do
9
+ @application.should be_valid
10
+ end
11
+
12
+
13
+ it "should not have errors" do
14
+ @application.errors.full_messages.should == []
15
+ end
16
+
17
+ it "should have key and secret" do
18
+ @application.key.should_not be_nil
19
+ @application.secret.should_not be_nil
20
+ end
21
+
22
+ it "should have credentials" do
23
+ @application.credentials.should_not be_nil
24
+ @application.credentials.key.should == @application.key
25
+ @application.credentials.secret.should == @application.secret
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ module OAuthHelpers
3
+
4
+ def create_consumer
5
+ @consumer=OAuth::Consumer.new(@application.key,@application.secret,
6
+ {
7
+ :site=>@application.oauth_server.base_url
8
+ })
9
+ end
10
+
11
+ end
12
+
13
+ class ClientApplicationTest < ActiveSupport::TestCase
14
+ include OAuthHelpers
15
+ fixtures :users,:client_applications,:oauth_tokens
16
+
17
+ def setup
18
+ @application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
19
+ create_consumer
20
+ end
21
+
22
+ def test_should_be_valid
23
+ assert @application.valid?
24
+ end
25
+
26
+
27
+ def test_should_not_have_errors
28
+ assert_equal [], @application.errors.full_messages
29
+ end
30
+
31
+ def test_should_have_key_and_secret
32
+ assert_not_nil @application.key
33
+ assert_not_nil @application.secret
34
+ end
35
+
36
+ def test_should_have_credentials
37
+ assert_not_nil @application.credentials
38
+ assert_equal @application.key, @application.credentials.key
39
+ assert_equal @application.secret, @application.credentials.secret
40
+ end
41
+
42
+ end
@@ -0,0 +1,23 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ name: MyString
5
+ url: http://test.com
6
+ support_url: http://test.com/support
7
+ callback_url: http://test.com/callback
8
+ key: one_key
9
+ secret: MyString
10
+ user_id: 1
11
+ created_at: 2007-11-17 16:56:51
12
+ updated_at: 2007-11-17 16:56:51
13
+ two:
14
+ id: 2
15
+ name: MyString
16
+ url: http://test.com
17
+ support_url: http://test.com/support
18
+ callback_url: http://test.com/callback
19
+ key: two_key
20
+ secret: MyString
21
+ user_id: 1
22
+ created_at: 2007-11-17 16:56:51
23
+ updated_at: 2007-11-17 16:56:51
@@ -0,0 +1,52 @@
1
+ class OauthClientsController < ApplicationController
2
+ before_filter :login_required
3
+ before_filter :get_client_application, :only => [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @client_applications = current_user.client_applications
7
+ @tokens = current_user.tokens.find :all, :conditions => 'oauth_tokens.invalidated_at is null and oauth_tokens.authorized_at is not null'
8
+ end
9
+
10
+ def new
11
+ @client_application = ClientApplication.new
12
+ end
13
+
14
+ def create
15
+ @client_application = current_user.client_applications.build(params[:client_application])
16
+ if @client_application.save
17
+ flash[:notice] = "Registered the information successfully"
18
+ redirect_to :action => "show", :id => @client_application.id
19
+ else
20
+ render :action => "new"
21
+ end
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def edit
28
+ end
29
+
30
+ def update
31
+ if @client_application.update_attributes(params[:client_application])
32
+ flash[:notice] = "Updated the client information successfully"
33
+ redirect_to :action => "show", :id => @client_application.id
34
+ else
35
+ render :action => "edit"
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ @client_application.destroy
41
+ flash[:notice] = "Destroyed the client application registration"
42
+ redirect_to :action => "index"
43
+ end
44
+
45
+ private
46
+ def get_client_application
47
+ unless @client_application = current_user.client_applications.find(params[:id])
48
+ flash.now[:error] = "Wrong application id"
49
+ raise ActiveRecord::RecordNotFound
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,176 @@
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 do
6
+ if defined?(Devise)
7
+ include Devise::TestHelpers
8
+ end
9
+ include OAuthControllerSpecHelper
10
+ fixtures :client_applications, :oauth_tokens, :users
11
+ before(:each) do
12
+ login_as_application_owner
13
+ end
14
+
15
+ describe "index" do
16
+ before do
17
+ @client_applications = @user.client_applications
18
+ end
19
+
20
+ def do_get
21
+ get :index
22
+ end
23
+
24
+ it "should be successful" do
25
+ do_get
26
+ response.should be_success
27
+ end
28
+
29
+ it "should assign client_applications" do
30
+ do_get
31
+ assigns[:client_applications].should==@client_applications
32
+ end
33
+
34
+ it "should render index template" do
35
+ do_get
36
+ response.should render_template('index')
37
+ end
38
+ end
39
+
40
+ describe "show" do
41
+
42
+ def do_get
43
+ get :show, :id => '1'
44
+ end
45
+
46
+ it "should be successful" do
47
+ do_get
48
+ response.should be_success
49
+ end
50
+
51
+ it "should assign client_applications" do
52
+ do_get
53
+ assigns[:client_application].should == current_client_application
54
+ end
55
+
56
+ it "should render show template" do
57
+ do_get
58
+ response.should render_template('show')
59
+ end
60
+
61
+ end
62
+
63
+ describe "new" do
64
+
65
+ def do_get
66
+ get :new
67
+ end
68
+
69
+ it "should be successful" do
70
+ do_get
71
+ response.should be_success
72
+ end
73
+
74
+ it "should assign client_applications" do
75
+ do_get
76
+ assigns[:client_application].class.should == ClientApplication
77
+ end
78
+
79
+ it "should render show template" do
80
+ do_get
81
+ response.should render_template('new')
82
+ end
83
+
84
+ end
85
+
86
+ describe "edit" do
87
+ def do_get
88
+ get :edit, :id => '1'
89
+ end
90
+
91
+ it "should be successful" do
92
+ do_get
93
+ response.should be_success
94
+ end
95
+
96
+ it "should assign client_applications" do
97
+ do_get
98
+ assigns[:client_application].should == current_client_application
99
+ end
100
+
101
+ it "should render edit template" do
102
+ do_get
103
+ response.should render_template('edit')
104
+ end
105
+
106
+ end
107
+
108
+ describe "create" do
109
+
110
+ def do_valid_post
111
+ post :create, 'client_application' => {'name' => 'my site', :url => "http://test.com"}
112
+ @client_application = ClientApplication.last
113
+ end
114
+
115
+ def do_invalid_post
116
+ post :create
117
+ end
118
+
119
+ it "should redirect to new client_application" do
120
+ do_valid_post
121
+ response.should be_redirect
122
+ response.should redirect_to(:action => "show", :id => @client_application.id)
123
+ end
124
+
125
+ it "should render show template" do
126
+ do_invalid_post
127
+ response.should render_template('new')
128
+ end
129
+ end
130
+
131
+ describe "destroy" do
132
+
133
+ def do_delete
134
+ delete :destroy, :id => '1'
135
+ end
136
+
137
+ it "should destroy client applications" do
138
+ do_delete
139
+ ClientApplication.should_not be_exists(1)
140
+ end
141
+
142
+ it "should redirect to list" do
143
+ do_delete
144
+ response.should be_redirect
145
+ response.should redirect_to(:action => 'index')
146
+ end
147
+
148
+ end
149
+
150
+ describe "update" do
151
+
152
+ def do_valid_update
153
+ put :update, :id => '1', 'client_application' => {'name' => 'updated site'}
154
+ end
155
+
156
+ def do_invalid_update
157
+ put :update, :id => '1', 'client_application' => {'name' => nil}
158
+ end
159
+
160
+ it "should redirect to show client_application" do
161
+ do_valid_update
162
+ response.should be_redirect
163
+ response.should redirect_to(:action => "show", :id => 1)
164
+ end
165
+
166
+ it "should assign client_applications" do
167
+ do_invalid_update
168
+ assigns[:client_application].should == ClientApplication.find(1)
169
+ end
170
+
171
+ it "should render show template" do
172
+ do_invalid_update
173
+ response.should render_template('edit')
174
+ end
175
+ end
176
+ end