From 2e3bf71e9ad344e2e49c216cc080d13da37e4a96 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 22 Apr 2012 12:45:13 +0000 Subject: Removed #generate_with_protected helper methods. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9471 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../integration/api_test/disabled_rest_api_test.rb | 8 +++--- test/object_helpers.rb | 14 ----------- test/unit/issue_test.rb | 6 ++--- test/unit/query_test.rb | 4 +-- test/unit/user_test.rb | 29 +++++++++++----------- 5 files changed, 25 insertions(+), 36 deletions(-) diff --git a/test/integration/api_test/disabled_rest_api_test.rb b/test/integration/api_test/disabled_rest_api_test.rb index 5ec1f22b9..ab177015b 100644 --- a/test/integration/api_test/disabled_rest_api_test.rb +++ b/test/integration/api_test/disabled_rest_api_test.rb @@ -21,7 +21,7 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest 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}" @@ -34,7 +34,9 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest 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 @@ -46,7 +48,7 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest 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') diff --git a/test/object_helpers.rb b/test/object_helpers.rb index 3cd5e5cd6..eb2c87e67 100644 --- a/test/object_helpers.rb +++ b/test/object_helpers.rb @@ -1,18 +1,4 @@ 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) diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 77c2b2b73..64844edbb 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -725,7 +725,7 @@ class IssueTest < ActiveSupport::TestCase 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 @@ -1212,8 +1212,8 @@ class IssueTest < ActiveSupport::TestCase 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 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index a516c7a98..8a39d09a1 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -769,8 +769,8 @@ class QueryTest < ActiveSupport::TestCase end should "include users of subprojects" do - user1 = User.generate_with_protected! - user2 = User.generate_with_protected! + user1 = User.generate! + user2 = User.generate! project = Project.find(1) Member.create!(:principal => user1, :project => project.children.visible.first, :role_ids => [1]) @query.project = project diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index cbd3de5e9..6488bb07e 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -35,8 +35,8 @@ class UserTest < ActiveSupport::TestCase 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 @@ -88,11 +88,11 @@ class UserTest < ActiveSupport::TestCase 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 @@ -619,7 +619,7 @@ class UserTest < ActiveSupport::TestCase 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 @@ -629,7 +629,7 @@ class UserTest < ActiveSupport::TestCase 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 @@ -644,7 +644,8 @@ class UserTest < ActiveSupport::TestCase 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 @@ -653,7 +654,7 @@ class UserTest < ActiveSupport::TestCase 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 @@ -781,12 +782,12 @@ class UserTest < ActiveSupport::TestCase 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 @@ -898,8 +899,8 @@ class UserTest < ActiveSupport::TestCase 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 @@ -914,7 +915,7 @@ class UserTest < ActiveSupport::TestCase 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 @@ -960,7 +961,7 @@ class UserTest < ActiveSupport::TestCase 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 -- cgit v1.2.3