Skip to content

Commit

Permalink
Update DataMapper specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Zagarzazú committed Dec 27, 2013
1 parent 83bf646 commit 7145deb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/sorcery/test_helpers/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def custom_create_new_external_user(provider, authentication_class, attributes_h

user_attributes_hash = attributes_hash || {:username => 'gizmo'}
@user = User.new(user_attributes_hash)
@user.save!
@user.sorcery_save(:raise_on_failure => true)
@user.send(authentication_association).create!({:provider => provider, :uid => 123})
@user
end
Expand Down
4 changes: 2 additions & 2 deletions spec/datamapper/controller_activity_logging_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'

describe ApplicationController do
describe SorceryController do

# ----------------- ACTIVITY LOGGING -----------------------
describe ApplicationController, "with activity logging features" do
describe SorceryController, "with activity logging features" do
before(:all) do
sorcery_reload!([:activity_logging])
end
Expand Down
26 changes: 13 additions & 13 deletions spec/datamapper/controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'

describe ApplicationController do
describe SorceryController do

# ----------------- PLUGIN CONFIGURATION -----------------------
describe ApplicationController, "plugin configuration" do
describe SorceryController, "plugin configuration" do
before(:all) do
sorcery_reload!
end
Expand All @@ -26,7 +26,7 @@
end

# ----------------- PLUGIN ACTIVATED -----------------------
describe ApplicationController, "when activated with sorcery" do
describe SorceryController, "when activated with sorcery" do
before(:all) do
sorcery_reload!
User.delete_all
Expand Down Expand Up @@ -54,46 +54,46 @@
specify { should respond_to(:current_user) }

it "login(username,password) should return the user when success and set the session with user.id" do
get :test_login, :username => 'gizmo', :password => 'secret'
get :test_login, :email => 'bla@bla.com', :password => 'secret'
assigns[:user].should == @user
session[:user_id].should == @user.id
end

it "login(email,password) should return the user when success and set the session with user.id" do
get :test_login, :username => 'bla@bla.com', :password => 'secret'
get :test_login, :email => 'bla@bla.com', :password => 'secret'
assigns[:user].should == @user
session[:user_id].should == @user.id
end

it "login(username,password) should return nil and not set the session when failure" do
get :test_login, :username => 'gizmo', :password => 'opensesame!'
get :test_login, :email => 'bla@bla.com', :password => 'opensesame!'
assigns[:user].should be_nil
session[:user_id].should be_nil
end

it "login(username,password) should return nil and not set the session when upper case username" do
pending('DM creates tables in mysql case insensitive by default')
get :test_login, :username => 'GIZMO', :password => 'secret'
get :test_login, :email => 'BLA@BLA.com', :password => 'secret'
assigns[:user].should be_nil
session[:user_id].should be_nil
end

it "login(email,password) should return the user when success and set the session with the _csrf_token" do
get :test_login, :username => 'gizmo', :password => 'secret'
get :test_login, :email => 'bla@bla.com', :password => 'secret'
session[:_csrf_token].should_not be_nil
end

it "login(username,password) should return the user and set the session with user.id when upper case username and config is downcase before authenticating" do
sorcery_model_property_set(:downcase_username_before_authenticating, true)
get :test_login, :username => 'GIZMO', :password => 'secret'
get :test_login, :email => 'bla@bla.com', :password => 'secret'
assigns[:user].should == @user
session[:user_id].should == @user.id
end

it "login(username,password) should return nil and not set the session when user was created with upper case username, config is default, and log in username is lower case" do
pending('DM Adapter dependant')
create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
get :test_login, :username => 'gizmo1', :password => 'secret1'
create_new_user({:username => 'GIZMO1', :email => "BLA1@BLA.com", :password => 'secret1'})
get :test_login, :email => 'bla1@bla.com', :password => 'secret1'
assigns[:user].should be_nil
session[:user_id].should be_nil
end
Expand All @@ -102,7 +102,7 @@
pending('DM Adapter dependant')
sorcery_model_property_set(:downcase_username_before_authenticating, true)
create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
get :test_login, :username => 'gizmo1', :password => 'secret1'
get :test_login, :email => 'bla1@bla.com', :password => 'secret1'
assigns[:user].should == @user
session[:user_id].should == @user.id
end
Expand Down Expand Up @@ -156,7 +156,7 @@

it "require_login before_filter should save the url that the user originally wanted" do
get :some_action
session[:return_to_url].should == "http://test.host/application/some_action"
session[:return_to_url].should == "http://test.host/some_action"
response.should redirect_to("http://test.host/")
end

Expand Down
3 changes: 2 additions & 1 deletion spec/rails_app/app/datamapper/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class User
include DataMapper::Resource
property :id, Serial
property :username, String

has n, :authentications
has n, :authentications, :constraint => :destroy
end
8 changes: 4 additions & 4 deletions spec/shared_examples/user_activation_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
it "should call send_activation_needed_email! method of user" do
user = build_new_user
user.should_receive(:send_activation_needed_email!).once
user.save!
user.sorcery_save(:raise_on_failure => true)
end

it "subsequent saves do not send activation email" do
old_size = ActionMailer::Base.deliveries.size
@user.email = "Shauli"
@user.save!
@user.sorcery_save(:raise_on_failure => true)
ActionMailer::Base.deliveries.size.should == old_size
end

Expand All @@ -110,7 +110,7 @@
@user.activate!
old_size = ActionMailer::Base.deliveries.size
@user.email = "Shauli"
@user.save!
@user.sorcery_save(:raise_on_failure => true)
ActionMailer::Base.deliveries.size.should == old_size
end

Expand Down Expand Up @@ -143,7 +143,7 @@
it "should not call send_activation_needed_email! method of user" do
user = build_new_user
user.should_receive(:send_activation_needed_email!).never
user.save!
user.sorcery_save(:raise_on_failure => true)
end

it "should not send the user an activation success email on successful activation" do
Expand Down

0 comments on commit 7145deb

Please sign in to comment.