another set of dynamic finder migrations. All non-cucumber tests pass

This commit is contained in:
Reinier Balt 2013-02-27 11:50:49 +01:00
parent 64a198d45a
commit ef91dd0c64
18 changed files with 66 additions and 66 deletions

View file

@ -20,7 +20,7 @@ class LoginControllerTest < ActionController::TestCase
def test_login_with_valid_admin_user
@request.session['return-to'] = "/bogus/location"
post :login, {:user_login => 'admin', :user_password => 'abracadabra', :user_noexpiry => 'on'}
user = User.find_by_id(session['user_id'])
user = User.find(session['user_id'])
assert_not_nil user
assert_equal user.id, session['user_id']
assert_equal user.login, "admin"
@ -31,7 +31,7 @@ class LoginControllerTest < ActionController::TestCase
def test_login_with_valid_standard_user
post :login, {:user_login => 'jane', :user_password => 'sesame', :user_noexpiry => 'off'}
user = User.find_by_id(session['user_id'])
user = User.find(session['user_id'])
assert_not_nil user
assert_equal user.id, session['user_id']
assert_equal user.login, "jane"

View file

@ -74,7 +74,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
assert recurring_todo_1.completed?
# remove remaining todo
todo = Todo.find_by_recurring_todo_id(1)
todo = Todo.where(:recurring_todo_id => 1).first
todo.recurring_todo_id = 2
todo.save
@ -89,7 +89,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
assert_equal todo_count+1, Todo.count
# find the new todo and check its description
new_todo = Todo.find_by_recurring_todo_id 1
new_todo = Todo.where(:recurring_todo_id => 1).first
assert_equal "Call Bill Gates every day", new_todo.description
end
@ -113,7 +113,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
xhr :post, :toggle_check, :id=>5, :_source_view=>""
xhr :post, :toggle_check, :id=>5, :_source_view=>""
new_todo = Todo.find_by_recurring_todo_id 5
new_todo = Todo.where(:recurring_todo_id => 5).first
# due date should be the target_date
assert_equal users(:admin_user).at_midnight(Date.new(target_date.year, target_date.month, target_date.day)), new_todo.due
@ -171,7 +171,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
assert_equal orig_todo_count+1, Todo.count
# find the newly created todo
new_todo = Todo.find_by_description("new recurring pattern")
new_todo = Todo.where(:description => "new recurring pattern").first
assert !new_todo.nil?
# the date should be 31 march 2013
@ -224,7 +224,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
assert_equal orig_todo_count+1, Todo.count
# find the newly created recurring todo
recurring_todo = RecurringTodo.find_by_description("new recurring pattern")
recurring_todo = RecurringTodo.where(:description => "new recurring pattern").first
assert !recurring_todo.nil?
assert_equal "due_date", recurring_todo.target
@ -235,7 +235,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
login_as(:admin_user)
rt = RecurringTodo.find(recurring_todos(:call_bill_gates_every_day).id)
todo = Todo.find_by_recurring_todo_id(rt.id)
todo = Todo.where(:recurring_todo_id => rt.id).first
assert_not_nil todo
assert_equal "active", todo.state, "todo should be active"

View file

@ -114,7 +114,7 @@ class TodosControllerTest < ActionController::TestCase
def test_find_tagged_with
login_as(:admin_user)
@user = User.find(@request.session['user_id'])
tag = Tag.find_by_name('foo').taggings
tag = Tag.where(:name => 'foo').first.taggings
@tagged = tag.count
get :tag, :name => 'foo'
assert_response :success
@ -260,7 +260,7 @@ class TodosControllerTest < ActionController::TestCase
# find a,b,c and d
%w{a b c d}.each do |todo|
eval "@#{todo} = Todo.find_by_description('#{todo}')"
eval "@#{todo} = Todo.where(:description => '#{todo}').first"
eval "assert !@#{todo}.nil?, 'a todo with description \"#{todo}\" should just have been added'"
end
@ -275,7 +275,7 @@ class TodosControllerTest < ActionController::TestCase
def test_destroy_todo
login_as(:admin_user)
xhr :post, :destroy, :id => 1, :_source_view => 'todo'
todo = Todo.find_by_id(1)
todo = Todo.where(:id=>1).first
assert_nil todo
end
@ -551,7 +551,7 @@ class TodosControllerTest < ActionController::TestCase
"show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
"project_id"=>"1",
"notes"=>"test notes", "description"=>"test_mobile_create_action"}}
t = Todo.find_by_description("test_mobile_create_action")
t = Todo.where(:description => "test_mobile_create_action").first
assert_not_nil t
assert_equal 2, t.context_id
assert_equal 1, t.project_id
@ -590,7 +590,7 @@ class TodosControllerTest < ActionController::TestCase
# link todo_1 and recurring_todo_1
recurring_todo_1 = RecurringTodo.find(1)
todo_1 = Todo.find_by_recurring_todo_id(1)
todo_1 = Todo.where(:recurring_todo_id => 1).first
# mark todo_1 as complete by toggle_check
xhr :post, :toggle_check, :id => todo_1.id, :_source_view => 'todo'
@ -645,7 +645,7 @@ class TodosControllerTest < ActionController::TestCase
# link todo_1 and recurring_todo_1
recurring_todo_1 = RecurringTodo.find(1)
#set_user_to_current_time_zone(recurring_todo_1.user)
todo_1 = Todo.find_by_recurring_todo_id(1)
todo_1 = Todo.where(:recurring_todo_id => 1).first
today = Time.zone.now.at_midnight
# change recurrence pattern to monthly and set show_from to today
@ -694,7 +694,7 @@ class TodosControllerTest < ActionController::TestCase
login_as :admin_user
recurring_todo_1 = RecurringTodo.find(5)
@todo = Todo.find_by_recurring_todo_id(1)
@todo = Todo.where(:recurring_todo_id => 1).first
assert @todo.from_recurring_todo?
# rewire @todo to yearly recurring todo
@todo.recurring_todo_id = 5

View file

@ -26,14 +26,14 @@ class UsersControllerTest < ActionController::TestCase
User.per_page = 1
login_as :admin_user
get :index
assert_equal assigns['users'],[User.find_by_login('admin')]
assert_equal assigns['users'],[User.where(:login => 'admin').first]
end
def test_index_pagination_page_2
User.per_page = 1
login_as :admin_user
get :index, :page => 2
assert_equal assigns['users'],[User.find_by_login('jane')]
assert_equal assigns['users'],[User.where(:login => 'jane').first]
end
def test_destroy_user
@ -90,7 +90,7 @@ class UsersControllerTest < ActionController::TestCase
def test_create_adds_a_new_nonadmin_user
login_as :admin_user
post :create, :user => {:login => 'newbie', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
newbie = User.find_by_login('newbie')
newbie = User.where(:login => 'newbie').first
assert_equal newbie.login, "newbie"
assert newbie.is_admin == false || newbie.is_admin == 0
assert_not_nil newbie.preference # have user preferences been created?

View file

@ -39,7 +39,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
authenticated_post_xml_to_context_create
assert_response 201
end
context1 = Context.find_by_name(@@context_name)
context1 = Context.where(:name => @@context_name).first
assert_not_nil context1, "expected context '#{@@context_name}' to be created"
end

View file

@ -46,7 +46,7 @@ class ProjectXmlApiTest < ActionController::IntegrationTest
def test_fails_with_comma_in_name
authenticated_post_xml_to_project_create "<project><name>foo,bar</name></project>"
assert_response :created
project1 = Project.find_by_name("foo,bar")
project1 = Project.where(:name => "foo,bar").first
assert_not_nil project1, "expected project 'foo,bar' to be created"
end
@ -55,7 +55,7 @@ class ProjectXmlApiTest < ActionController::IntegrationTest
authenticated_post_xml_to_project_create
assert_response :created
end
project1 = Project.find_by_name(@@project_name)
project1 = Project.where(:name => @@project_name).first
assert_not_nil project1, "expected project '#{@@project_name}' to be created"
end

View file

@ -21,7 +21,7 @@ class RecurringTodosTest < ActionController::IntegrationTest
assert_equal 1, rt.todos.size # and it has one todo referencing it
# when I toggle the todo complete
todo = Todo.find_by_recurring_todo_id(1)
todo = Todo.where(:recurring_todo_id => 1).first
put "/todos/#{todo.id}/toggle_check", :_source_view => 'todo'
todo.reload
assert todo.completed?

View file

@ -59,7 +59,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 2.0")
todo = @user.todos.where(:description => "this will succeed 2.0").first
assert_not_nil todo
assert !todo.uncompleted_predecessors.empty?
end
@ -76,7 +76,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 2.1")
todo = @user.todos.where(:description => "this will succeed 2.1").first
assert_not_nil todo
assert !todo.uncompleted_predecessors.empty?
end
@ -95,7 +95,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 3")
todo = @user.todos.where(:description => "this will succeed 3").first
assert_not_nil todo
assert_equal "starred, starred1, starred2", todo.tag_list
assert todo.starred?
@ -113,7 +113,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 3.1")
todo = @user.todos.where(:description => "this will succeed 3.1").first
assert_not_nil todo
assert_equal "tracks", todo.tag_list
end
@ -133,7 +133,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 3")
todo = @user.todos.where(:description => "this will succeed 3").first
assert_not_nil todo
assert_equal "bar, bingo, foo", todo.tag_list
authenticated_post_xml_to_todo_create "
@ -149,7 +149,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 4")
todo = @user.todos.where(:description => "this will succeed 4").first
assert_not_nil todo
assert_equal "bar, bingo, foo", todo.tag_list
end
@ -165,7 +165,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 4")
todo = @user.todos.where(:description => "this will succeed 4").first
assert_not_nil todo
assert_not_nil todo.context
assert_equal todo.context.name, "@SomeNewContext"
@ -182,7 +182,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 4")
todo = @user.todos.where(:description => "this will succeed 4").first
assert_not_nil todo
assert_not_nil todo.context
assert_equal contexts(:office).name, todo.context.name
@ -200,7 +200,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 5")
todo = @user.todos.where(:description => "this will succeed 5").first
assert_not_nil todo
assert_not_nil todo.project
assert_equal todo.project.name, "Make even more money"
@ -217,7 +217,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 5")
todo = @user.todos.where(:description => "this will succeed 5").first
assert_not_nil todo
assert_not_nil todo.project
assert_equal projects(:timemachine).name, todo.project.name

View file

@ -56,7 +56,7 @@ class UsersXmlApiTest < ActionController::IntegrationTest
authenticated_post_xml_to_user_create @@johnny_postdata
assert_response_and_body 200, "User created."
end
johnny1 = User.find_by_login('johnny')
johnny1 = User.where(:login => 'johnny').first
assert_not_nil johnny1, "expected user johnny to be created"
johnny2 = User.authenticate('johnny','barracuda')
assert_not_nil johnny2, "expected user johnny to be authenticated"

View file

@ -4,39 +4,39 @@ class TagTest < ActiveSupport::TestCase
fixtures :tags
def test_find_or_create_with_single_word
tag = Tag.find_or_create_by_name("test")
tag = Tag.where(:name => "test").first_or_create
assert !tag.new_record?
end
def test_find_or_create_with_space
tag = Tag.find_or_create_by_name("test test")
tag = Tag.where(:name => "test test").first_or_create
assert !tag.new_record?
end
def test_find_or_create_with_dot
tag = Tag.find_or_create_by_name("a.b.c")
tag = Tag.where(:name => "a.b.c").first_or_create
assert !tag.new_record?
end
def test_find_or_create_with_number_as_string
tag = Tag.find_or_create_by_name("12343")
tag = Tag.where(:name => "12343").first_or_create
assert !tag.new_record?
tag = Tag.find_or_create_by_name("8.1.2")
tag = Tag.where(:name => "8.1.2").first_or_create
assert !tag.new_record?
end
def test_tag_name_always_lowercase
tag = Tag.find_or_create_by_name("UPPER")
tag = Tag.where(:name => "UPPER").first_or_create
assert !tag.new_record?
upper = Tag.find_by_name("upper")
upper = Tag.where(:name => "upper").first
assert_not_nil upper
assert upper.name == "upper"
end
def test_tag_name_stripped_of_spaces
tag = Tag.find_or_create_by_name(" strip spaces ")
tag = Tag.where(:name => " strip spaces ").first_or_create
assert !tag.new_record?
assert tag.name == "strip spaces"

View file

@ -11,6 +11,6 @@ class TaggingTest < ActiveSupport::TestCase
tagging.destroy
assert_nil Tag.find_by_name("hello")
assert_nil Tag.where(:name => "hello").first
end
end

View file

@ -276,9 +276,9 @@ class TodoTest < ActiveSupport::TestCase
todo.tag_list = "a, b, c"
todo.save!
tag_a = Tag.find_by_name("a")
tag_b = Tag.find_by_name("b")
tag_c = Tag.find_by_name("c")
tag_a = Tag.where(:name => "a").first
tag_b = Tag.where(:name => "b").first
tag_c = Tag.where(:name => "c").first
todos_with_a = Todo.with_tag(tag_a)
assert_equal 1, todos_with_a.count
@ -292,7 +292,7 @@ class TodoTest < ActiveSupport::TestCase
todo2.tag_list = "a, c, d"
todo2.save!
tag_d = Tag.find_by_name("d")
tag_d = Tag.where(:name => "d").first
todos_with_a = Todo.with_tag(tag_a)
assert_equal 2, todos_with_a.count
@ -310,10 +310,10 @@ class TodoTest < ActiveSupport::TestCase
todo2.tag_list = "a, c, d"
todo2.save!
tag_a = Tag.find_by_name("a")
tag_b = Tag.find_by_name("b")
tag_c = Tag.find_by_name("c")
tag_d = Tag.find_by_name("d")
tag_a = Tag.where(:name => "a").first
tag_b = Tag.where(:name => "b").first
tag_c = Tag.where(:name => "c").first
tag_d = Tag.where(:name => "d").first
# overlapping tags
tag_ids = [tag_a.id, tag_c.id]
@ -335,8 +335,8 @@ class TodoTest < ActiveSupport::TestCase
todo2.tag_list = "a, c, d"
todo2.save!
tag_a_id = Tag.find_by_name("a").id
tag_b_id = Tag.find_by_name("b").id
tag_a_id = Tag.where(:name => "a").first.id
tag_b_id = Tag.where(:name => "b").first.id
todos_with_a_and_b = Todo.with_tags([tag_a_id]).with_tags([tag_b_id])
assert_equal 1, todos_with_a_and_b.count
@ -352,9 +352,9 @@ class TodoTest < ActiveSupport::TestCase
todo2.tag_list = "a, c, d"
todo2.save!
tag_a_id = Tag.find_by_name("a").id
tag_b_id = Tag.find_by_name("b").id
tag_c_id = Tag.find_by_name("c").id
tag_a_id = Tag.where(:name => "a").first.id
tag_b_id = Tag.where(:name => "b").first.id
tag_c_id = Tag.where(:name => "c").first.id
todos_with_aORc_and_b = Todo.with_tags([tag_a_id, tag_c_id]).with_tags([tag_b_id])
assert_equal 1, todos_with_aORc_and_b.count