devise_invitable 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +108 -0
  3. data/README.rdoc +13 -1
  4. data/Rakefile +4 -3
  5. data/VERSION +1 -1
  6. data/app/controllers/{invitations_controller.rb → devise/invitations_controller.rb} +1 -1
  7. data/app/views/devise/invitations/edit.html.erb +14 -0
  8. data/app/views/devise/invitations/new.html.erb +12 -0
  9. data/app/views/{devise_mailer → devise/mailer}/invitation.html.erb +0 -0
  10. data/{lib/devise_invitable → config}/locales/en.yml +3 -0
  11. data/devise_invitable.gemspec +48 -35
  12. data/lib/devise_invitable.rb +4 -1
  13. data/lib/devise_invitable/controllers/helpers.rb +3 -2
  14. data/lib/devise_invitable/controllers/url_helpers.rb +21 -17
  15. data/lib/devise_invitable/mailer.rb +5 -7
  16. data/lib/devise_invitable/model.rb +5 -4
  17. data/lib/devise_invitable/rails.rb +13 -2
  18. data/lib/devise_invitable/routes.rb +6 -25
  19. data/lib/devise_invitable/schema.rb +2 -2
  20. data/test/integration/invitable_test.rb +31 -44
  21. data/test/integration_tests_helper.rb +22 -3
  22. data/test/mailers/invitation_test.rb +4 -4
  23. data/test/model_tests_helper.rb +1 -1
  24. data/test/models/invitable_test.rb +6 -6
  25. data/test/models_test.rb +1 -5
  26. data/test/rails_app/app/controllers/application_controller.rb +1 -8
  27. data/test/rails_app/app/helpers/application_helper.rb +0 -1
  28. data/test/rails_app/app/models/user.rb +1 -1
  29. data/test/rails_app/app/views/layouts/application.html.erb +15 -0
  30. data/test/rails_app/config.ru +4 -0
  31. data/test/rails_app/config/application.rb +45 -0
  32. data/test/rails_app/config/boot.rb +13 -110
  33. data/test/rails_app/config/environment.rb +4 -43
  34. data/test/rails_app/config/environments/development.rb +22 -13
  35. data/test/rails_app/config/environments/production.rb +41 -20
  36. data/test/rails_app/config/environments/test.rb +35 -28
  37. data/test/rails_app/config/initializers/backtrace_silencers.rb +1 -1
  38. data/test/rails_app/config/initializers/devise.rb +82 -45
  39. data/test/rails_app/config/initializers/inflections.rb +10 -2
  40. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  41. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  42. data/test/rails_app/config/initializers/session_store.rb +2 -9
  43. data/test/rails_app/config/locales/en.yml +5 -0
  44. data/test/rails_app/config/routes.rb +3 -2
  45. data/test/routes_test.rb +4 -4
  46. data/test/test_helper.rb +7 -36
  47. metadata +85 -33
  48. data/app/views/invitations/edit.html.erb +0 -14
  49. data/app/views/invitations/new.html.erb +0 -12
  50. data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -21
  51. data/test/rails_app/vendor/plugins/devise_invitable/init.rb +0 -1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise_invitable (0.3.0)
5
+ devise (~> 1.1.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.0)
12
+ actionpack (= 3.0.0)
13
+ mail (~> 2.2.5)
14
+ actionpack (3.0.0)
15
+ activemodel (= 3.0.0)
16
+ activesupport (= 3.0.0)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4.1)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.12)
22
+ rack-test (~> 0.5.4)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.0)
25
+ activesupport (= 3.0.0)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4.1)
28
+ activerecord (3.0.0)
29
+ activemodel (= 3.0.0)
30
+ activesupport (= 3.0.0)
31
+ arel (~> 1.0.0)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.0)
34
+ activemodel (= 3.0.0)
35
+ activesupport (= 3.0.0)
36
+ activesupport (3.0.0)
37
+ arel (1.0.1)
38
+ activesupport (~> 3.0.0)
39
+ bcrypt-ruby (2.1.2)
40
+ builder (2.1.2)
41
+ capybara (0.3.9)
42
+ culerity (>= 0.2.4)
43
+ mime-types (>= 1.16)
44
+ nokogiri (>= 1.3.3)
45
+ rack (>= 1.0.0)
46
+ rack-test (>= 0.5.4)
47
+ selenium-webdriver (>= 0.0.3)
48
+ culerity (0.2.12)
49
+ devise (1.1.2)
50
+ bcrypt-ruby (~> 2.1.2)
51
+ warden (~> 0.10.7)
52
+ erubis (2.6.6)
53
+ abstract (>= 1.0.0)
54
+ ffi (0.6.3)
55
+ rake (>= 0.8.7)
56
+ i18n (0.4.1)
57
+ json_pure (1.4.6)
58
+ mail (2.2.6)
59
+ activesupport (>= 2.3.6)
60
+ mime-types
61
+ treetop (>= 1.4.5)
62
+ mime-types (1.16)
63
+ mocha (0.9.8)
64
+ rake
65
+ nokogiri (1.4.3.1)
66
+ polyglot (0.3.1)
67
+ rack (1.2.1)
68
+ rack-mount (0.6.13)
69
+ rack (>= 1.0.0)
70
+ rack-test (0.5.4)
71
+ rack (>= 1.0)
72
+ rails (3.0.0)
73
+ actionmailer (= 3.0.0)
74
+ actionpack (= 3.0.0)
75
+ activerecord (= 3.0.0)
76
+ activeresource (= 3.0.0)
77
+ activesupport (= 3.0.0)
78
+ bundler (~> 1.0.0)
79
+ railties (= 3.0.0)
80
+ railties (3.0.0)
81
+ actionpack (= 3.0.0)
82
+ activesupport (= 3.0.0)
83
+ rake (>= 0.8.4)
84
+ thor (~> 0.14.0)
85
+ rake (0.8.7)
86
+ rubyzip (0.9.4)
87
+ selenium-webdriver (0.0.28)
88
+ ffi (>= 0.6.1)
89
+ json_pure
90
+ rubyzip
91
+ sqlite3-ruby (1.3.1)
92
+ thor (0.14.0)
93
+ treetop (1.4.8)
94
+ polyglot (>= 0.3.1)
95
+ tzinfo (0.3.23)
96
+ warden (0.10.7)
97
+ rack (>= 1.0.0)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ capybara (>= 0.3.9)
104
+ devise (~> 1.1.0)
105
+ devise_invitable!
106
+ mocha (>= 0.9.8)
107
+ rails (~> 3.0.0)
108
+ sqlite3-ruby
data/README.rdoc CHANGED
@@ -58,6 +58,18 @@ You have to configure mailer as it's required for confirmable and recoverable.
58
58
 
59
59
  It uses two flash messages, :send_invitation and :updated, which are translated as other flash messages from devise.
60
60
 
61
+ == Sending an invitation
62
+
63
+ To send an invitation to a user use send_invitation class model. You must set email in the attributes hash:
64
+
65
+ User.send_invitation(:email => 'new_user@example.com')
66
+
67
+ To accept an invitation with a token use accept_invitation! class model. You must set invitiation_token attribute, and you can include other attriutes in the hash, which will be updated in the record.
68
+
69
+ User.accept_invitation!(:invitation_token => params[:invitation_token])
70
+
71
+ Invitations controller implement this. You can go to /users/invitation/new to send an invitation and an email will be sent with a link to accept in invitiation with a URL like /users/invitation/accept?invitation_token=...
72
+
61
73
  == Adding Invitable to a running application
62
74
 
63
75
  Define a migration to add invitable to your model:
@@ -74,7 +86,7 @@ Define a migration to add invitable to your model:
74
86
 
75
87
  Add :invitable to the devise line of your model, or to config.all in devise initializer if your model uses devise :all.
76
88
 
77
- Override authenticate_resource! filter if you need to customize who can send invitations.
89
+ Override authenticate_resource! filter if you need to customize who can send invitations as it's explained in controller filters section.
78
90
 
79
91
  == Note on Patches/Pull Requests
80
92
 
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
2
 
4
3
  begin
@@ -10,8 +9,10 @@ begin
10
9
  gem.email = "sergio@entrecables.com"
11
10
  gem.homepage = "http://github.com/scambra/devise_invitable"
12
11
  gem.authors = ["Sergio Cambra"]
13
- gem.add_development_dependency 'mocha'
14
- gem.add_development_dependency 'webrat'
12
+ gem.add_development_dependency 'mocha', '>= 0.9.8'
13
+ gem.add_development_dependency 'capybara', '>= 0.3.9'
14
+ gem.add_development_dependency 'rails', '~> 3.0.0'
15
+ gem.add_development_dependency 'sqlite3-ruby'
15
16
  gem.add_dependency 'devise', '~> 1.1.0'
16
17
  end
17
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,4 +1,4 @@
1
- class InvitationsController < ApplicationController
1
+ class Devise::InvitationsController < ApplicationController
2
2
  include Devise::Controllers::InternalHelpers
3
3
 
4
4
  before_filter :authenticate_resource!, :only => [:new, :create]
@@ -0,0 +1,14 @@
1
+ <h2>Set your password</h2>
2
+
3
+ <%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => { :method => :put } do |f| %>
4
+ <%= devise_error_messages! %>
5
+ <%= f.hidden_field :invitation_token %>
6
+
7
+ <p><%= f.label :password %><br />
8
+ <%= f.password_field :password %></p>
9
+
10
+ <p><%= f.label :password_confirmation %><br />
11
+ <%= f.password_field :password_confirmation %></p>
12
+
13
+ <p><%= f.submit "Set my password" %></p>
14
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <h2>Send invitation</h2>
2
+
3
+ <%= form_for resource, :as => resource_name, :url => invitation_path(resource_name) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.text_field :email %></p>
8
+
9
+ <p><%= f.submit "Send an invitation" %></p>
10
+ <% end %>
11
+
12
+ <%= link_to "Home", after_sign_in_path_for(resource_name) %><br />
@@ -3,3 +3,6 @@ en:
3
3
  invitations:
4
4
  send_instructions: 'An email with instructions about how to set the password has been sent.'
5
5
  updated: 'Your password was set successfully. You are now signed in.'
6
+ mailer:
7
+ invitiation:
8
+ subject: 'Invitation'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{devise_invitable}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sergio Cambra"]
12
- s.date = %q{2010-05-17}
12
+ s.date = %q{2010-09-13}
13
13
  s.description = %q{It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password}
14
14
  s.email = %q{sergio@entrecables.com}
15
15
  s.extra_rdoc_files = [
@@ -19,20 +19,22 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ "Gemfile",
23
+ "Gemfile.lock",
22
24
  "LICENSE",
23
25
  "README.rdoc",
24
26
  "Rakefile",
25
27
  "VERSION",
26
- "app/controllers/invitations_controller.rb",
27
- "app/views/devise_mailer/invitation.html.erb",
28
- "app/views/invitations/edit.html.erb",
29
- "app/views/invitations/new.html.erb",
28
+ "app/controllers/devise/invitations_controller.rb",
29
+ "app/views/devise/invitations/edit.html.erb",
30
+ "app/views/devise/invitations/new.html.erb",
31
+ "app/views/devise/mailer/invitation.html.erb",
32
+ "config/locales/en.yml",
30
33
  "devise_invitable.gemspec",
31
34
  "init.rb",
32
35
  "lib/devise_invitable.rb",
33
36
  "lib/devise_invitable/controllers/helpers.rb",
34
37
  "lib/devise_invitable/controllers/url_helpers.rb",
35
- "lib/devise_invitable/locales/en.yml",
36
38
  "lib/devise_invitable/mailer.rb",
37
39
  "lib/devise_invitable/model.rb",
38
40
  "lib/devise_invitable/rails.rb",
@@ -51,6 +53,9 @@ Gem::Specification.new do |s|
51
53
  "test/rails_app/app/helpers/application_helper.rb",
52
54
  "test/rails_app/app/models/user.rb",
53
55
  "test/rails_app/app/views/home/index.html.erb",
56
+ "test/rails_app/app/views/layouts/application.html.erb",
57
+ "test/rails_app/config.ru",
58
+ "test/rails_app/config/application.rb",
54
59
  "test/rails_app/config/boot.rb",
55
60
  "test/rails_app/config/database.yml",
56
61
  "test/rails_app/config/environment.rb",
@@ -60,63 +65,71 @@ Gem::Specification.new do |s|
60
65
  "test/rails_app/config/initializers/backtrace_silencers.rb",
61
66
  "test/rails_app/config/initializers/devise.rb",
62
67
  "test/rails_app/config/initializers/inflections.rb",
63
- "test/rails_app/config/initializers/new_rails_defaults.rb",
68
+ "test/rails_app/config/initializers/mime_types.rb",
69
+ "test/rails_app/config/initializers/secret_token.rb",
64
70
  "test/rails_app/config/initializers/session_store.rb",
71
+ "test/rails_app/config/locales/en.yml",
65
72
  "test/rails_app/config/routes.rb",
66
- "test/rails_app/vendor/plugins/devise_invitable/init.rb",
67
73
  "test/routes_test.rb",
68
74
  "test/test_helper.rb"
69
75
  ]
70
76
  s.homepage = %q{http://github.com/scambra/devise_invitable}
71
77
  s.rdoc_options = ["--charset=UTF-8"]
72
78
  s.require_paths = ["lib"]
73
- s.rubygems_version = %q{1.3.6}
79
+ s.rubygems_version = %q{1.3.7}
74
80
  s.summary = %q{An invitation strategy for devise}
75
81
  s.test_files = [
76
- "test/integration/invitable_test.rb",
77
- "test/integration_tests_helper.rb",
78
- "test/mailers/invitation_test.rb",
79
- "test/model_tests_helper.rb",
80
- "test/models/invitable_test.rb",
81
- "test/models_test.rb",
82
+ "test/test_helper.rb",
83
+ "test/integration/invitable_test.rb",
84
+ "test/routes_test.rb",
85
+ "test/rails_app/app/helpers/application_helper.rb",
86
+ "test/rails_app/app/models/user.rb",
82
87
  "test/rails_app/app/controllers/admins_controller.rb",
83
88
  "test/rails_app/app/controllers/application_controller.rb",
84
89
  "test/rails_app/app/controllers/home_controller.rb",
85
90
  "test/rails_app/app/controllers/users_controller.rb",
86
- "test/rails_app/app/helpers/application_helper.rb",
87
- "test/rails_app/app/models/user.rb",
88
- "test/rails_app/config/boot.rb",
91
+ "test/rails_app/config/initializers/devise.rb",
92
+ "test/rails_app/config/initializers/inflections.rb",
93
+ "test/rails_app/config/initializers/mime_types.rb",
94
+ "test/rails_app/config/initializers/secret_token.rb",
95
+ "test/rails_app/config/initializers/session_store.rb",
96
+ "test/rails_app/config/initializers/backtrace_silencers.rb",
89
97
  "test/rails_app/config/environment.rb",
90
- "test/rails_app/config/environments/development.rb",
91
98
  "test/rails_app/config/environments/production.rb",
92
99
  "test/rails_app/config/environments/test.rb",
93
- "test/rails_app/config/initializers/backtrace_silencers.rb",
94
- "test/rails_app/config/initializers/inflections.rb",
95
- "test/rails_app/config/initializers/new_rails_defaults.rb",
96
- "test/rails_app/config/initializers/session_store.rb",
97
- "test/rails_app/config/initializers/devise.rb",
100
+ "test/rails_app/config/environments/development.rb",
98
101
  "test/rails_app/config/routes.rb",
99
- "test/rails_app/vendor/plugins/devise_invitable/init.rb",
100
- "test/routes_test.rb",
101
- "test/test_helper.rb"
102
+ "test/rails_app/config/application.rb",
103
+ "test/rails_app/config/boot.rb",
104
+ "test/integration_tests_helper.rb",
105
+ "test/model_tests_helper.rb",
106
+ "test/models_test.rb",
107
+ "test/mailers/invitation_test.rb",
108
+ "test/models/invitable_test.rb"
102
109
  ]
103
110
 
104
111
  if s.respond_to? :specification_version then
105
112
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
106
113
  s.specification_version = 3
107
114
 
108
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
109
- s.add_development_dependency(%q<mocha>, [">= 0"])
110
- s.add_development_dependency(%q<webrat>, [">= 0"])
115
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
116
+ s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
117
+ s.add_development_dependency(%q<capybara>, [">= 0.3.9"])
118
+ s.add_development_dependency(%q<rails>, ["~> 3.0.0"])
119
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
111
120
  s.add_runtime_dependency(%q<devise>, ["~> 1.1.0"])
112
121
  else
113
- s.add_dependency(%q<mocha>, [">= 0"])
114
- s.add_dependency(%q<webrat>, [">= 0"])
122
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
123
+ s.add_dependency(%q<capybara>, [">= 0.3.9"])
124
+ s.add_dependency(%q<rails>, ["~> 3.0.0"])
125
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
115
126
  s.add_dependency(%q<devise>, ["~> 1.1.0"])
116
127
  end
117
128
  else
118
- s.add_dependency(%q<mocha>, [">= 0"])
119
- s.add_dependency(%q<webrat>, [">= 0"])
129
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
130
+ s.add_dependency(%q<capybara>, [">= 0.3.9"])
131
+ s.add_dependency(%q<rails>, ["~> 3.0.0"])
132
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
120
133
  s.add_dependency(%q<devise>, ["~> 1.1.0"])
121
134
  end
122
135
  end
@@ -7,11 +7,14 @@ Devise.module_eval do
7
7
  mattr_accessor :invite_for
8
8
  @@invite_for = 0
9
9
  end
10
- Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model'
10
+
11
+ Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => :invitation
11
12
 
12
13
  module DeviseInvitable; end
13
14
 
14
15
  require 'devise_invitable/mailer'
15
16
  require 'devise_invitable/routes'
16
17
  require 'devise_invitable/schema'
18
+ require 'devise_invitable/controllers/url_helpers'
19
+ require 'devise_invitable/controllers/helpers'
17
20
  require 'devise_invitable/rails'
@@ -1,6 +1,7 @@
1
- DeviseInvitable::Controllers::Helpers.module_eval do
1
+ module DeviseInvitable::Controllers::Helpers
2
2
  protected
3
3
  def authenticate_resource!
4
- authenticate!(resource_name)
4
+ send(:"authenticate_#{resource_name}!")
5
5
  end
6
6
  end
7
+ ActionController::Base.send :include, DeviseInvitable::Controllers::Helpers
@@ -1,20 +1,24 @@
1
- Devise::Controllers::UrlHelpers.module_eval do
2
- [:path, :url].each do |path_or_url|
3
- [nil, :new_, :accept_].each do |action|
4
- class_eval <<-URL_HELPERS
5
- def #{action}invitation_#{path_or_url}(resource, *args)
6
- resource = case resource
7
- when Symbol, String
8
- resource
9
- when Class
10
- resource.name.underscore
11
- else
12
- resource.class.name.underscore
13
- end
14
-
15
- send("#{action}\#{resource}_invitation_#{path_or_url}", *args)
1
+ module DeviseInvitable
2
+ module Controllers
3
+ module UrlHelpers
4
+ [:path, :url].each do |path_or_url|
5
+ [nil, :new_, :accept_].each do |action|
6
+ class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
7
+ def #{action}invitation_#{path_or_url}(resource, *args)
8
+ resource = case resource
9
+ when Symbol, String
10
+ resource
11
+ when Class
12
+ resource.name.underscore
13
+ else
14
+ resource.class.name.underscore
15
+ end
16
+
17
+ send("#{action}\#{resource}_invitation_#{path_or_url}", *args)
18
+ end
19
+ URL_HELPERS
16
20
  end
17
- URL_HELPERS
21
+ end
18
22
  end
19
23
  end
20
- end
24
+ end
@@ -1,9 +1,7 @@
1
- module DeviseInvitable
2
- module Mailer
3
- # Deliver an invitation when is requested
4
- def invitation(record)
5
- setup_mail(record, :invitation)
6
- end
1
+ module DeviseInvitable::Mailer
2
+
3
+ # Deliver an invitation when is requested
4
+ def invitation(record)
5
+ setup_mail(record, :invitation)
7
6
  end
8
7
  end
9
- Devise::Mailer.send :include, DeviseInvitable::Mailer