current_user 0.0.1
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/MIT-LICENSE +20 -0
- data/README.md +72 -0
- data/Rakefile +40 -0
- data/app/assets/stylesheets/current_user/application.css +13 -0
- data/app/controllers/current_user/application_controller.rb +4 -0
- data/app/controllers/current_user/sessions_controller.rb +44 -0
- data/app/helpers/current_user/application_helper.rb +4 -0
- data/app/views/current_user/sessions/new.html.erb +44 -0
- data/app/views/layouts/current_user/application.html.erb +12 -0
- data/config/initializers/extend_controllers.rb +1 -0
- data/config/routes.rb +6 -0
- data/lib/current_user.rb +32 -0
- data/lib/current_user/constants.rb +3 -0
- data/lib/current_user/controller/helpers.rb +40 -0
- data/lib/current_user/engine.rb +5 -0
- data/lib/current_user/version.rb +3 -0
- data/lib/generators/current_user/install_generator.rb +29 -0
- data/lib/generators/templates/README +14 -0
- data/lib/generators/templates/current_user.rb +13 -0
- data/lib/tasks/current_user_tasks.rake +13 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/my_protected_pages_controller.rb +7 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/my_protected_pages/show.html.erb +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +65 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/current_user/key +1 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/current_user.rb +13 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/users.yml +5 -0
- data/test/integration/login_test.rb +72 -0
- data/test/integration_test_helper.rb +19 -0
- data/test/test_helper.rb +17 -0
- metadata +191 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'integration_test_helper'
|
2
|
+
|
3
|
+
class LoginTest < ActionDispatch::IntegrationTest
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
test "unauthorized user sees the 401 error page" do
|
7
|
+
visit '/my_protected_page'
|
8
|
+
assert_user_sees_unauthorized_error
|
9
|
+
end
|
10
|
+
|
11
|
+
test "repeated successful login process" do
|
12
|
+
sign_in_as 'admin@my.app.com'
|
13
|
+
sign_in_as 'member@some.app.com'
|
14
|
+
end
|
15
|
+
|
16
|
+
test "sign in page does sign out" do
|
17
|
+
sign_in_as 'member@some.app.com'
|
18
|
+
visit sing_in_page_path
|
19
|
+
visit '/my_protected_page'
|
20
|
+
assert_user_sees_unauthorized_error
|
21
|
+
end
|
22
|
+
|
23
|
+
test "invalide key" do
|
24
|
+
invalid_key = '54321'
|
25
|
+
visit sing_in_page_path(invalid_key)
|
26
|
+
assert_user_sees_unauthorized_error
|
27
|
+
end
|
28
|
+
|
29
|
+
test "empty users table" do
|
30
|
+
::User.destroy_all
|
31
|
+
|
32
|
+
visit sing_in_page_path
|
33
|
+
|
34
|
+
assert page.has_content?("Your database doesn't contain users."),
|
35
|
+
'Show a message about an empty user table'
|
36
|
+
end
|
37
|
+
|
38
|
+
test "logout" do
|
39
|
+
sign_in_as "member@some.app.com"
|
40
|
+
visit 'current_user/sign_out'
|
41
|
+
|
42
|
+
visit '/my_protected_page'
|
43
|
+
assert_user_sees_unauthorized_error
|
44
|
+
end
|
45
|
+
|
46
|
+
test "helper methods in views" do end
|
47
|
+
test "all users in the application database are listed in the signin page" do end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def sing_in_page_path(key = '12345')
|
52
|
+
"/current_user/#{key}/sign_in"
|
53
|
+
end
|
54
|
+
|
55
|
+
def assert_user_sees_unauthorized_error
|
56
|
+
assert page.has_content?('Unauthorized'), 'Contains "unauthorized" message'
|
57
|
+
assert_equal 401, page.status_code, 'Responds with the unauthorized http status code'
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_user_sees_protected_page(identifier)
|
61
|
+
assert_equal 200, page.status_code, 'Root responds with the OK http status code'
|
62
|
+
assert page.has_content?("Welcome #{identifier}"), 'Contains the welcome message for the use'
|
63
|
+
end
|
64
|
+
|
65
|
+
def sign_in_as(identifier)
|
66
|
+
visit sing_in_page_path
|
67
|
+
assert_equal 200, page.status_code, 'Sign in responds with the OK http status code'
|
68
|
+
page.click_button identifier
|
69
|
+
assert_user_sees_protected_page identifier
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'capybara/rails'
|
3
|
+
require 'database_cleaner'
|
4
|
+
|
5
|
+
DatabaseCleaner.strategy = :truncation
|
6
|
+
|
7
|
+
class ActionDispatch::IntegrationTest
|
8
|
+
# Make the Capybara DSL available in all integration tests
|
9
|
+
include Capybara::DSL
|
10
|
+
|
11
|
+
# Stop ActiveRecord from wrapping tests in transactions
|
12
|
+
self.use_transactional_fixtures = false
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
DatabaseCleaner.clean # Truncate the database
|
16
|
+
Capybara.reset_sessions! # Forget the (simulated) browser state
|
17
|
+
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: current_user
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pavel Mitin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &80944150 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *80944150
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sqlite3
|
27
|
+
requirement: &80943930 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *80943930
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: capybara
|
38
|
+
requirement: &80943700 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *80943700
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: database_cleaner
|
49
|
+
requirement: &80943480 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *80943480
|
58
|
+
description: ! 'An authentication gem for the pre-production (mainly) phase of the
|
59
|
+
application lifecycle.
|
60
|
+
|
61
|
+
Provide a simple sign in page with a list of all users in the application.
|
62
|
+
|
63
|
+
Click on any user logins you to the application under the user.
|
64
|
+
|
65
|
+
'
|
66
|
+
email:
|
67
|
+
- mitin.pavel@gmail.com
|
68
|
+
executables: []
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files:
|
71
|
+
- README.md
|
72
|
+
files:
|
73
|
+
- app/assets/stylesheets/current_user/application.css
|
74
|
+
- app/views/layouts/current_user/application.html.erb
|
75
|
+
- app/views/current_user/sessions/new.html.erb
|
76
|
+
- app/controllers/current_user/application_controller.rb
|
77
|
+
- app/controllers/current_user/sessions_controller.rb
|
78
|
+
- app/helpers/current_user/application_helper.rb
|
79
|
+
- config/routes.rb
|
80
|
+
- config/initializers/extend_controllers.rb
|
81
|
+
- lib/current_user.rb
|
82
|
+
- lib/generators/current_user/install_generator.rb
|
83
|
+
- lib/generators/templates/current_user.rb
|
84
|
+
- lib/generators/templates/README
|
85
|
+
- lib/tasks/current_user_tasks.rake
|
86
|
+
- lib/current_user/version.rb
|
87
|
+
- lib/current_user/constants.rb
|
88
|
+
- lib/current_user/controller/helpers.rb
|
89
|
+
- lib/current_user/engine.rb
|
90
|
+
- MIT-LICENSE
|
91
|
+
- Rakefile
|
92
|
+
- README.md
|
93
|
+
- test/dummy/test/fixtures/users.yml
|
94
|
+
- test/dummy/config.ru
|
95
|
+
- test/dummy/app/models/user.rb
|
96
|
+
- test/dummy/app/assets/stylesheets/application.css
|
97
|
+
- test/dummy/app/assets/javascripts/application.js
|
98
|
+
- test/dummy/app/views/layouts/application.html.erb
|
99
|
+
- test/dummy/app/views/my_protected_pages/show.html.erb
|
100
|
+
- test/dummy/app/controllers/application_controller.rb
|
101
|
+
- test/dummy/app/controllers/my_protected_pages_controller.rb
|
102
|
+
- test/dummy/app/helpers/application_helper.rb
|
103
|
+
- test/dummy/config/environments/test.rb
|
104
|
+
- test/dummy/config/environments/production.rb
|
105
|
+
- test/dummy/config/environments/development.rb
|
106
|
+
- test/dummy/config/locales/en.yml
|
107
|
+
- test/dummy/config/application.rb
|
108
|
+
- test/dummy/config/boot.rb
|
109
|
+
- test/dummy/config/routes.rb
|
110
|
+
- test/dummy/config/environment.rb
|
111
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
112
|
+
- test/dummy/config/initializers/mime_types.rb
|
113
|
+
- test/dummy/config/initializers/current_user.rb
|
114
|
+
- test/dummy/config/initializers/secret_token.rb
|
115
|
+
- test/dummy/config/initializers/session_store.rb
|
116
|
+
- test/dummy/config/initializers/inflections.rb
|
117
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
118
|
+
- test/dummy/config/database.yml
|
119
|
+
- test/dummy/config/current_user/key
|
120
|
+
- test/dummy/Rakefile
|
121
|
+
- test/dummy/public/422.html
|
122
|
+
- test/dummy/public/500.html
|
123
|
+
- test/dummy/public/404.html
|
124
|
+
- test/dummy/public/favicon.ico
|
125
|
+
- test/dummy/README.rdoc
|
126
|
+
- test/dummy/script/rails
|
127
|
+
- test/integration_test_helper.rb
|
128
|
+
- test/integration/login_test.rb
|
129
|
+
- test/test_helper.rb
|
130
|
+
homepage: https://github.com/MitinPavel/current_user
|
131
|
+
licenses: []
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.8.6
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: Dev phase auth for Rails
|
154
|
+
test_files:
|
155
|
+
- test/dummy/test/fixtures/users.yml
|
156
|
+
- test/dummy/config.ru
|
157
|
+
- test/dummy/app/models/user.rb
|
158
|
+
- test/dummy/app/assets/stylesheets/application.css
|
159
|
+
- test/dummy/app/assets/javascripts/application.js
|
160
|
+
- test/dummy/app/views/layouts/application.html.erb
|
161
|
+
- test/dummy/app/views/my_protected_pages/show.html.erb
|
162
|
+
- test/dummy/app/controllers/application_controller.rb
|
163
|
+
- test/dummy/app/controllers/my_protected_pages_controller.rb
|
164
|
+
- test/dummy/app/helpers/application_helper.rb
|
165
|
+
- test/dummy/config/environments/test.rb
|
166
|
+
- test/dummy/config/environments/production.rb
|
167
|
+
- test/dummy/config/environments/development.rb
|
168
|
+
- test/dummy/config/locales/en.yml
|
169
|
+
- test/dummy/config/application.rb
|
170
|
+
- test/dummy/config/boot.rb
|
171
|
+
- test/dummy/config/routes.rb
|
172
|
+
- test/dummy/config/environment.rb
|
173
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
174
|
+
- test/dummy/config/initializers/mime_types.rb
|
175
|
+
- test/dummy/config/initializers/current_user.rb
|
176
|
+
- test/dummy/config/initializers/secret_token.rb
|
177
|
+
- test/dummy/config/initializers/session_store.rb
|
178
|
+
- test/dummy/config/initializers/inflections.rb
|
179
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
180
|
+
- test/dummy/config/database.yml
|
181
|
+
- test/dummy/config/current_user/key
|
182
|
+
- test/dummy/Rakefile
|
183
|
+
- test/dummy/public/422.html
|
184
|
+
- test/dummy/public/500.html
|
185
|
+
- test/dummy/public/404.html
|
186
|
+
- test/dummy/public/favicon.ico
|
187
|
+
- test/dummy/README.rdoc
|
188
|
+
- test/dummy/script/rails
|
189
|
+
- test/integration_test_helper.rb
|
190
|
+
- test/integration/login_test.rb
|
191
|
+
- test/test_helper.rb
|