end
def test_with_a_valid_api_token
- @user = User.generate_with_protected!
+ @user = User.generate!
@token = Token.create!(:user => @user, :action => 'api')
get "/news.xml?key=#{@token.value}"
end
def test_with_valid_username_password_http_authentication
- @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
+ @user = User.generate! do |user|
+ user.password = 'my_password'
+ end
get "/news.xml", nil, credentials(@user.login, 'my_password')
assert_response :unauthorized
end
def test_with_valid_token_http_authentication
- @user = User.generate_with_protected!
+ @user = User.generate!
@token = Token.create!(:user => @user, :action => 'api')
get "/news.xml", nil, credentials(@token.value, 'X')
module ObjectHelpers
- # TODO: Remove these three once everyone has ported their code to use the
- # new object_daddy version with protected attribute support
- def User.generate_with_protected(attributes={})
- User.generate(attributes)
- end
-
- def User.generate_with_protected!(attributes={})
- User.generate!(attributes)
- end
-
- def User.spawn_with_protected(attributes={})
- User.spawn(attributes)
- end
-
def User.add_to_project(user, project, roles)
roles = [roles] unless roles.is_a?(Array)
Member.create!(:principal => user, :project => project, :roles => roles)
end
def test_recipients_should_include_the_assigned_group_members
- group_member = User.generate_with_protected!
+ group_member = User.generate!
group = Group.generate!
group.users << group_member
context "Issue#recipients" do
setup do
@project = Project.find(1)
- @author = User.generate_with_protected!
- @assignee = User.generate_with_protected!
+ @author = User.generate!
+ @assignee = User.generate!
@issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author)
end
end
test 'object_daddy creation' do
- User.generate_with_protected!(:firstname => 'Testing connection')
- User.generate_with_protected!(:firstname => 'Testing connection')
+ User.generate!(:firstname => 'Testing connection')
+ User.generate!(:firstname => 'Testing connection')
assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'})
end
context "User#before_create" do
should "set the mail_notification to the default Setting" do
- @user1 = User.generate_with_protected!
+ @user1 = User.generate!
assert_equal 'only_my_events', @user1.mail_notification
with_settings :default_notification_option => 'all' do
- @user2 = User.generate_with_protected!
+ @user2 = User.generate!
assert_equal 'all', @user2.mail_notification
end
end
context "User#api_key" do
should "generate a new one if the user doesn't have one" do
- user = User.generate_with_protected!(:api_token => nil)
+ user = User.generate!(:api_token => nil)
assert_nil user.api_token
key = user.api_key
end
should "return the existing api token value" do
- user = User.generate_with_protected!
+ user = User.generate!
token = Token.create!(:action => 'api')
user.api_token = token
assert user.save
end
should "return nil if the key is found for an inactive user" do
- user = User.generate_with_protected!(:status => User::STATUS_LOCKED)
+ user = User.generate!
+ user.status = User::STATUS_LOCKED
token = Token.create!(:action => 'api')
user.api_token = token
user.save
end
should "return the user if the key is found for an active user" do
- user = User.generate_with_protected!(:status => User::STATUS_ACTIVE)
+ user = User.generate!
token = Token.create!(:action => 'api')
user.api_token = token
user.save
context "#change_password_allowed?" do
should "be allowed if no auth source is set" do
- user = User.generate_with_protected!
+ user = User.generate!
assert user.change_password_allowed?
end
should "delegate to the auth source" do
- user = User.generate_with_protected!
+ user = User.generate!
allowed_auth_source = AuthSource.generate!
def allowed_auth_source.allow_password_changes?; true; end
context "Issues" do
setup do
@project = Project.find(1)
- @author = User.generate_with_protected!
- @assignee = User.generate_with_protected!
+ @author = User.generate!
+ @assignee = User.generate!
@issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author)
end
end
should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do
- @user = User.generate_with_protected!(:mail_notification => 'only_my_events')
+ @user = User.generate!(:mail_notification => 'only_my_events')
Member.create!(:user => @user, :project => @project, :role_ids => [1])
assert ! @user.notify_about?(@issue)
end
end
should "be false for a user with :selected and is not the author or assignee" do
- @user = User.generate_with_protected!(:mail_notification => 'selected')
+ @user = User.generate!(:mail_notification => 'selected')
Member.create!(:user => @user, :project => @project, :role_ids => [1])
assert ! @user.notify_about?(@issue)
end