devise_invitable 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,6 +1,76 @@
1
1
  = devise_invitable
2
2
 
3
- It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password.
3
+ It adds support to devise[http://github.com/plataformatec/devise] for send invitations by email (it requires to be authenticated) and accept the invitation setting the password.
4
+
5
+ == Installation
6
+
7
+ All gems are on gemcutter, so you need to add gemcutter to your sources if you haven’t yet:
8
+
9
+ sudo gem sources -a http://gemcutter.org/
10
+
11
+ Install devise_invitable gem, it should install dependencies (such as devise and warden):
12
+
13
+ sudo gem install devise_invitable
14
+
15
+ Configure devise_invitable inside your app (and warden and devise if you weren't using them):
16
+
17
+ config.gem 'warden'
18
+ config.gem 'devise'
19
+ config.gem 'devise_invitable'
20
+
21
+ == Basic Usage
22
+
23
+ Follow the walkthrough for devise with the following modifications.
24
+
25
+ Add t.invitable to the migration:
26
+
27
+ create_table :users do
28
+ ...
29
+ t.invitable
30
+ ...
31
+ end
32
+ add_index :users, :invitation_token # for invitable
33
+
34
+ Add :invitable to the devise line in your model:
35
+
36
+ class User < ActiveRecord::Base
37
+ devise ..., :invitable
38
+ end
39
+
40
+ If you are using devise :all, you can add :invitable to config.all in devise initializer:
41
+ Devise.setup do |config|
42
+ ...
43
+ config.all = [..., :invitable]
44
+ ...
45
+ end
46
+
47
+ == Model configuration
48
+
49
+ DeviseInvitable adds a new configuration option, :invite_for. It's the time a invitation is valid for. Default value is nil, which means invitation doesn't expire.
50
+
51
+ == Controller filters
52
+
53
+ It adds authenticate_resource! filter to restrict who can send invitations. You can override this method in your ApplicationController. Default behavior is require authentication of the same resource_name, so if you only have a model with devise it will allow to all authenticated users to send invitations.
54
+
55
+ You have to configure mailer as it's required for confirmable and recoverable.
56
+
57
+ == I18n
58
+
59
+ It uses two flash messages, :send_invitation and :updated, which are translated as other flash messages from devise.
60
+
61
+ == Adding Invitable to a running application
62
+
63
+ Define a migration to add invitable to your model:
64
+
65
+ change_table :your_table do |t|
66
+ t.string :invitation_token, :limit => 20
67
+ t.datetime :invitation_sent_at
68
+ t.index :invitation_token
69
+ end
70
+
71
+ Add :invitable to the devise line of your model, or to config.all in devise initializer if your model uses devise :all.
72
+
73
+ Override authenticate_resource! filter if you need to customize who can send invitations.
4
74
 
5
75
  == Note on Patches/Pull Requests
6
76
 
@@ -10,7 +80,7 @@ It adds support for send invitations by email (it requires to be authenticated)
10
80
  future version unintentionally.
11
81
  * Commit, do not mess with rakefile, version, or history.
12
82
  (if you want to have your own version, that is fine but
13
- bump version in a commit by itself I can ignore when I pull)
83
+ bump version in a commit by itself I can ignore when I pull)
14
84
  * Send me a pull request. Bonus points for topic branches.
15
85
 
16
86
  == Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -23,7 +23,7 @@ class InvitationsController < ApplicationController
23
23
  end
24
24
  end
25
25
 
26
- # GET /resource/invitation/edit?invitation_token=abcdef
26
+ # GET /resource/invitation/accept?invitation_token=abcdef
27
27
  def edit
28
28
  self.resource = resource_class.new
29
29
  resource.invitation_token = params[:invitation_token]
@@ -2,7 +2,7 @@ Hello <%= @resource.email %>!
2
2
 
3
3
  Someone has invited you to <%= root_url %>, you can accept it through the link below.
4
4
 
5
- <%= link_to 'Accept invitation', edit_invitation_url(@resource, :invitation_token => @resource.invitation_token) %>
5
+ <%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %>
6
6
 
7
7
  If you don't want to accept the invitation, please ignore this email.
8
8
  Your account won't be created until you access the link above and set your password.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{devise_invitable}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
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"]
@@ -1,6 +1,6 @@
1
1
  Devise::Controllers::UrlHelpers.module_eval do
2
2
  [:path, :url].each do |path_or_url|
3
- [nil, :new_, :edit_].each do |action|
3
+ [nil, :new_, :accept_].each do |action|
4
4
  class_eval <<-URL_HELPERS
5
5
  def #{action}invitation_#{path_or_url}(resource, *args)
6
6
  resource = case resource
@@ -17,4 +17,4 @@ Devise::Controllers::UrlHelpers.module_eval do
17
17
  URL_HELPERS
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -12,15 +12,16 @@ module DeviseInvitable
12
12
  # needed routes:
13
13
  #
14
14
  # # Invitation routes for Invitable, if User model has :invitable configured
15
- # new_user_invitation GET /users/invitation/new(.:format) {:controller=>"invitations", :action=>"new"}
16
- # edit_user_invitation GET /users/invitation/edit(.:format) {:controller=>"invitations", :action=>"edit"}
17
- # user_invitation PUT /users/invitation(.:format) {:controller=>"invitations", :action=>"update"}
18
- # POST /users/invitation(.:format) {:controller=>"invitations", :action=>"create"}
15
+ # new_user_invitation GET /users/invitation/new(.:format) {:controller=>"invitations", :action=>"new"}
16
+ # user_invitation PUT /users/invitation(.:format) {:controller=>"invitations", :action=>"update"}
17
+ # POST /users/invitation(.:format) {:controller=>"invitations", :action=>"create"}
18
+ # accept_user_invitation GET /users/invitation/accept(.:format) {:controller=>"invitations", :action=>"edit"}
19
19
  #
20
20
 
21
21
  protected
22
22
  def invitable(routes, mapping)
23
- routes.resource :invitation, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:invitation]
23
+ routes.resource :invitation, :only => [:new, :create, :update], :as => mapping.path_names[:invitation]
24
+ routes.send(:"accept_#{mapping.name}_invitation", mapping.path_names[:accept] || 'accept', :controller => 'invitations', :action => 'edit', :name_prefix => nil, :path_prefix => "#{mapping.as}/invitation", :conditions => { :method => :get })
24
25
  end
25
26
  end
26
27
  end
@@ -17,7 +17,7 @@ class InvitationTest < ActionController::IntegrationTest
17
17
 
18
18
  def set_password(options={}, &block)
19
19
  unless options[:visit] == false
20
- visit edit_user_invitation_path(:invitation_token => options[:invitation_token])
20
+ visit accept_user_invitation_path(:invitation_token => options[:invitation_token])
21
21
  end
22
22
  assert_response :success
23
23
  assert_template 'invitations/edit'
@@ -59,7 +59,7 @@ class InvitationTest < ActionController::IntegrationTest
59
59
  test 'authenticated user should not be able to visit edit invitation page' do
60
60
  sign_in_as_user
61
61
 
62
- get edit_user_invitation_path
62
+ get accept_user_invitation_path
63
63
 
64
64
  assert_response :redirect
65
65
  assert_redirected_to root_path
@@ -56,7 +56,7 @@ class InviationTest < ActionMailer::TestCase
56
56
 
57
57
  test 'body should have link to confirm the account' do
58
58
  host = ActionMailer::Base.default_url_options[:host]
59
- invitation_url_regexp = %r{<a href=\"http://#{host}/users/invitation/edit\?invitation_token=#{user.invitation_token}">}
59
+ invitation_url_regexp = %r{<a href=\"http://#{host}/users/invitation/accept\?invitation_token=#{user.invitation_token}">}
60
60
  assert_match invitation_url_regexp, mail.body
61
61
  end
62
62
  end
data/test/routes_test.rb CHANGED
@@ -10,8 +10,8 @@ class MapRoutingTest < ActionController::TestCase
10
10
  assert_recognizes({:controller => 'invitations', :action => 'create'}, {:path => 'users/invitation', :method => :post})
11
11
  end
12
12
 
13
- test 'map edit user invitation' do
14
- assert_recognizes({:controller => 'invitations', :action => 'edit'}, 'users/invitation/edit')
13
+ test 'map accept user invitation' do
14
+ assert_recognizes({:controller => 'invitations', :action => 'edit'}, 'users/invitation/accept')
15
15
  end
16
16
 
17
17
  test 'map update user invitation' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra