simple_auth 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,16 @@
1
1
  require 'rake'
2
- require 'spec/rake/spectask'
2
+
3
+ if ENV["TARGET"] == "rails3"
4
+ require 'rspec/core/rake_task'
5
+ Rspec::Core::RakeTask.new(:spec)
6
+ else
7
+ require 'spec/rake/spectask'
8
+ desc 'Run the specs'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ t.spec_opts = ['--colour --format specdoc --loadby mtime --reverse']
11
+ t.spec_files = FileList['spec/**/*_spec.rb']
12
+ end
13
+ end
3
14
 
4
15
  require 'jeweler'
5
16
  require File.dirname(__FILE__) + '/lib/simple_auth/version'
@@ -8,11 +19,6 @@ require File.dirname(__FILE__) + '/lib/simple_auth/version'
8
19
  desc 'Default: run specs.'
9
20
  task :default => :spec
10
21
 
11
- desc 'Run the specs'
12
- Spec::Rake::SpecTask.new(:spec) do |t|
13
- t.spec_opts = ['--colour --format specdoc --loadby mtime --reverse']
14
- t.spec_files = FileList['spec/**/*_spec.rb']
15
- end
16
22
 
17
23
  JEWEL = Jeweler::Tasks.new do |gem|
18
24
  gem.name = "simple_auth"
@@ -55,7 +55,14 @@ module SimpleAuth
55
55
 
56
56
  unless logged_in? && authorized?
57
57
  flash[:alert] = I18n.translate("simple_auth.sessions.need_to_be_logged")
58
- session[:return_to] = request.request_uri if request.get?
58
+
59
+ if request.respond_to?(:fullpath)
60
+ return_to = request.fullpath
61
+ else
62
+ return_to = request.request_uri
63
+ end
64
+
65
+ session[:return_to] = return_to if request.get?
59
66
  redirect_to path
60
67
  end
61
68
  end
@@ -2,7 +2,7 @@ module SimpleAuth
2
2
  module Version
3
3
  MAJOR = "0"
4
4
  MINOR = "1"
5
- PATCH = "6"
5
+ PATCH = "7"
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/simple_auth.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_auth}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nando Vieira"]
12
- s.date = %q{2010-04-09}
12
+ s.date = %q{2010-05-07}
13
13
  s.description = %q{When Authlogic & Devise are just too much.
14
14
  }
15
15
  s.email = %q{fnando.vieira@gmail.com}
@@ -35,6 +35,8 @@ Gem::Specification.new do |s|
35
35
  "simple_auth.gemspec",
36
36
  "spec/resources/controllers.rb",
37
37
  "spec/resources/user.rb",
38
+ "spec/resources/views/dashboard/index.erb",
39
+ "spec/resources/views/session/new.erb",
38
40
  "spec/schema.rb",
39
41
  "spec/simple_auth/action_controller_spec.rb",
40
42
  "spec/simple_auth/active_record_spec.rb",
@@ -1,7 +1,11 @@
1
1
  # Add routes
2
- ActionController::Routing::Routes.add_route "/:controller/:action/:id"
3
- ActionController::Routing::Routes.add_named_route :login, "/login", :controller => "session", :action => "new"
4
- ActionController::Routing::Routes.add_named_route :dashboard, "/dashboard", :controller => "dashboard", :action => "index"
2
+ if ENV["TARGET"] == "rails3"
3
+ # Rails.application.routes.add_route "/:controller/:action/:id"
4
+ else
5
+ ActionController::Routing::Routes.add_route "/:controller/:action/:id"
6
+ ActionController::Routing::Routes.add_named_route :login, "/login", :controller => "session", :action => "new"
7
+ ActionController::Routing::Routes.add_named_route :dashboard, "/dashboard", :controller => "dashboard", :action => "index"
8
+ end
5
9
 
6
10
  class SampleController < ActionController::Base
7
11
  end
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
- describe SimpleAuth::ActionController, :type => :controller do
3
+ describe DashboardController, :type => :controller do
4
4
  before do
5
5
  @user = User.create(
6
6
  :login => "johndoe",
@@ -11,11 +11,11 @@ describe SimpleAuth::ActionController, :type => :controller do
11
11
  end
12
12
 
13
13
  describe "require_logged_user" do
14
- controller_name :dashboard
15
-
16
14
  context "unlogged user" do
17
15
  before do
18
- DashboardController.filter_chain.pop if DashboardController.filter_chain.count > 1
16
+ if ENV["TARGET"] != "rails3"
17
+ DashboardController.filter_chain.pop if DashboardController.filter_chain.count > 1
18
+ end
19
19
  end
20
20
 
21
21
  context "return to" do
@@ -34,8 +34,8 @@ describe SimpleAuth::ActionController, :type => :controller do
34
34
  end
35
35
 
36
36
  it "should redirect when user is not authorized" do
37
- controller.should_receive(:logged_in?).and_return(true)
38
- controller.should_receive(:authorized?).and_return(false)
37
+ @controller.should_receive(:logged_in?).and_return(true)
38
+ @controller.should_receive(:authorized?).and_return(false)
39
39
 
40
40
  get :index
41
41
  response.should redirect_to("/login")
@@ -46,7 +46,12 @@ describe SimpleAuth::ActionController, :type => :controller do
46
46
  DashboardController.require_logged_user :to => {:controller => "session", :action => "new"}
47
47
 
48
48
  get :index
49
- response.should redirect_to("/session/new")
49
+
50
+ if ENV["TARGET"] == "rails3"
51
+ response.should redirect_to("/login")
52
+ else
53
+ response.should redirect_to("/session/new")
54
+ end
50
55
  end
51
56
 
52
57
  it "should be redirected [block]" do
@@ -75,29 +80,38 @@ describe SimpleAuth::ActionController, :type => :controller do
75
80
  end
76
81
  end
77
82
  end
83
+ end
78
84
 
85
+ describe SessionController, :type => :controller do
86
+ before do
87
+ @user = User.create(
88
+ :login => "johndoe",
89
+ :email => "john@doe.com",
90
+ :password => "test",
91
+ :password_confirmation => "test"
92
+ )
93
+ end
94
+
79
95
  describe "redirect_logged_users" do
80
- controller_name :session
81
-
82
96
  context "unlogged user" do
83
97
  before do
84
98
  get :new
85
99
  end
86
-
100
+
87
101
  it "should render page" do
88
102
  response.should render_template(:new)
89
103
  end
90
104
  end
91
-
105
+
92
106
  context "logged user" do
93
107
  before do
94
108
  session[:record_id] = @user.id
95
109
  get :new
96
110
  end
97
-
111
+
98
112
  it "should be redirected" do
99
113
  response.should redirect_to("/dashboard")
100
114
  end
101
115
  end
102
116
  end
103
- end
117
+ end
@@ -9,28 +9,28 @@ describe SimpleAuth::ActiveRecord do
9
9
  end
10
10
 
11
11
  it "should require password" do
12
- subject.should have(1).error_on(:password)
12
+ [subject.errors[:password]].flatten.should have(1).item
13
13
  end
14
14
 
15
15
  it "should require password to be at least 4-chars long" do
16
16
  subject.password = "123"
17
17
  subject.should_not be_valid
18
- subject.should have(1).error_on(:password)
18
+ [subject.errors[:password]].flatten.should have(1).item
19
19
  end
20
20
 
21
21
  it "should require password confirmation not to be empty" do
22
22
  subject.password_confirmation = ""
23
- subject.should have(1).error_on(:password_confirmation)
23
+ [subject.errors[:password_confirmation]].flatten.should have(1).item
24
24
  end
25
25
 
26
26
  it "should require password confirmation not to be nil" do
27
27
  subject.password_confirmation = nil
28
- subject.should have(1).error_on(:password_confirmation)
28
+ [subject.errors[:password_confirmation]].flatten.should have(1).item
29
29
  end
30
30
 
31
31
  it "should unset password after saving" do
32
32
  subject = User.new(:password => "test", :password_confirmation => "test")
33
- subject.save(false)
33
+ subject.save
34
34
  subject.password.should be_nil
35
35
  subject.password_confirmation.should be_nil
36
36
  end
@@ -47,7 +47,7 @@ describe SimpleAuth::ActiveRecord do
47
47
 
48
48
  it "should mark password as unchanged after saving" do
49
49
  subject = User.new(:password => "test", :password_confirmation => "test")
50
- subject.save(false)
50
+ subject.save
51
51
  subject.password_changed?.should be_false
52
52
  end
53
53
  end
@@ -75,13 +75,13 @@ describe SimpleAuth::ActiveRecord do
75
75
  it "should require password confirmation when it has changed" do
76
76
  subject.password = "newpass"
77
77
  subject.should_not be_valid
78
- subject.should have(1).error_on(:password_confirmation)
78
+ [subject.errors[:password_confirmation]].flatten.should have(1).item
79
79
  end
80
80
 
81
81
  it "should require password when it has changed to blank" do
82
82
  subject.password = nil
83
83
  subject.should_not be_valid
84
- subject.should have(1).error_on(:password)
84
+ [subject.errors[:password]].flatten.should have(1).item
85
85
  end
86
86
 
87
87
  it "should authenticate using email" do
@@ -1,6 +1,17 @@
1
1
  require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe SimpleAuth::Helper, :type => :helper do
4
+ if ENV["TARGET"] == "rails3"
5
+ attr_accessor :helper
6
+
7
+ before do
8
+ @helper = Object.new
9
+ @helper.class_eval { attr_accessor :output_buffer }
10
+ @helper.extend(SimpleAuth::Helper)
11
+ @helper.extend(ActionView::Helpers::CaptureHelper)
12
+ end
13
+ end
14
+
4
15
  it "should include module" do
5
16
  ApplicationController.included_modules.include?(SimpleAuth::Helper)
6
17
  end
@@ -11,7 +11,7 @@ describe SimpleAuth::Session do
11
11
 
12
12
  @session = Hash.new
13
13
  @controller = SampleController.new
14
- @controller.session = @session
14
+ @controller.stub!(:session).and_return(@session)
15
15
 
16
16
  SimpleAuth::Config.controller = @controller
17
17
  @user_session = SimpleAuth::Session.new(:credential => "johndoe", :password => "test")
data/spec/spec_helper.rb CHANGED
@@ -22,9 +22,20 @@ require File.dirname(__FILE__) + "/resources/user"
22
22
  require File.dirname(__FILE__) + "/resources/controllers"
23
23
 
24
24
  # Restore default configuration
25
- Spec::Runner.configure do |config|
26
- config.before :each do
27
- load File.dirname(__FILE__) + "/../lib/simple_auth/config.rb"
28
- SimpleAuth::Config.model = :user
25
+ if ENV["TARGET"] == "rails3"
26
+ Rspec.configure do |config|
27
+ config.before :each do
28
+ load File.dirname(__FILE__) + "/../lib/simple_auth/config.rb"
29
+ SimpleAuth::Config.model = :user
30
+ end
31
+ end
32
+
33
+ ActionController::Base.prepend_view_path File.dirname(__FILE__) + "/resources/views"
34
+ else
35
+ Spec::Runner.configure do |config|
36
+ config.before :each do
37
+ load File.dirname(__FILE__) + "/../lib/simple_auth/config.rb"
38
+ SimpleAuth::Config.model = :user
39
+ end
29
40
  end
30
41
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nando Vieira
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-09 00:00:00 -03:00
17
+ date: 2010-05-07 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -47,6 +47,8 @@ files:
47
47
  - simple_auth.gemspec
48
48
  - spec/resources/controllers.rb
49
49
  - spec/resources/user.rb
50
+ - spec/resources/views/dashboard/index.erb
51
+ - spec/resources/views/session/new.erb
50
52
  - spec/schema.rb
51
53
  - spec/simple_auth/action_controller_spec.rb
52
54
  - spec/simple_auth/active_record_spec.rb