devise_masquerade 0.0.4 → 0.0.5

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

Potentially problematic release.


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

data/Gemfile CHANGED
@@ -12,11 +12,16 @@ group :test do
12
12
  gem 'guard'
13
13
  gem 'guard-rspec'
14
14
  gem 'guard-bundler'
15
- gem 'capybara', '>= 0.4.0'
15
+ gem 'guard-cucumber'
16
16
  gem 'rspec-rails'
17
17
  gem 'shoulda'
18
18
  gem 'rb-fsevent'
19
19
  gem 'factory_girl_rails'
20
20
  gem 'database_cleaner'
21
+ gem 'cucumber'
22
+ gem 'cucumber-rails'
23
+ gem 'capybara'
24
+ gem 'capybara-webkit'
25
+ gem 'launchy'
21
26
  end
22
27
 
data/Guardfile CHANGED
@@ -8,6 +8,12 @@ guard 'rspec', :cli => '--format documentation', :version => 2, :all_after_pass
8
8
  watch('spec/spec_helper.rb') { "spec" }
9
9
  end
10
10
 
11
+ guard 'cucumber',:all_after_pass => false do
12
+ watch(%r{^features/.+\.feature$})
13
+ watch(%r{^features/support/.+$}) { 'features' }
14
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
15
+ end
16
+
11
17
  guard 'bundler' do
12
18
  watch('Gemfile')
13
19
  watch(/^.+\.gemspec/)
@@ -42,7 +42,7 @@ class Devise::MasqueradesController < DeviseController
42
42
  end
43
43
 
44
44
  def session_key
45
- "devise.masquerade.#{resource_name}"
45
+ "devise_masquerade_#{resource_name}".to_sym
46
46
  end
47
47
  end
48
48
 
@@ -0,0 +1,2 @@
1
+ require File.expand_path("../../spec/dummy/config/environment.rb", __FILE__)
2
+
@@ -0,0 +1,17 @@
1
+ Feature: Use back button for returning to the owner of the masquerade action.
2
+ In order to back to the owner user
3
+ As an masquerade user
4
+ I want to be able to press a simple button on the page
5
+
6
+ @devise
7
+ Scenario: Use back button
8
+ Given I logged in
9
+ And I have a user for masquerade
10
+
11
+ When I am on the users page
12
+ And I login as one user
13
+ Then I should be login as this user
14
+
15
+ When I press back masquerade button
16
+ Then I should be login as owner user
17
+
@@ -0,0 +1,11 @@
1
+ Given /^I logged in$/ do
2
+ @user = create(:user)
3
+
4
+ visit '/'
5
+
6
+ fill_in 'user[email]', :with => @user.email
7
+ fill_in 'user[password]', :with => 'password'
8
+
9
+ click_on 'Sign in'
10
+ end
11
+
@@ -0,0 +1,24 @@
1
+ Given /^I have a user for masquerade$/ do
2
+ @mask = create(:user)
3
+ end
4
+
5
+ When /^I am on the users page$/ do
6
+ visit '/'
7
+ end
8
+
9
+ When /^I login as one user$/ do
10
+ click_on "Login as"
11
+ end
12
+
13
+ Then /^I should be login as this user$/ do
14
+ find('.current_user').should have_content(@mask.email)
15
+ end
16
+
17
+ When /^I press back masquerade button$/ do
18
+ click_on "Back masquerade"
19
+ end
20
+
21
+ Then /^I should be login as owner user$/ do
22
+ find('.current_user').should have_content(@user.email)
23
+ end
24
+
@@ -0,0 +1,23 @@
1
+ require 'cucumber/rails'
2
+ require 'factory_girl'
3
+ require 'database_cleaner'
4
+
5
+ Dir[File.join(File.dirname(__FILE__), '..', '..', "spec/support/*.rb")].each {|f| require f}
6
+
7
+ ENV["RAILS_ENV"] = "test"
8
+
9
+ Capybara.default_selector = :css
10
+
11
+ ActionController::Base.allow_rescue = false
12
+
13
+ World(FactoryGirl::Syntax::Methods)
14
+
15
+ begin
16
+ DatabaseCleaner.strategy = :transaction
17
+ rescue NameError
18
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
19
+ end
20
+
21
+ Cucumber::Rails::Database.javascript_strategy = :truncation
22
+ Capybara.javascript_driver = :webkit
23
+
@@ -12,7 +12,15 @@ module DeviseMasquerade
12
12
 
13
13
  sign_in #{name} if #{name}
14
14
  end
15
+
16
+ def #{name}_masquerade?
17
+ session[:"devise_masquerade_#{name}"].present?
18
+ end
15
19
  METHODS
20
+
21
+ ActiveSupport.on_load(:action_controller) do
22
+ helper_method "#{name}_masquerade?"
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -6,8 +6,9 @@ module DeviseMasquerade
6
6
  send("#{scope}_masquerade_path", resource)
7
7
  end
8
8
 
9
- def back_masquerade_path
10
- back_masquerade_path
9
+ def back_masquerade_path(resource)
10
+ scope = Devise::Mapping.find_scope!(resource)
11
+ send("back_#{scope}_masquerade_index_path")
11
12
  end
12
13
  end
13
14
  end
@@ -15,6 +15,9 @@ module Devise
15
15
  def self.find_by_masquerade_key(key)
16
16
  id = Rails.cache.read("#{self.name.pluralize.downcase}:#{key}:masquerade")
17
17
 
18
+ # clean up the cached masquerade key value
19
+ Rails.cache.write("#{self.name.pluralize.downcase}:#{key}:masquerade", nil)
20
+
18
21
  self.find_by_id(id)
19
22
  end
20
23
  end
@@ -4,9 +4,11 @@ module ActionDispatch::Routing
4
4
  protected
5
5
 
6
6
  def devise_masquerade(mapping, controllers)
7
- resources :masquerade, :only => :show,
7
+ resources :masquerade,
8
+ :only => :show,
8
9
  :path => mapping.path_names[:masquerade],
9
10
  :controller => controllers[:masquerades] do
11
+
10
12
  get :back, :on => :collection
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseMasquerade
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
+ before_filter :authenticate_user!
4
5
  before_filter :masquerade_user!
5
6
  end
6
7
 
@@ -2,7 +2,7 @@ class DashboardController < ApplicationController
2
2
  before_filter :masquerade_user!
3
3
 
4
4
  def index
5
- render :text => "text to render"
5
+ @users = User.where("users.id != ?", current_user.id).all
6
6
  end
7
7
  end
8
8
 
@@ -0,0 +1,3 @@
1
+ <h1>Users</h1>
2
+
3
+ <%= render @users %>
@@ -1,14 +1,20 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
8
- </head>
9
- <body>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+ <% if signed_in? %>
11
+ <h1 class='current_user'><%= current_user.email %></h1>
10
12
 
11
- <%= yield %>
13
+ <% if user_masquerade? %>
14
+ <%= link_to "Back masquerade", back_masquerade_path(current_user) %>
15
+ <% end %>
16
+ <% end %>
12
17
 
13
- </body>
18
+ <%= yield %>
19
+ </body>
14
20
  </html>
@@ -0,0 +1,6 @@
1
+ <p>
2
+ <%= user.email %>
3
+
4
+ <%= link_to "Login as", masquerade_path(user) %>
5
+ </p>
6
+
File without changes
@@ -16,6 +16,7 @@ describe User do
16
16
  user.masquerade!
17
17
 
18
18
  Rails.cache.should_receive(:read).with("users:#{user.masquerade_key}:masquerade").and_return(user.id)
19
+ Rails.cache.should_receive(:write).with("users:#{user.masquerade_key}:masquerade", nil)
19
20
 
20
21
  new_user = User.find_by_masquerade_key(user.masquerade_key)
21
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_masquerade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-23 00:00:00.000000000 Z
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -76,7 +76,12 @@ files:
76
76
  - README.md
77
77
  - Rakefile
78
78
  - app/controllers/devise/masquerades_controller.rb
79
+ - config/environment.rb
79
80
  - devise_masquerade.gemspec
81
+ - features/back.feature
82
+ - features/step_definitions/auth_steps.rb
83
+ - features/step_definitions/back_steps.rb
84
+ - features/support/env.rb
80
85
  - lib/devise_masquerade.rb
81
86
  - lib/devise_masquerade/controllers/helpers.rb
82
87
  - lib/devise_masquerade/controllers/url_helpers.rb
@@ -91,7 +96,9 @@ files:
91
96
  - spec/dummy/app/controllers/dashboard_controller.rb
92
97
  - spec/dummy/app/helpers/application_helper.rb
93
98
  - spec/dummy/app/models/user.rb
99
+ - spec/dummy/app/views/dashboard/index.html.erb
94
100
  - spec/dummy/app/views/layouts/application.html.erb
101
+ - spec/dummy/app/views/users/_user.html.erb
95
102
  - spec/dummy/config.ru
96
103
  - spec/dummy/config/application.rb
97
104
  - spec/dummy/config/boot.rb
@@ -111,6 +118,7 @@ files:
111
118
  - spec/dummy/config/routes.rb
112
119
  - spec/dummy/db/migrate/20121119085620_devise_create_users.rb
113
120
  - spec/dummy/db/schema.rb
121
+ - spec/dummy/public/.empty
114
122
  - spec/dummy/script/rails
115
123
  - spec/models/user_spec.rb
116
124
  - spec/orm/active_record.rb
@@ -142,6 +150,10 @@ signing_key:
142
150
  specification_version: 3
143
151
  summary: use for login as functionallity on your admin users pages
144
152
  test_files:
153
+ - features/back.feature
154
+ - features/step_definitions/auth_steps.rb
155
+ - features/step_definitions/back_steps.rb
156
+ - features/support/env.rb
145
157
  - spec/controllers/dashboard_controller_spec.rb
146
158
  - spec/controllers/devise/masquerades_controller_spec.rb
147
159
  - spec/dummy/Rakefile
@@ -149,7 +161,9 @@ test_files:
149
161
  - spec/dummy/app/controllers/dashboard_controller.rb
150
162
  - spec/dummy/app/helpers/application_helper.rb
151
163
  - spec/dummy/app/models/user.rb
164
+ - spec/dummy/app/views/dashboard/index.html.erb
152
165
  - spec/dummy/app/views/layouts/application.html.erb
166
+ - spec/dummy/app/views/users/_user.html.erb
153
167
  - spec/dummy/config.ru
154
168
  - spec/dummy/config/application.rb
155
169
  - spec/dummy/config/boot.rb
@@ -169,6 +183,7 @@ test_files:
169
183
  - spec/dummy/config/routes.rb
170
184
  - spec/dummy/db/migrate/20121119085620_devise_create_users.rb
171
185
  - spec/dummy/db/schema.rb
186
+ - spec/dummy/public/.empty
172
187
  - spec/dummy/script/rails
173
188
  - spec/models/user_spec.rb
174
189
  - spec/orm/active_record.rb