devise_invitable 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/app/controllers/devise/invitations_controller.rb~ +48 -0
  2. data/config/locales/en.yml +1 -1
  3. data/lib/devise_invitable/model.rb +5 -0
  4. data/lib/devise_invitable/model.rb~ +129 -0
  5. data/lib/devise_invitable/version.rb +3 -0
  6. metadata +42 -104
  7. data/.document +0 -5
  8. data/.gitignore +0 -22
  9. data/Gemfile +0 -3
  10. data/Gemfile.lock +0 -117
  11. data/Rakefile +0 -55
  12. data/VERSION +0 -1
  13. data/devise_invitable.gemspec +0 -146
  14. data/test/generators_test.rb +0 -45
  15. data/test/integration/invitable_test.rb +0 -109
  16. data/test/integration_tests_helper.rb +0 -58
  17. data/test/mailers/invitation_test.rb +0 -62
  18. data/test/model_tests_helper.rb +0 -41
  19. data/test/models/invitable_test.rb +0 -188
  20. data/test/models_test.rb +0 -31
  21. data/test/rails_app/app/controllers/admins_controller.rb +0 -6
  22. data/test/rails_app/app/controllers/application_controller.rb +0 -3
  23. data/test/rails_app/app/controllers/home_controller.rb +0 -4
  24. data/test/rails_app/app/controllers/users_controller.rb +0 -12
  25. data/test/rails_app/app/helpers/application_helper.rb +0 -2
  26. data/test/rails_app/app/models/octopussy.rb +0 -11
  27. data/test/rails_app/app/models/user.rb +0 -4
  28. data/test/rails_app/app/views/home/index.html.erb +0 -0
  29. data/test/rails_app/app/views/layouts/application.html.erb +0 -15
  30. data/test/rails_app/app/views/users/invitations/new.html.erb +0 -15
  31. data/test/rails_app/config.ru +0 -4
  32. data/test/rails_app/config/application.rb +0 -46
  33. data/test/rails_app/config/boot.rb +0 -13
  34. data/test/rails_app/config/database.yml +0 -22
  35. data/test/rails_app/config/environment.rb +0 -5
  36. data/test/rails_app/config/environments/development.rb +0 -26
  37. data/test/rails_app/config/environments/production.rb +0 -49
  38. data/test/rails_app/config/environments/test.rb +0 -35
  39. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  40. data/test/rails_app/config/initializers/devise.rb +0 -144
  41. data/test/rails_app/config/initializers/inflections.rb +0 -10
  42. data/test/rails_app/config/initializers/mime_types.rb +0 -5
  43. data/test/rails_app/config/initializers/secret_token.rb +0 -7
  44. data/test/rails_app/config/initializers/session_store.rb +0 -8
  45. data/test/rails_app/config/locales/en.yml +0 -5
  46. data/test/rails_app/config/routes.rb +0 -4
  47. data/test/rails_app/script/rails +0 -6
  48. data/test/routes_test.rb +0 -20
  49. data/test/test_helper.rb +0 -30
data/Rakefile DELETED
@@ -1,55 +0,0 @@
1
- require 'rake'
2
-
3
- begin
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gem|
6
- gem.name = "devise_invitable"
7
- gem.summary = %Q{An invitation strategy for devise}
8
- gem.description = %Q{It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password}
9
- gem.email = "sergio@entrecables.com"
10
- gem.homepage = "http://github.com/scambra/devise_invitable"
11
- gem.authors = ["Sergio Cambra"]
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'
16
- gem.add_dependency 'devise', '~> 1.1.0'
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
- end
22
-
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/*_test.rb'
27
- test.verbose = true
28
- end
29
-
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
41
- end
42
-
43
- task :test => :check_dependencies
44
-
45
- task :default => :test
46
-
47
- require 'rake/rdoctask'
48
- Rake::RDocTask.new do |rdoc|
49
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
-
51
- rdoc.rdoc_dir = 'rdoc'
52
- rdoc.title = "devise_invitable #{version}"
53
- rdoc.rdoc_files.include('README*')
54
- rdoc.rdoc_files.include('lib/**/*.rb')
55
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.5
@@ -1,146 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{devise_invitable}
8
- s.version = "0.3.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Sergio Cambra"]
12
- s.date = %q{2010-11-02}
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
- s.email = %q{sergio@entrecables.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
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",
33
- "devise_invitable.gemspec",
34
- "lib/devise_invitable.rb",
35
- "lib/devise_invitable/controllers/helpers.rb",
36
- "lib/devise_invitable/controllers/url_helpers.rb",
37
- "lib/devise_invitable/mailer.rb",
38
- "lib/devise_invitable/model.rb",
39
- "lib/devise_invitable/rails.rb",
40
- "lib/devise_invitable/routes.rb",
41
- "lib/devise_invitable/schema.rb",
42
- "lib/generators/active_record/devise_invitable_generator.rb",
43
- "lib/generators/active_record/templates/migration.rb",
44
- "lib/generators/devise_invitable/devise_invitable_generator.rb",
45
- "lib/generators/devise_invitable/install_generator.rb",
46
- "lib/generators/devise_invitable/views_generator.rb",
47
- "test/generators_test.rb",
48
- "test/integration/invitable_test.rb",
49
- "test/integration_tests_helper.rb",
50
- "test/mailers/invitation_test.rb",
51
- "test/model_tests_helper.rb",
52
- "test/models/invitable_test.rb",
53
- "test/models_test.rb",
54
- "test/rails_app/app/controllers/admins_controller.rb",
55
- "test/rails_app/app/controllers/application_controller.rb",
56
- "test/rails_app/app/controllers/home_controller.rb",
57
- "test/rails_app/app/controllers/users_controller.rb",
58
- "test/rails_app/app/helpers/application_helper.rb",
59
- "test/rails_app/app/models/octopussy.rb",
60
- "test/rails_app/app/models/user.rb",
61
- "test/rails_app/app/views/home/index.html.erb",
62
- "test/rails_app/app/views/layouts/application.html.erb",
63
- "test/rails_app/app/views/users/invitations/new.html.erb",
64
- "test/rails_app/config.ru",
65
- "test/rails_app/config/application.rb",
66
- "test/rails_app/config/boot.rb",
67
- "test/rails_app/config/database.yml",
68
- "test/rails_app/config/environment.rb",
69
- "test/rails_app/config/environments/development.rb",
70
- "test/rails_app/config/environments/production.rb",
71
- "test/rails_app/config/environments/test.rb",
72
- "test/rails_app/config/initializers/backtrace_silencers.rb",
73
- "test/rails_app/config/initializers/devise.rb",
74
- "test/rails_app/config/initializers/inflections.rb",
75
- "test/rails_app/config/initializers/mime_types.rb",
76
- "test/rails_app/config/initializers/secret_token.rb",
77
- "test/rails_app/config/initializers/session_store.rb",
78
- "test/rails_app/config/locales/en.yml",
79
- "test/rails_app/config/routes.rb",
80
- "test/rails_app/script/rails",
81
- "test/routes_test.rb",
82
- "test/test_helper.rb"
83
- ]
84
- s.homepage = %q{http://github.com/scambra/devise_invitable}
85
- s.rdoc_options = ["--charset=UTF-8"]
86
- s.require_paths = ["lib"]
87
- s.rubygems_version = %q{1.3.7}
88
- s.summary = %q{An invitation strategy for devise}
89
- s.test_files = [
90
- "test/integration/invitable_test.rb",
91
- "test/integration_tests_helper.rb",
92
- "test/mailers/invitation_test.rb",
93
- "test/model_tests_helper.rb",
94
- "test/models/invitable_test.rb",
95
- "test/models_test.rb",
96
- "test/rails_app/app/controllers/admins_controller.rb",
97
- "test/rails_app/app/controllers/application_controller.rb",
98
- "test/rails_app/app/controllers/home_controller.rb",
99
- "test/rails_app/app/controllers/users_controller.rb",
100
- "test/rails_app/app/helpers/application_helper.rb",
101
- "test/rails_app/app/models/user.rb",
102
- "test/rails_app/app/models/octopussy.rb",
103
- "test/rails_app/config/boot.rb",
104
- "test/rails_app/config/environment.rb",
105
- "test/rails_app/config/environments/development.rb",
106
- "test/rails_app/config/environments/production.rb",
107
- "test/rails_app/config/environments/test.rb",
108
- "test/rails_app/config/initializers/backtrace_silencers.rb",
109
- "test/rails_app/config/initializers/inflections.rb",
110
- "test/rails_app/config/initializers/devise.rb",
111
- "test/rails_app/config/initializers/session_store.rb",
112
- "test/rails_app/config/initializers/mime_types.rb",
113
- "test/rails_app/config/initializers/secret_token.rb",
114
- "test/rails_app/config/routes.rb",
115
- "test/rails_app/config/application.rb",
116
- "test/routes_test.rb",
117
- "test/test_helper.rb",
118
- "test/generators_test.rb"
119
- ]
120
-
121
- if s.respond_to? :specification_version then
122
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
123
- s.specification_version = 3
124
-
125
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
126
- s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
127
- s.add_development_dependency(%q<capybara>, [">= 0.3.9"])
128
- s.add_development_dependency(%q<rails>, ["~> 3.0.0"])
129
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
130
- s.add_runtime_dependency(%q<devise>, ["~> 1.1.0"])
131
- else
132
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
133
- s.add_dependency(%q<capybara>, [">= 0.3.9"])
134
- s.add_dependency(%q<rails>, ["~> 3.0.0"])
135
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
136
- s.add_dependency(%q<devise>, ["~> 1.1.0"])
137
- end
138
- else
139
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
140
- s.add_dependency(%q<capybara>, [">= 0.3.9"])
141
- s.add_dependency(%q<rails>, ["~> 3.0.0"])
142
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
143
- s.add_dependency(%q<devise>, ["~> 1.1.0"])
144
- end
145
- end
146
-
@@ -1,45 +0,0 @@
1
- require 'test/test_helper'
2
- require 'rails/generators'
3
- require 'generators/devise_invitable/devise_invitable_generator'
4
-
5
- class GeneratorsTest < ActiveSupport::TestCase
6
- RAILS_APP_PATH = File.expand_path("../rails_app", __FILE__)
7
-
8
- test "rails g should include the 3 generators" do
9
- @output = `cd #{RAILS_APP_PATH} && rails g`
10
- assert @output.match(%r|DeviseInvitable:\n devise_invitable\n devise_invitable:install\n devise_invitable:views|)
11
- end
12
-
13
- test "rails g devise_invitable:install" do
14
- @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
15
- assert @output.match(%r|inject.+ config/initializers/devise\.rb\n|)
16
- assert @output.match(%r|create.+ config/locales/devise_invitable\.en\.yml\n|)
17
- end
18
-
19
- test "rails g devise_invitable:views not scoped" do
20
- @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views -p`
21
- assert @output.match(%r|create.+ app/views/devise\n|)
22
- assert @output.match(%r|create.+ app/views/devise/invitations/edit\.html\.erb\n|)
23
- assert @output.match(%r|create.+ app/views/devise/invitations/new\.html\.erb\n|)
24
- assert @output.match(%r|create.+ app/views/devise/mailer/invitation\.html\.erb\n|)
25
- end
26
-
27
- test "rails g devise_invitable:views scoped" do
28
- @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views octopussies -p`
29
- assert @output.match(%r|create.+ app/views/octopussies\n|)
30
- assert @output.match(%r|create.+ app/views/octopussies/invitations/edit\.html\.erb\n|)
31
- assert @output.match(%r|create.+ app/views/octopussies/invitations/new\.html\.erb\n|)
32
- assert @output.match(%r|create.+ app/views/octopussies/mailer/invitation\.html\.erb\n|)
33
- end
34
-
35
- test "rails g devise_invitable Octopussy" do
36
- @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
37
- assert @output.match(%r|inject.+ app/models/octopussy\.rb\n|)
38
- assert @output.match(%r|invoke.+ #{DEVISE_ORM}\n|)
39
- if DEVISE_ORM == :active_record
40
- assert @output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
41
- elsif DEVISE_ORM == :mongoid
42
- assert !@output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
43
- end
44
- end
45
- end
@@ -1,109 +0,0 @@
1
- require 'test/test_helper'
2
- require 'test/integration_tests_helper'
3
-
4
- class InvitationTest < ActionDispatch::IntegrationTest
5
- def teardown
6
- Capybara.reset_sessions!
7
- end
8
-
9
- def send_invitation(&block)
10
- visit new_user_invitation_path
11
-
12
- fill_in 'user_email', :with => 'user@test.com'
13
- yield if block_given?
14
- click_button 'Send an invitation'
15
- end
16
-
17
- def set_password(options={}, &block)
18
- unless options[:visit] == false
19
- visit accept_user_invitation_path(:invitation_token => options[:invitation_token])
20
- end
21
-
22
- fill_in 'user_password', :with => '987654321'
23
- fill_in 'user_password_confirmation', :with => '987654321'
24
- yield if block_given?
25
- click_button 'Set my password'
26
- end
27
-
28
- test 'not authenticated user should not be able to send an invitation' do
29
- get new_user_invitation_path
30
- assert_redirected_to new_user_session_path
31
- end
32
-
33
- test 'authenticated user should be able to send an invitation' do
34
- sign_in_as_user
35
-
36
- send_invitation
37
- assert_equal root_path, current_path
38
- assert page.has_css?('p#notice', :text => 'An email with instructions about how to set the password has been sent.')
39
- end
40
-
41
- test 'authenticated user with invalid email should receive an error message' do
42
- user = create_full_user
43
- sign_in_as_user(user)
44
- send_invitation do
45
- fill_in 'user_email', :with => user.email
46
- end
47
-
48
- assert_equal user_invitation_path, current_path
49
- assert page.has_css?("input[type=text][value='#{user.email}']")
50
- assert page.has_css?('#error_explanation li', :text => 'Email has already been taken')
51
- end
52
-
53
- test 'authenticated user should not be able to visit edit invitation page' do
54
- sign_in_as_user
55
-
56
- visit accept_user_invitation_path
57
-
58
- assert_equal root_path, current_path
59
- end
60
-
61
- test 'not authenticated user with invalid invitation token should not be able to set his password' do
62
- user = create_user
63
- set_password :invitation_token => 'invalid_token'
64
-
65
- assert_equal user_invitation_path, current_path
66
- assert page.has_css?('#error_explanation li', :text => 'Invitation token is invalid')
67
- assert_nil user.encrypted_password
68
- end
69
-
70
- test 'not authenticated user with valid invitation token but invalid password should not be able to set his password' do
71
- user = create_user(false)
72
- set_password :invitation_token => user.invitation_token do
73
- fill_in 'Password confirmation', :with => 'other_password'
74
- end
75
-
76
- assert_equal user_invitation_path, current_path
77
- assert page.has_css?('#error_explanation li', :text => 'Password doesn\'t match confirmation')
78
- assert_nil user.encrypted_password
79
- end
80
-
81
- test 'not authenticated user with valid data should be able to change his password' do
82
- user = create_user(false)
83
- set_password :invitation_token => user.invitation_token
84
-
85
- assert_equal root_path, current_path
86
- assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
87
- assert user.reload.valid_password?('987654321')
88
- end
89
-
90
- test 'after entering invalid data user should still be able to set his password' do
91
- user = create_user(false)
92
- set_password :invitation_token => user.invitation_token do
93
- fill_in 'Password confirmation', :with => 'other_password'
94
- end
95
- assert_equal user_invitation_path, current_path
96
- assert page.has_css?('#error_explanation')
97
- assert_nil user.encrypted_password
98
-
99
- set_password :visit => false
100
- assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
101
- assert user.reload.valid_password?('987654321')
102
- end
103
-
104
- test 'sign in user automatically after setting it\'s password' do
105
- user = create_user(false)
106
- set_password :invitation_token => user.invitation_token
107
- assert_equal root_path, current_path
108
- end
109
- end
@@ -1,58 +0,0 @@
1
- class ActionController::IntegrationTest
2
-
3
- def warden
4
- request.env['warden']
5
- end
6
-
7
- def create_full_user
8
- @user ||= begin
9
- user = User.create!(
10
- :username => 'usertest',
11
- :email => 'fulluser@test.com',
12
- :password => '123456',
13
- :password_confirmation => '123456',
14
- :created_at => Time.now.utc
15
- )
16
- user.confirm!
17
- user
18
- end
19
- end
20
-
21
- def sign_in_as_user(user = nil)
22
- user ||= create_full_user
23
- visit new_user_session_path
24
- fill_in 'user_email', :with => user.email
25
- fill_in 'user_password', :with => '123456'
26
- fill_in 'user_password', :with => user.password
27
- click_button 'Sign in'
28
- end
29
-
30
- def create_user(accept_invitation = true)
31
- user = User.new :email => 'newuser@test.com'
32
- user.skip_confirmation!
33
- user.invitation_token = 'token'
34
- user.invitation_sent_at = Time.now.utc
35
- user.save(:validate => false)
36
- user.accept_invitation! if accept_invitation
37
- user
38
- end
39
-
40
- # Fix assert_redirect_to in integration sessions because they don't take into
41
- # account Middleware redirects.
42
- #
43
- def assert_redirected_to(url)
44
- assert [301, 302].include?(@integration_session.status),
45
- "Expected status to be 301 or 302, got #{@integration_session.status}"
46
-
47
- url = prepend_host(url)
48
- location = prepend_host(@integration_session.headers["Location"])
49
- assert_equal url, location
50
- end
51
-
52
- protected
53
-
54
- def prepend_host(url)
55
- url = "http://#{request.host}#{url}" if url[0] == ?/
56
- url
57
- end
58
- end
@@ -1,62 +0,0 @@
1
- require 'test/test_helper'
2
-
3
- class InvitationMailTest < ActionMailer::TestCase
4
-
5
- def setup
6
- setup_mailer
7
- Devise.mailer_sender = 'test@example.com'
8
- end
9
-
10
- def user
11
- @user ||= begin
12
- user = create_user_with_invitation('token')
13
- user.send_invitation
14
- user
15
- end
16
- end
17
-
18
- def mail
19
- @mail ||= begin
20
- user
21
- ActionMailer::Base.deliveries.last
22
- end
23
- end
24
-
25
- test 'email sent after reseting the user password' do
26
- assert_not_nil mail
27
- end
28
-
29
- test 'content type should be set to html' do
30
- assert_equal 'text/html; charset=UTF-8', mail.content_type
31
- end
32
-
33
- test 'send invitation to the user email' do
34
- assert_equal [user.email], mail.to
35
- end
36
-
37
- test 'setup sender from configuration' do
38
- assert_equal ['test@example.com'], mail.from
39
- end
40
-
41
- test 'setup subject from I18n' do
42
- store_translations :en, :devise => { :mailer => { :invitation => { :subject => 'Localized Invitation' } } } do
43
- assert_equal 'Localized Invitation', mail.subject
44
- end
45
- end
46
-
47
- test 'subject namespaced by model' do
48
- store_translations :en, :devise => { :mailer => { :invitation => { :user_subject => 'User Invitation' } } } do
49
- assert_equal 'User Invitation', mail.subject
50
- end
51
- end
52
-
53
- test 'body should have user info' do
54
- assert_match /#{user.email}/, mail.body
55
- end
56
-
57
- test 'body should have link to confirm the account' do
58
- host = ActionMailer::Base.default_url_options[:host]
59
- invitation_url_regexp = %r{<a href=\"http://#{host}/users/invitation/accept\?invitation_token=#{user.invitation_token}">}
60
- assert_match invitation_url_regexp, mail.body
61
- end
62
- end