clearance 1.0.0.rc7 → 1.0.0.rc8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of clearance might be problematic. Click here for more details.

Files changed (55) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +3 -3
  3. data/.travis.yml +0 -17
  4. data/Appraisals +2 -6
  5. data/Gemfile +16 -1
  6. data/Gemfile.lock +116 -107
  7. data/NEWS.md +7 -3
  8. data/README.md +195 -129
  9. data/Rakefile +5 -9
  10. data/app/views/layouts/application.html.erb +1 -1
  11. data/clearance.gemspec +20 -17
  12. data/config/locales/clearance.en.yml +2 -1
  13. data/config/routes.rb +2 -2
  14. data/features/add_migrations_to_project.feature +7 -37
  15. data/features/integration_with_rspec.feature +5 -4
  16. data/features/integration_with_test_unit.feature +11 -38
  17. data/features/step_definitions/configuration_steps.rb +94 -8
  18. data/features/step_definitions/gem_file_steps.rb +8 -0
  19. data/features/support/env.rb +7 -0
  20. data/lib/clearance/authorization.rb +16 -3
  21. data/lib/clearance/configuration.rb +2 -0
  22. data/lib/clearance/engine.rb +1 -1
  23. data/lib/clearance/session.rb +12 -11
  24. data/lib/clearance/testing.rb +0 -4
  25. data/lib/clearance/testing/application.rb +23 -24
  26. data/lib/clearance/testing/helpers.rb +1 -1
  27. data/lib/clearance/user.rb +17 -10
  28. data/lib/clearance/version.rb +1 -1
  29. data/lib/generators/clearance/specs/templates/{integration → features}/clearance/user_signs_out_spec.rb +0 -0
  30. data/lib/generators/clearance/specs/templates/{integration → features}/clearance/visitor_resets_password_spec.rb +24 -0
  31. data/lib/generators/clearance/specs/templates/{integration → features}/clearance/visitor_signs_in_spec.rb +0 -0
  32. data/lib/generators/clearance/specs/templates/{integration → features}/clearance/visitor_signs_up_spec.rb +8 -0
  33. data/lib/generators/clearance/specs/templates/{integration → features}/clearance/visitor_updates_password_spec.rb +0 -0
  34. data/lib/generators/clearance/specs/templates/support/features.rb +5 -0
  35. data/lib/generators/clearance/specs/templates/support/{integration → features}/clearance_helpers.rb +1 -1
  36. data/spec/clearance/session_spec.rb +27 -0
  37. data/spec/controllers/apis_controller_spec.rb +36 -0
  38. data/spec/controllers/passwords_controller_spec.rb +13 -11
  39. data/spec/controllers/sessions_controller_spec.rb +13 -27
  40. data/spec/controllers/users_controller_spec.rb +6 -2
  41. data/spec/factories.rb +5 -0
  42. data/spec/models/user_spec.rb +13 -19
  43. data/spec/support/clearance.rb +9 -0
  44. metadata +36 -218
  45. data/gemfiles/3.0.20.gemfile +0 -7
  46. data/gemfiles/3.0.20.gemfile.lock +0 -173
  47. data/gemfiles/3.1.11.gemfile +0 -7
  48. data/gemfiles/3.1.11.gemfile.lock +0 -183
  49. data/gemfiles/3.2.12.gemfile +0 -7
  50. data/gemfiles/3.2.12.gemfile.lock +0 -182
  51. data/gemfiles/3.2.13.rc2.gemfile +0 -7
  52. data/gemfiles/3.2.13.rc2.gemfile.lock +0 -182
  53. data/lib/clearance/password_strategies/fake.rb +0 -23
  54. data/lib/generators/clearance/specs/templates/support/integration.rb +0 -6
  55. data/lib/generators/clearance/specs/templates/support/integration/action_mailer_helpers.rb +0 -19
data/Rakefile CHANGED
@@ -12,21 +12,17 @@ require 'appraisal'
12
12
  require 'clearance/testing/application'
13
13
  Clearance::Testing::Application.load_tasks
14
14
 
15
- task :default do
16
- if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
17
- exec 'rake spec cucumber'
18
- else
19
- Rake::Task['appraise'].execute
20
- end
21
- end
15
+ desc 'Default'
16
+ task :default => [:all]
22
17
 
23
- task :appraise => ['appraisal:install'] do
18
+ desc 'Test the engine under all supported Rails versions'
19
+ task :all => ['appraisal:install'] do |t|
24
20
  exec 'rake appraisal spec cucumber'
25
21
  end
26
22
 
27
23
  RSpec::Core::RakeTask.new(:spec)
28
24
 
29
25
  Cucumber::Rake::Task.new(:cucumber) do |t|
30
- t.fork = true
26
+ t.fork = false
31
27
  t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
32
28
  end
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <%= javascript_include_tag :defaults %>
4
+ <%= javascript_include_tag 'application' %>
5
5
  <%= csrf_meta_tag %>
6
6
  </head>
7
7
  <body>
@@ -6,8 +6,24 @@ Gem::Specification.new do |s|
6
6
  s.name = %q{clearance}
7
7
  s.version = Clearance::VERSION
8
8
  s.authors = [
9
- 'Dan Croak', 'Mike Burns', 'Jason Morrison', 'Joe Ferris', 'Eugene Bolshakov',
10
- 'Nick Quaranto', 'Josh Nichols', 'Mike Breen', 'Jon Yurek', 'Chad Pytel'
9
+ 'Dan Croak',
10
+ 'Eugene Bolshakov',
11
+ 'Mike Burns',
12
+ 'Joe Ferris',
13
+ 'Nick Quaranto',
14
+ 'Josh Nichols',
15
+ 'Matt Jankowski',
16
+ 'Josh Clayton',
17
+ 'Gabe Berke-Williams',
18
+ 'Greg Lazarev',
19
+ 'Mike Breen',
20
+ 'Prem Sichanugrist',
21
+ 'Harlow Ward',
22
+ 'Ryan McGeary',
23
+ 'Derek Prior',
24
+ 'Jason Morrison',
25
+ 'Galen Frechette',
26
+ 'Josh Steiner'
11
27
  ]
12
28
  s.email = %q{support@thoughtbot.com}
13
29
  s.homepage = %q{http://github.com/thoughtbot/clearance}
@@ -23,19 +39,6 @@ Gem::Specification.new do |s|
23
39
  s.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
24
40
 
25
41
  s.add_dependency 'bcrypt-ruby'
26
- s.add_dependency 'email_validator'
27
- s.add_dependency 'rails', '>= 3.0'
28
- s.add_development_dependency 'appraisal', '0.4.1'
29
- s.add_development_dependency 'aruba', '0.4.11'
30
- s.add_development_dependency 'bourne', '1.3.0'
31
- s.add_development_dependency 'bundler', '~> 1.1'
32
- s.add_development_dependency 'capybara', '1.1.2'
33
- s.add_development_dependency 'cucumber-rails', '1.1.1'
34
- s.add_development_dependency 'database_cleaner', '0.8.0'
35
- s.add_development_dependency 'factory_girl_rails', '3.5.0'
36
- s.add_development_dependency 'psych', '~> 1.3.4'
37
- s.add_development_dependency 'rspec-rails', '2.12.2'
38
- s.add_development_dependency 'shoulda-matchers', '1.2.0'
39
- s.add_development_dependency 'sqlite3', '1.3.6'
40
- s.add_development_dependency 'timecop', '0.3.5'
42
+ s.add_dependency 'email_validator', '~> 1.4'
43
+ s.add_dependency 'rails', '>= 3.1'
41
44
  end
@@ -59,11 +59,12 @@ en:
59
59
  title:
60
60
  'Reset your password'
61
61
  sessions:
62
- new:
62
+ form:
63
63
  forgot_password:
64
64
  'Forgot password?'
65
65
  sign_up:
66
66
  'Sign up'
67
+ new:
67
68
  title:
68
69
  'Sign in'
69
70
  users:
@@ -5,11 +5,11 @@ Rails.application.routes.draw do
5
5
 
6
6
  resource :session,
7
7
  :controller => 'clearance/sessions',
8
- :only => [:create, :new, :destroy]
8
+ :only => [:create]
9
9
 
10
10
  resources :users,
11
11
  :controller => 'clearance/users',
12
- :only => [:create, :new] do
12
+ :only => [:create] do
13
13
  resource :password,
14
14
  :controller => 'clearance/passwords',
15
15
  :only => [:create, :edit, :update]
@@ -2,9 +2,9 @@ Feature: add migrations to the project
2
2
 
3
3
  Background:
4
4
  Given I have a project with clearance
5
- And I run `bundle install --local`
6
5
 
7
6
  Scenario: Users table does not exist
7
+ When I install dependencies
8
8
  And I successfully run `bundle exec rails generate clearance:install`
9
9
  And I successfully run `ls db/migrate`
10
10
  Then the output should contain:
@@ -13,20 +13,9 @@ Feature: add migrations to the project
13
13
  """
14
14
 
15
15
  Scenario: Users table without clearance fields exists in the database
16
- When I write to "db/migrate/001_create_users.rb" with:
17
- """
18
- class CreateUsers < ActiveRecord::Migration
19
- def self.up
20
- create_table(:users) do |t|
21
- t.string :email
22
- t.string :name
23
- end
24
- end
25
- def self.down
26
- end
27
- end
28
- """
29
- And I successfully run `bundle exec rake db:migrate --trace`
16
+ When I install dependencies
17
+ And I create a simple migration
18
+ And I successfully run `bundle exec rake db:migrate`
30
19
  And I successfully run `bundle exec rails generate clearance:install`
31
20
  And I successfully run `ls db/migrate`
32
21
  Then the output should contain:
@@ -35,28 +24,9 @@ Feature: add migrations to the project
35
24
  """
36
25
 
37
26
  Scenario: Users table with clearance fields exists in the database
38
- When I write to "db/migrate/001_create_users.rb" with:
39
- """
40
- class CreateUsers < ActiveRecord::Migration
41
- def self.up
42
- create_table :users do |t|
43
- t.timestamps :null => false
44
- t.string :email, :null => false
45
- t.string :encrypted_password, :limit => 128, :null => false
46
- t.string :confirmation_token, :limit => 128
47
- t.string :remember_token, :limit => 128, :null => false
48
- end
49
-
50
- add_index :users, :email
51
- add_index :users, :remember_token
52
- end
53
-
54
- def self.down
55
- drop_table :users
56
- end
57
- end
58
- """
59
- And I successfully run `bundle exec rake db:migrate --trace`
27
+ When I install dependencies
28
+ And I create a migration with clearance fields
29
+ And I successfully run `bundle exec rake db:migrate`
60
30
  And I successfully run `bundle exec rails generate clearance:install`
61
31
  And I successfully run `ls db/migrate`
62
32
  Then the output should not contain:
@@ -7,14 +7,15 @@ Feature: generate rspec integration tests with application
7
7
  | rspec-rails |
8
8
  | factory_girl_rails |
9
9
  | database_cleaner |
10
- And I run `bundle install --local`
11
- And I successfully run `bundle exec rails generate rspec:install`
12
- And I successfully run `bundle exec rails generate clearance:specs`
13
10
 
14
11
  Scenario: generate a Rails app, run the generators, and run the tests
12
+ When I install dependencies
13
+ And I successfully run `bundle exec rails generate rspec:install`
14
+ And I successfully run `bundle exec rails generate clearance:specs`
15
15
  And I successfully run `bundle exec rails generate clearance:install`
16
16
  Then the output should contain "Next steps"
17
- When I successfully run `bundle exec rake db:migrate --trace`
17
+ When I successfully run `bundle exec rake db:migrate`
18
+ And I successfully run `bundle exec rake db:test:prepare`
18
19
  And I successfully run `bundle exec rspec`
19
20
  Then the output should contain "Finished"
20
21
  And the output should not contain "Failed examples"
@@ -1,43 +1,16 @@
1
- Feature: integrate with test unit
1
+ Feature: integrate with test-unit
2
2
 
3
3
  Background:
4
- When I successfully run `bundle exec rails new testapp`
5
- And I cd to "testapp"
6
- And I remove the file "public/index.html"
7
- And I remove the file "app/views/layouts/application.html.erb"
8
- And I configure ActionMailer to use "localhost" as a host
9
- And I configure a root route
10
- And I add the "factory_girl_rails" gem
11
- And I run `bundle install --local`
4
+ Given I have a project with clearance and the following gems:
5
+ | gem |
6
+ | factory_girl_rails |
7
+ | cucumber-rails |
12
8
 
13
9
  Scenario: generate a Rails app, run the generators, and run the tests
14
- When I successfully run `bundle exec rails generate clearance:install`
15
- And I successfully run `bundle exec rake db:migrate --trace`
10
+ When I install dependencies
11
+ And I successfully run `bundle exec rails generate clearance:install`
12
+ And I successfully run `bundle exec rake db:migrate`
16
13
  And I successfully run `bundle exec rails generate controller posts index`
17
- And I add the "cucumber-rails" gem
18
- And I write to "test/test_helper.rb" with:
19
- """
20
- ENV['RAILS_ENV'] = 'test'
21
- require File.expand_path('../../config/environment', __FILE__)
22
- require 'rails/test_help'
23
-
24
- class ActiveSupport::TestCase
25
- fixtures :all
26
- end
27
-
28
- require 'clearance/testing'
29
- """
30
- And I write to "test/functionals/posts_controller_test.rb" with:
31
- """
32
- require 'test_helper'
33
-
34
- class PostsControllerTest < ActionController::TestCase
35
- test 'should get index' do
36
- sign_in
37
- get :index
38
- assert_response :success
39
- end
40
- end
41
- """
42
- And I successfully run `bundle exec rake --trace`
43
- Then the output should contain "1 tests, 1 assertions, 0 failures"
14
+ And I configure test-unit
15
+ And I successfully run `bundle exec rake`
16
+ Then the output should match /1 tests.+1 assertions/
@@ -1,20 +1,31 @@
1
+ When /^I install dependencies$/ do
2
+ step "I successfully run `bundle install --local`"
3
+ end
4
+
1
5
  When "I have a project with clearance and the following gems:" do |table|
2
6
  step "I have a project with clearance"
3
7
 
4
- table.map_column!('gem') do |gem|
5
- step %Q{ And I add the "#{gem}" gem }
8
+ table.rows.flatten.each do |gem|
9
+ step %Q{I add the "#{gem}" gem}
6
10
  end
7
11
  end
8
12
 
9
13
  When "I have a project with clearance" do
10
- step "I successfully run `bundle exec rails new testapp`"
14
+ Bundler.with_original_env do
15
+ step "I successfully run `bundle exec rails new testapp --skip-bundle --skip-javascript --skip-sprockets`"
16
+ end
17
+
18
+ step 'I cd to "testapp"'
19
+
20
+ unless Clearance::Testing.rails4?
21
+ step 'I remove the file "public/index.html"'
22
+ end
11
23
 
12
24
  steps %Q{
13
- And I cd to "testapp"
14
- And I remove the file "public/index.html"
15
25
  And I remove the file "app/views/layouts/application.html.erb"
16
26
  And I configure ActionMailer to use "localhost" as a host
17
27
  And I configure a root route
28
+ And I remove the "turn" gem from this project
18
29
  And I add the "clearance" gem from this project
19
30
  }
20
31
  end
@@ -49,8 +60,83 @@ When /^I configure a root route$/ do
49
60
  CONTROLLER
50
61
  end
51
62
 
52
- When /^I copy the locked Gemfile from this project$/ do
53
- in_current_dir do
54
- FileUtils.cp(File.join(PROJECT_ROOT, 'Gemfile.lock'), 'Gemfile.lock')
63
+ When /^I configure test-unit$/ do
64
+ factories_path = File.join(
65
+ 'lib', 'generators', 'clearance', 'specs', 'templates', 'factories',
66
+ 'clearance.rb'
67
+ )
68
+ steps %Q{
69
+ When I append to "test/test_helper.rb" with:
70
+ """
71
+ require 'clearance/testing'
72
+ """
73
+ And I overwrite "test/#{controller_test_dir}/posts_controller_test.rb" with:
74
+ """
75
+ require 'test_helper'
76
+
77
+ class PostsControllerTest < ActionController::TestCase
78
+ test 'should get index' do
79
+ sign_in
80
+ get :index
81
+ assert_response :success
82
+ end
83
+ end
84
+ """
85
+ And I write to "test/factories.rb" with:
86
+ """
87
+ #{File.read(factories_path)}
88
+ """
89
+ }
90
+ end
91
+
92
+ When /^I create a simple migration$/ do
93
+ steps %Q{
94
+ When I write to "db/migrate/001_create_users.rb" with:
95
+ """
96
+ class CreateUsers < ActiveRecord::Migration
97
+ def self.up
98
+ create_table(:users) do |t|
99
+ t.string :email
100
+ t.string :name
101
+ end
102
+ end
103
+ def self.down
104
+ end
105
+ end
106
+ """
107
+ }
108
+ end
109
+
110
+ When /^I create a migration with clearance fields$/ do
111
+ steps %Q{
112
+ When I write to "db/migrate/001_create_users.rb" with:
113
+ """
114
+ class CreateUsers < ActiveRecord::Migration
115
+ def self.up
116
+ create_table :users do |t|
117
+ t.timestamps :null => false
118
+ t.string :email, :null => false
119
+ t.string :encrypted_password, :limit => 128, :null => false
120
+ t.string :confirmation_token, :limit => 128
121
+ t.string :remember_token, :limit => 128, :null => false
122
+ end
123
+
124
+ add_index :users, :email
125
+ add_index :users, :remember_token
126
+ end
127
+
128
+ def self.down
129
+ drop_table :users
130
+ end
131
+ end
132
+ """
133
+ }
134
+ end
135
+
136
+ def controller_test_dir
137
+ if Clearance::Testing.rails4?
138
+ 'controllers'
139
+ else
140
+ 'functional'
55
141
  end
56
142
  end
@@ -5,3 +5,11 @@ end
5
5
  When /^I add the "([^"]*)" gem from this project$/ do |gem_name|
6
6
  append_to_file('Gemfile', %{\ngem "#{gem_name}", :path => "../../.."\n})
7
7
  end
8
+
9
+ When /^I remove the "([^"]*)" gem from this project$/ do |gem_name|
10
+ in_current_dir do
11
+ content = File.read('Gemfile')
12
+ content.gsub!(/^.*gem 'turn'.*\n/, '')
13
+ File.open('Gemfile', 'w') { |file| file.write(content) }
14
+ end
15
+ end
@@ -13,6 +13,7 @@ require 'clearance/testing/application'
13
13
  require 'cucumber/rails/action_controller'
14
14
  require 'cucumber/rails/application'
15
15
  require 'cucumber/rails/capybara'
16
+ require 'cucumber/rails/database'
16
17
  require 'cucumber/rails/hooks'
17
18
  require 'cucumber/rails/world'
18
19
 
@@ -26,3 +27,9 @@ begin
26
27
  rescue NameError
27
28
  raise 'You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it.'
28
29
  end
30
+
31
+ Around do |scenario, block|
32
+ Bundler.with_clean_env do
33
+ block.call
34
+ end
35
+ end
@@ -13,6 +13,15 @@ module Clearance
13
13
  end
14
14
 
15
15
  def deny_access(flash_message = nil)
16
+ respond_to do |format|
17
+ format.any(:js, :json, :xml) { head :unauthorized }
18
+ format.any { redirect_request(flash_message) }
19
+ end
20
+ end
21
+
22
+ protected
23
+
24
+ def redirect_request(flash_message)
16
25
  store_location
17
26
 
18
27
  if flash_message
@@ -26,8 +35,6 @@ module Clearance
26
35
  end
27
36
  end
28
37
 
29
- protected
30
-
31
38
  def clear_return_to
32
39
  session[:return_to] = nil
33
40
  end
@@ -44,7 +51,13 @@ module Clearance
44
51
  end
45
52
 
46
53
  def return_to
47
- session[:return_to] || params[:return_to]
54
+ if return_to_url
55
+ URI.parse(return_to_url).path
56
+ end
57
+ end
58
+
59
+ def return_to_url
60
+ session[:return_to]
48
61
  end
49
62
 
50
63
  def url_after_denied_access_when_signed_in