remove dynamic finders from cucumber scenarios

This commit is contained in:
Reinier Balt 2013-02-27 20:02:01 +01:00
parent 2b2572a2d1
commit 48e47fc009
20 changed files with 133 additions and 134 deletions

View file

@ -73,7 +73,7 @@ class RecurringTodosController < ApplicationController
# update context
if params['recurring_todo']['context_id'].blank? && !params['context_name'].blank?
context = current_user.contexts.where(:name => params['context_name'].strip)
context = current_user.contexts.where(:name => params['context_name'].strip).first
unless context
context = current_user.contexts.build
context.name = params['context_name'].strip

View file

@ -34,7 +34,7 @@ class TodosController < ApplicationController
end
if params[:tag]
tag = Tag.where(:name => params['tag'])
tag = Tag.where(:name => params['tag']).first
@not_done_todos = @not_done_todos.where('taggings.tag_id = ?', tag.id)
end
@ -103,8 +103,8 @@ class TodosController < ApplicationController
def create
@source_view = params['_source_view'] || 'todo'
@default_context = current_user.contexts.where(:name => params['default_context_name'])
@default_project = current_user.projects.where(:name => params['default_project_name']) unless params['default_project_name'].blank?
@default_context = current_user.contexts.where(:name => params['default_context_name']).first
@default_project = current_user.projects.where(:name => params['default_project_name']).first unless params['default_project_name'].blank?
@tag_name = params['_tag_name']
@ -719,7 +719,7 @@ class TodosController < ApplicationController
@source_view = params['_source_view'] || 'tag'
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
@page_title = t('todos.completed_tagged_page_title', :tag_name => @tag_name)
@tag = Tag.where(:name => @tag_name)
@tag = Tag.where(:name => @tag_name).first
@tag = Tag.new(:name => @tag_name) if @tag.nil?
completed_todos = current_user.todos.completed.with_tag(@tag.id)
@ -736,7 +736,7 @@ class TodosController < ApplicationController
@source_view = params['_source_view'] || 'tag'
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
@page_title = t('todos.all_completed_tagged_page_title', :tag_name => @tag_name)
@tag = Tag.where(:name => @tag_name)
@tag = Tag.where(:name => @tag_name).first
@tag = Tag.new(:name => @tag_name) if @tag.nil?
@done = current_user.todos.completed.with_tag(@tag.id).reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES).paginate :page => params[:page], :per_page => 20
@ -1017,7 +1017,7 @@ class TodosController < ApplicationController
end
from.tag do
@tag_name = params['_tag_name']
@tag = Tag.where(:name => @tag_name)
@tag = Tag.where(:name => @tag_name).first
if @tag.nil?
@tag = Tag.new(:name => @tag_name)
end
@ -1034,7 +1034,7 @@ class TodosController < ApplicationController
@target_context_count = current_user.contexts.find(@todo.context_id).todos.deferred_or_blocked.count
}
from.tag {
tag = Tag.where(:name => params['_tag_name'])
tag = Tag.where(:name => params['_tag_name']).first
if tag.nil?
tag = Tag.new(:name => params['tag'])
end
@ -1103,7 +1103,7 @@ class TodosController < ApplicationController
end
def determine_deferred_tag_count(tag_name)
tag = Tag.where(:name => tag_name)
tag = Tag.where(:name => tag_name).first
# tag.nil? should normally not happen, but is a workaround for #929
@remaining_deferred_or_pending_count = tag.nil? ? 0 : current_user.todos.deferred.with_tag(tag.id).count
end

View file

@ -124,7 +124,7 @@ Feature: dependencies
Then I should see an error flash message saying "Cannot add this action as a dependency to a completed action!"
And I should see "test 1" in project container for "dependencies"
@javascript
@javascript
Scenario Outline: Marking a successor as complete will update predecessor
Given I have a context called "@pc"
And I have a project "dependencies" that has the following todos

View file

@ -23,7 +23,7 @@ Feature: Manage users
Then I should be on the manage users page
And I should see "new.user"
@selenium
@javascript
Scenario: Delete account from users page
When I go to the manage users page
And I delete the user "testuser"

View file

@ -1,5 +1,5 @@
When /^I collapse the context container of "([^"]*)"$/ do |context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
xpath = "//a[@id='toggle_c#{context.id}']"
@ -15,7 +15,7 @@ end
####### Context #######
Then /^I should not see the context "([^"]*)"$/ do |context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
xpath = "//div[@id='c#{context.id}']"
@ -35,7 +35,7 @@ Then /^the container for the context "([^"]*)" should not be visible$/ do |conte
end
Then /^I should see the container for context "([^"]*)"$/ do |context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
xpath = "//div[@id='c#{context.id}']"
@ -47,9 +47,9 @@ Then /^the container for the context "([^"]*)" should be visible$/ do |context_n
end
Then /^I should see "([^"]*)" in the context container for "([^"]*)"$/ do |todo_description, context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id=\"c#{context.id}\"]//div[@id='line_todo_#{todo.id}']"
@ -57,9 +57,9 @@ Then /^I should see "([^"]*)" in the context container for "([^"]*)"$/ do |todo_
end
Then /^I should not see "([^"]*)" in the context container for "([^"]*)"$/ do |todo_description, context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id=\"c#{context.id}\"]//div[@id='line_todo_#{todo.id}']"
@ -69,21 +69,21 @@ end
####### Deferred #######
Then /^I should see "([^"]*)" in the deferred container$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
page.should have_xpath("//div[@id='tickler']//div[@id='line_todo_#{todo.id}']")
end
Then /^I should not see "([^"]*)" in the deferred container$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
page.should_not have_xpath("//div[@id='tickler']//div[@id='line_todo_#{todo.id}']")
end
Then /^I should (not see|see) "([^"]*)" in the action container$/ do |visible, todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
id = @source_view=="project" ? "p#{todo.project_id}items" : "c#{todo.context_id}items"
@ -99,10 +99,10 @@ end
####### Project #######
Then /^I should not see "([^"]*)" in the project container of "([^"]*)"$/ do |todo_description, project_name|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
xpath = "//div[@id='p#{todo.project.id}items']//div[@id='line_todo_#{todo.id}']"
@ -110,10 +110,10 @@ Then /^I should not see "([^"]*)" in the project container of "([^"]*)"$/ do |to
end
Then /^I should see "([^"]*)" in project container for "([^"]*)"$/ do |todo_description, project_name|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
xpath = "//div[@id='p#{project.id}items']//div[@id='line_todo_#{todo.id}']"
@ -123,7 +123,7 @@ end
####### Completed #######
Then /^I should see "([^"]*)" in the completed container$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='completed_container']//div[@id='line_todo_#{todo.id}']"
@ -131,7 +131,7 @@ Then /^I should see "([^"]*)" in the completed container$/ do |todo_description|
end
Then /^I should not see "([^"]*)" in the completed container$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='completed_container']//div[@id='line_todo_#{todo.id}']"
@ -141,7 +141,7 @@ end
####### Hidden #######
Then /^I should see "([^"]*)" in the hidden container$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='hidden']//div[@id='line_todo_#{todo.id}']"
@ -151,7 +151,7 @@ end
####### Calendar #######
Then /^I should see "([^"]*)" in the due next month container$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
within "div#due_after_this_month" do
@ -162,7 +162,7 @@ end
####### Repeat patterns #######
Then /^I should (see|not see) "([^"]*)" in the active recurring todos container$/ do |visibility, repeat_pattern|
repeat = @current_user.recurring_todos.find_by_description(repeat_pattern)
repeat = @current_user.recurring_todos.where(:description => repeat_pattern).first
unless repeat.nil?
xpath = "//div[@id='active_recurring_todos_container']//div[@id='recurring_todo_#{repeat.id}']"
@ -173,7 +173,7 @@ Then /^I should (see|not see) "([^"]*)" in the active recurring todos container$
end
Then /^I should not see "([^"]*)" in the completed recurring todos container$/ do |repeat_pattern|
repeat = @current_user.recurring_todos.find_by_description(repeat_pattern)
repeat = @current_user.todos.where(:description => repeat_pattern).first
unless repeat.nil?
xpath = "//div[@id='completed_recurring_todos_container']//div[@id='recurring_todo_#{repeat.id}']"
@ -181,5 +181,4 @@ Then /^I should not see "([^"]*)" in the completed recurring todos container$/ d
else
step "I should not see \"#{repeat_pattern}\""
end
end
end

View file

@ -1,5 +1,5 @@
When /^I delete the context "([^\"]*)"$/ do |context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
handle_js_confirm do
@ -44,7 +44,7 @@ When /^I add a new hidden context "([^"]*)"$/ do |context_name|
end
When /^I drag context "([^"]*)" above context "([^"]*)"$/ do |context_drag, context_drop|
drag_id = @current_user.contexts.find_by_name(context_drag).id
drag_id = @current_user.contexts.where(:name => context_drag).first.id
sortable_css = "div.ui-sortable div#container_context_#{drag_id}"
drag_index = context_list_find_index(context_drag)
@ -73,7 +73,7 @@ Then /^I should see that the context container for (.*) contexts is present$/ do
end
Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state|
context = Context.find_by_name(context_name)
context = Context.where(:name => context_name).first
context.should_not be_nil
page.has_css?("div#list-contexts-#{state} div#context_#{context.id}").should be_true

View file

@ -4,9 +4,9 @@ Given /^I have no contexts$/ do
end
Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
user = User.find_by_login(login)
user = User.where(:login => login).first
user.should_not be_nil
@context = user.contexts.find_or_create_by_name(:name => context_name, :hide => false)
@context = user.contexts.where(:name => context_name, :hide => false).first_or_create
end
Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
@ -14,7 +14,7 @@ Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context
end
Given /^there exists a hidden context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
user = User.find_by_login(login)
user = User.where(:login => login).first
user.should_not be_nil
@context = user.contexts.create!(:name => context_name, :hide => true)
end
@ -70,7 +70,7 @@ Then /^I should see the context name is "([^\"]*)"$/ do |context_name|
end
Then /^he should see that a context named "([^\"]*)" (is|is not) present$/ do |context_name, visible|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
if visible == "is"
context.should_not be_nil
css = "div#context_#{context.id} div.context_description a"

View file

@ -1,6 +1,6 @@
Given /^"([^"]*)" depends on "([^"]*)"$/ do |successor_name, predecessor_name|
successor = Todo.find_by_description(successor_name)
predecessor = Todo.find_by_description(predecessor_name)
successor = Todo.where(:description => successor_name).first
predecessor = Todo.where(:description => predecessor_name).first
successor.add_predecessor(predecessor)
successor.state = "pending"
@ -8,8 +8,8 @@ Given /^"([^"]*)" depends on "([^"]*)"$/ do |successor_name, predecessor_name|
end
When /^I drag "(.*)" to "(.*)"$/ do |dragged, target|
drag_id = Todo.find_by_description(dragged).id
drop_id = Todo.find_by_description(target).id
drag_id = Todo.where(:description => dragged).first.id
drop_id = Todo.where(:description => target).first.id
drag_elem = page.find(:xpath, "//div[@id='line_todo_#{drag_id}']//img[@class='grip']")
drop_elem = page.find(:xpath, "//div[@id='line_todo_#{drop_id}']")
@ -17,7 +17,7 @@ When /^I drag "(.*)" to "(.*)"$/ do |dragged, target|
end
When /^I expand the dependencies of "([^\"]*)"$/ do |todo_name|
todo = Todo.find_by_description(todo_name)
todo = Todo.where(:description=>todo_name).first
todo.should_not be_nil
expand_img_locator = "//div[@id='line_todo_#{todo.id}']/div/a[@class='show_successors']/img"
@ -27,9 +27,9 @@ When /^I expand the dependencies of "([^\"]*)"$/ do |todo_name|
end
When /^I edit the dependency of "([^"]*)" to add "([^"]*)" as predecessor$/ do |todo_description, predecessor_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
predecessor = @current_user.todos.find_by_description(predecessor_description)
predecessor = @current_user.todos.where(:description => predecessor_description).first
predecessor.should_not be_nil
open_edit_form_for(todo)
@ -55,9 +55,9 @@ When /^I edit the dependency of "([^"]*)" to add "([^"]*)" as predecessor$/ do |
end
When /^I edit the dependency of "([^"]*)" to remove "([^"]*)" as predecessor$/ do |todo_description, predecessor_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
predecessor = @current_user.todos.find_by_description(predecessor_description)
predecessor = @current_user.todos.where(:description => predecessor_description).first
predecessor.should_not be_nil
open_edit_form_for(todo)
@ -73,7 +73,7 @@ When /^I edit the dependency of "([^"]*)" to remove "([^"]*)" as predecessor$/ d
end
When /^I edit the dependency of "([^"]*)" to "([^"]*)"$/ do |todo_name, deps|
todo = @dep_todo = @current_user.todos.find_by_description(todo_name)
todo = @dep_todo = @current_user.todos.where(:description => todo_name).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -82,19 +82,19 @@ When /^I edit the dependency of "([^"]*)" to "([^"]*)"$/ do |todo_name, deps|
end
Then /^the successors of "(.*)" should include "(.*)"$/ do |parent_name, child_name|
parent = @current_user.todos.find_by_description(parent_name)
parent = @current_user.todos.where(:description => parent_name).first
parent.should_not be_nil
# wait until the successor is added. TODO: make this not loop indefinitly
wait_until do
found = !parent.pending_successors.find_by_description(child_name).nil?
found = !parent.pending_successors.where(:description => child_name).first.nil?
sleep 0.2 unless found
found
end
end
Then /^I should see "([^\"]*)" within the dependencies of "([^\"]*)"$/ do |successor_description, todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
# open successors
@ -108,14 +108,14 @@ Then /^I should see "([^\"]*)" within the dependencies of "([^\"]*)"$/ do |succe
end
Then /^I should not see "([^"]*)" within the dependencies of "([^"]*)"$/ do |successor_description, todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
step "I should not see \"#{successor_description}\" within \"div#line_todo_#{todo.id}\""
end
Then /^I should see that "([^"]*)" does not have dependencies$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
dependencies_icon = "//div[@id='line_todo_#{todo.id}']/div/a[@class='show_successors']/img"
page.should_not have_xpath(dependencies_icon)

View file

@ -9,7 +9,7 @@ end
Then /^I should see a script "([^\"]*)" for "([^\"]*)"$/ do |script, context_name|
page.should have_css("##{script}", :visible => true)
context = Context.find_by_name(context_name)
context = Context.where(:name => context_name).first
page.should have_content("#{context.id} (* #{context_name} *)")

View file

@ -7,7 +7,7 @@ Given /^I have logged in as "(.*)" with password "(.*)"$/ do |username, password
logout_regexp = @mobile_interface ? "Logout" : "Logout \(#{username}\)"
page.should have_content(logout_regexp)
@current_user = User.find_by_login(username)
@current_user = User.where(:login => username).first
end
When /^I submit the login form as user "([^\"]*)" with password "([^\"]*)"$/ do |username, password|

View file

@ -1,5 +1,5 @@
When /^I add note "([^\"]*)" from the "([^\"]*)" project page$/ do |note, project|
project = Project.find_by_name(project)
project = Project.where(:name => project).first
project.notes.create!(:user_id => @current_user.id, :body => note)
end
@ -31,7 +31,7 @@ When /^I edit the first note to "([^"]*)"$/ do |note_body|
end
When /^I toggle the note of "([^"]*)"$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='line_todo_#{todo.id}']/div/a/img"
@ -54,7 +54,7 @@ Then /^(.*) notes should be visible$/ do |number|
end
Then /^I should see note "([^\"]*)" on the "([^\"]*)" project page$/ do |note, project|
project = Project.find_by_name(project)
project = Project.where(:name => project).first
visit project_path(project)
step "I should see the note \"#{note}\""
end

View file

@ -1,5 +1,5 @@
When /^I delete project "([^"]*)"$/ do |project_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
handle_js_confirm do
@ -13,7 +13,7 @@ When /^I delete project "([^"]*)"$/ do |project_name|
end
When /^I drag the project "([^"]*)" below "([^"]*)"$/ do |project_drag, project_drop|
drag_id = @current_user.projects.find_by_name(project_drag).id
drag_id = @current_user.projects.where(:name => project_drag).first.id
sortable_css = "div.ui-sortable div#container_project_#{drag_id}"
drag_index = project_list_find_index(project_drag)
@ -78,7 +78,7 @@ Then /^the project "([^"]*)" should be above the project "([^"]*)"$/ do |project
end
Then /^the project "([^"]*)" should not be in state list "([^"]*)"$/ do |project_name, state_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
list_id = @source_view=="review" ? "list-#{state}-projects" : "list-#{state_name}-projects-container"
@ -88,7 +88,7 @@ Then /^the project "([^"]*)" should not be in state list "([^"]*)"$/ do |project
end
Then /^the project "([^"]*)" should be in state list "([^"]*)"$/ do |project_name, state_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
list_id = @source_view=="review" ? "list-#{state_name}-projects" : "list-#{state_name}-projects-container"
@ -113,15 +113,15 @@ Then /^the new project form should not be visible$/ do
page.should_not have_css("div#project_new", :visible => true)
end
Then /^the project "([^"]*)" should have (\d+) actions listed$/ do |name, count|
project = @current_user.projects.find_by_name(name)
Then /^the project "([^"]*)" should have (\d+) actions listed$/ do |project_name, count|
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
xpath = "//div[@id='list-active-projects-container']//div[@id='project_#{project.id}']//span[@class='needsreview']"
page.find(:xpath, xpath).text.should == "#{project.name} (#{count} actions)"
end
Then /^the project "([^"]*)" should have (\d+) deferred actions listed$/ do |name, deferred|
project = @current_user.projects.find_by_name(name)
Then /^the project "([^"]*)" should have (\d+) deferred actions listed$/ do |project_name, deferred|
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
xpath = "//div[@id='list-active-projects-container']//div[@id='project_#{project.id}']//span[@class='needsreview']"
page.find(:xpath, xpath).text.should == "#{project.name} (#{deferred} deferred actions)"

View file

@ -4,7 +4,7 @@ end
Given /^I have an outdated project "([^"]*)" with (\d+) todos$/ do |project_name, num_todos|
step "I have a project \"#{project_name}\" with #{num_todos} todos"
@project = @current_user.projects.find_by_name(project_name)
@project = @current_user.projects.where(:name => project_name).first
@project.last_reviewed = @current_user.time - @current_user.prefs.review_period.days-1
@project.save
end
@ -19,8 +19,8 @@ Given /^I have a project "([^"]*)" with (\d+) active actions and (\d+) deferred
end
Given /^I have a project "([^"]*)" with (\d+) (todo|active todo|deferred todo)s prefixed by "([^\"]*)"$/ do |project_name, num_todos, state, prefix|
@context = @current_user.contexts.find_or_create_by_name("Context A")
@project = @current_user.projects.find_or_create_by_name(project_name)
@context = @current_user.contexts.where(:name => "Context A").first_or_create
@project = @current_user.projects.where(:name => project_name).first_or_create
# acts_as_list adds at top by default, but that is counter-intuitive when reading scenario's, so reverse this
@project.move_to_bottom
@ -41,7 +41,7 @@ Given /^I have a project "([^"]*)" with (\d+) (todos|active todos|deferred todos
end
Given /^there exists a project (?:|called )"([^"]*)" for user "([^"]*)"$/ do |project_name, user_name|
user = User.find_by_login(user_name)
user = User.where(:login => user_name).first
user.should_not be_nil
@project = user.projects.create!(:name => project_name)
# acts_as_list adds at top by default, but that is counter-intuitive when reading scenario's, so reverse this
@ -101,7 +101,7 @@ Given /^I have a project "([^\"]*)" with (.*) notes?$/ do |project_name, num|
end
Given /^the default tags for "(.*?)" are "(.*?)"$/ do |project_name, default_tags|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
project.default_tags = default_tags
@ -146,13 +146,13 @@ When /^I edit the default context to "([^"]*)"$/ do |default_context|
end
When /^I edit the project name of "([^"]*)" to "([^"]*)"$/ do |project_current_name, project_new_name|
@project = @current_user.projects.find_by_name(project_current_name)
@project = @current_user.projects.where(:name => project_current_name).first
@project.should_not be_nil
step "I edit the project name to \"#{project_new_name}\""
end
When /^I try to edit the project name of "([^"]*)" to "([^"]*)"$/ do |project_current_name, project_new_name|
@project = @current_user.projects.find_by_name(project_current_name)
@project = @current_user.projects.where(:name => project_current_name).first
@project.should_not be_nil
step "I try to edit the project name to \"#{project_new_name}\""
end
@ -182,7 +182,7 @@ When /^I close the project settings$/ do
end
When /^I edit the project state of "([^"]*)" to "([^"]*)"$/ do |project_name, state_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
edit_project_settings(project) do
@ -191,7 +191,7 @@ When /^I edit the project state of "([^"]*)" to "([^"]*)"$/ do |project_name, st
end
When /^I edit project "([^"]*)" and mark the project as reviewed$/ do |project_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
open_project_edit_form(project)
@ -318,12 +318,12 @@ Then /^I should (see|not see) the default project settings$/ do |visible|
end
Then /^I should have a project called "([^"]*)"$/ do |project_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
end
Then /^I should have (\d+) todo in project "([^"]*)"$/ do |todo_count, project_name|
project = @current_user.projects.find_by_name(project_name)
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
project.todos.count.should == todo_count.to_i
end

View file

@ -38,7 +38,7 @@ When /^I select "([^\"]*)" recurrence pattern$/ do |recurrence_period|
end
When /^I edit the name of the pattern "([^\"]*)" to "([^\"]*)"$/ do |pattern_name, new_name|
pattern = @current_user.recurring_todos.find_by_description(pattern_name)
pattern = @current_user.recurring_todos.where(:description => pattern_name).first
pattern.should_not be_nil
click_link "link_edit_recurring_todo_#{pattern.id}"
@ -51,13 +51,13 @@ When /^I edit the name of the pattern "([^\"]*)" to "([^\"]*)"$/ do |pattern_nam
end
When /^I star the pattern "([^\"]*)"$/ do |pattern_name|
pattern = @current_user.recurring_todos.find_by_description(pattern_name)
pattern = @current_user.recurring_todos.where(:description => pattern_name).first
pattern.should_not be_nil
click_link "star_icon_#{pattern.id}"
end
When /^I delete the pattern "([^"]*)"$/ do |pattern_name|
pattern = @current_user.recurring_todos.find_by_description(pattern_name)
pattern = @current_user.recurring_todos.where(:description => pattern_name).first
pattern.should_not be_nil
handle_js_confirm do
@ -69,7 +69,7 @@ When /^I delete the pattern "([^"]*)"$/ do |pattern_name|
end
When /^I mark the pattern "([^"]*)" as (complete|active)$/ do |pattern_name, state|
pattern = @current_user.recurring_todos.find_by_description(pattern_name)
pattern = @current_user.recurring_todos.where(:description => pattern_name).first
pattern.should_not be_nil
pattern.completed?.should(state=="complete" ? be_false : be_true)
page.find("#check_#{pattern.id}").click
@ -78,7 +78,7 @@ When /^I mark the pattern "([^"]*)" as (complete|active)$/ do |pattern_name, sta
end
When /^I follow the recurring todo link of "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
page.find(:xpath, "//div[@id='todo_#{todo.id}']//a[@class='recurring_icon']/img").click
@ -93,7 +93,7 @@ Then /^the state list "([^"]*)" should be empty$/ do |state|
end
Then /^the pattern "([^\"]*)" should be starred$/ do |pattern_name|
pattern = @current_user.recurring_todos.find_by_description(pattern_name)
pattern = @current_user.recurring_todos.where(:description => pattern_name).first
pattern.should_not be_nil
page.should have_xpath("//div[@id='recurring_todo_#{pattern.id}']//img[@class='todo_star starred']")
end
@ -103,7 +103,7 @@ Then /^I should see the form for "([^\"]*)" recurrence pattern$/ do |recurrence_
end
Then /^the pattern "([^"]*)" should be in the state list "([^"]*)"$/ do |pattern_name, state_name|
pattern = @current_user.recurring_todos.find_by_description(pattern_name)
pattern = @current_user.recurring_todos.where(:description => pattern_name).first
pattern.should_not be_nil
page.should have_xpath("//div[@id='#{state_name}_recurring_todos_container']//div[@id='recurring_todo_#{pattern.id}']")
end

View file

@ -3,7 +3,7 @@ Given /^I have no todos$/ do
end
Given /^I have a todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
context = @current_user.contexts.find_or_create_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first_or_create
@todo = @current_user.todos.create!(:context_id => context.id, :description => description)
end
@ -14,17 +14,17 @@ Given /^I have a todo "([^"]*)" in context "([^"]*)" with tags "([^"]*)"$/ do |d
end
Given /^I have a todo "([^"]*)" in the context "([^"]*)" which is due tomorrow$/ do |description, context_name|
context = @current_user.contexts.find_or_create_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first_or_create
@todo = @current_user.todos.create!(:context_id => context.id, :description => description)
@todo.due = @todo.created_at + 1.day
@todo.save!
end
Given /^I have (\d+) todos in project "([^"]*)" in context "([^"]*)" with tags "([^"]*)" prefixed by "([^"]*)"$/ do |number_of_todos, project_name, context_name, tag_names, prefix|
@context = @current_user.contexts.find_by_name(context_name)
@context = @current_user.contexts.where(:name => context_name).first
@context.should_not be_nil
@project = @current_user.projects.find_by_name(project_name)
@project = @current_user.projects.where(:name => project_name).first
@project.should_not be_nil
@todos = []
@ -63,8 +63,8 @@ Given /^I have ([0-9]+) todos$/ do |count|
end
Given /^I have a todo with description "([^"]*)" in project "([^"]*)" with tags "([^"]*)" in the context "([^"]*)"$/ do |action_description, project_name, tags, context_name|
context = @current_user.contexts.find_or_create_by_name(context_name)
project = @current_user.projects.find_or_create_by_name(project_name)
context = @current_user.contexts.where(:name => context_name).first_or_create
project = @current_user.projects.where(:name => project_name).first_or_create
@todo = @current_user.todos.create!(:context_id => context.id, :project_id => project.id, :description => action_description)
@todo.tag_with(tags)
@todo.save
@ -88,7 +88,7 @@ Given /^I have ([0-9]+) deferred todos$/ do |count|
end
Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
context = @current_user.contexts.find_or_create_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first_or_create
todo = @current_user.todos.create!(:context_id => context.id, :description => description)
todo.show_from = @current_user.time + 1.week
todo.save!
@ -107,10 +107,10 @@ end
####### COMPLETED TODOS #######
Given /^I have ([0-9]+) completed todos in project "([^"]*)" in context "([^"]*)"$/ do |count, project_name, context_name|
@context = @current_user.contexts.find_by_name(context_name)
@context = @current_user.contexts.where(:name => context_name).first
@context.should_not be_nil
@project = @current_user.projects.find_by_name(project_name)
@project = @current_user.projects.where(:name => project_name).first
@project.should_not be_nil
@todos = []
@ -133,7 +133,7 @@ Given /^I have (\d+) completed todos in project "([^"]*)" in context "([^"]*)" w
end
Given /^I have ([0-9]+) completed todos in context "([^"]*)"$/ do |count, context_name|
context = @current_user.contexts.find_by_name(context_name)
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
count.to_i.downto 1 do |i|
@ -168,7 +168,7 @@ Given /^I have a project "([^"]*)" that has the following (todos|deferred todos)
step "I have a project called \"#{project_name}\""
@project.should_not be_nil
todos.hashes.each do |todo|
context = @current_user.contexts.find_by_name(todo[:context])
context = @current_user.contexts.where(:name => todo[:context]).first
context.should_not be_nil
new_todo = @current_user.todos.create!(
:description => todo[:description],
@ -195,7 +195,7 @@ When /^I submit a new action with description "([^"]*)"$/ do |description|
end
When /^I submit a new action with description "([^"]*)" with a dependency on "([^"]*)"$/ do |todo_description, predecessor_description|
predecessor = @current_user.todos.find_by_description(predecessor_description)
predecessor = @current_user.todos.where(:description => predecessor_description).first
predecessor.should_not be_nil
within "form#todo-form-new-action" do

View file

@ -1,7 +1,7 @@
####### MARK (UN)COMPLETE #######
When /^I mark "([^"]*)" as complete$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
check "mark_complete_#{todo.id}"
@ -11,7 +11,7 @@ When /^I mark "([^"]*)" as complete$/ do |action_description|
end
When /^I mark "([^"]*)" as uncompleted$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
uncheck "mark_complete_#{todo.id}"
@ -29,7 +29,7 @@ end
####### (UN)STARRING #######
When /^I star the action "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
xpath_unstarred = "//div[@id='line_todo_#{todo.id}']//img[@class='todo_star']"
@ -47,7 +47,7 @@ When /^I star the action "([^"]*)"$/ do |action_description|
end
When /^I unstar the action "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
xpath_unstarred = "//div[@id='line_todo_#{todo.id}']//img[@class='todo_star']"
@ -64,7 +64,7 @@ end
####### Editing a todo using Edit Form #######
When /I change the (.*) field of "([^\"]*)" to "([^\"]*)"$/ do |field_name, todo_name, new_value|
todo = @current_user.todos.find_by_description(todo_name)
todo = @current_user.todos.where(:description => todo_name).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -86,7 +86,7 @@ When /^I edit the project of "([^"]*)" to "([^"]*)"$/ do |todo_name, project_new
end
When /^I edit the description of "([^"]*)" to "([^"]*)"$/ do |action_description, new_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -97,7 +97,7 @@ When /^I edit the description of "([^"]*)" to "([^"]*)"$/ do |action_description
end
When /^I try to edit the description of "([^"]*)" to "([^"]*)"$/ do |action_description, new_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -111,7 +111,7 @@ When /^I try to edit the description of "([^"]*)" to "([^"]*)"$/ do |action_desc
end
When /^I edit the due date of "([^"]*)" to "([^"]*)"$/ do |action_description, date|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -130,7 +130,7 @@ When /^I edit the due date of "([^"]*)" to next month$/ do |action_description|
end
When /^I clear the due date of "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -144,7 +144,7 @@ When /^I clear the due date of "([^"]*)"$/ do |action_description|
end
When /^I edit the show from date of "([^"]*)" to next month$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -153,7 +153,7 @@ When /^I edit the show from date of "([^"]*)" to next month$/ do |action_descri
end
When /^I remove the show from date from "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -166,7 +166,7 @@ When /^I clear the show from date of "([^"]*)"$/ do |action_description|
end
When /^I defer "([^"]*)" for 1 day$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_submenu_for(todo)
@ -178,7 +178,7 @@ When /^I defer "([^"]*)" for 1 day$/ do |action_description|
end
When /^I edit the tags of "([^"]*)" to "([^"]*)"$/ do |action_description, tags|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_edit_form_for(todo)
@ -189,7 +189,7 @@ When /^I edit the tags of "([^"]*)" to "([^"]*)"$/ do |action_description, tags|
end
When /^I make a project of "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
open_submenu_for(todo)

View file

@ -5,7 +5,7 @@ end
####### DELETE #######
When /^I delete the action "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
handle_js_confirm do
@ -26,7 +26,7 @@ end
####### Notes #######
When /^I open the notes of "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
page.find(:xpath, "//div[@id='line_todo_#{todo.id}']/div/a/img").click
@ -37,7 +37,7 @@ end
####### THEN #######
Then /^I should see a starred "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
xpath_starred = "//div[@id='line_todo_#{todo.id}']//img[@class='todo_star starred']"
@ -45,7 +45,7 @@ Then /^I should see a starred "([^"]*)"$/ do |action_description|
end
Then /^I should see an unstarred "([^"]*)"$/ do |action_description|
todo = @current_user.todos.find_by_description(action_description)
todo = @current_user.todos.where(:description => action_description).first
todo.should_not be_nil
xpath_starred = "//div[@id='line_todo_#{todo.id}']//img[@class='todo_star']"
@ -66,7 +66,7 @@ Then /^I should not see the todo "([^\"]*)"$/ do |todo_description|
end
Then /^I should see a completed todo "([^"]*)"$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
# only completed todos have a grey span with the completed_at date
@ -75,7 +75,7 @@ Then /^I should see a completed todo "([^"]*)"$/ do |todo_description|
end
Then /^I should see an active todo "([^"]*)"$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='line_todo_#{todo.id}']/img[@class='grip']"
@ -137,14 +137,14 @@ Then /^the tag field in the new todo form should be "([^"]*)"$/ do |tag_list|
end
Then /^the tags of "([^"]*)" should be "([^"]*)"$/ do |todo_description, tag_list|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
todo.tag_list.should == tag_list
end
Then /^I should see "([^"]*)" in the completed section of the mobile site$/ do |desc|
todo = @current_user.todos.find_by_description(desc)
todo = @current_user.todos.where(:description => desc).first
todo.should_not be_nil
xpath = "//div[@id='completed_container']//a[@href='/todos/#{todo.id}.m']"
@ -162,7 +162,7 @@ Then /^I should (see|not see) the empty tickler message$/ do |see|
end
Then /^I should (see|not see) the notes of "([^"]*)"$/ do |visible, todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
page.find("div#notes_todo_#{todo.id}").send(visible=="see" ? "should" : "should_not", be_visible)

View file

@ -48,7 +48,7 @@ end
When /^I delete the user "([^\"]*)"$/ do |username|
# click "//tr[@id='user-3']//img"
# assert_confirmation "Warning: this will delete user 'john', all their actions, contexts, project and notes. Are you sure that you want to continue?"
user = User.find_by_login(username)
user = User.where(:login => username).first
user.should_not be_nil
handle_js_confirm do

View file

@ -21,11 +21,11 @@ module NavigationHelpers
done_overview_path(options)
when /the done actions page for context "([^"]*)"/i
@source_view = "done"
context = @current_user.contexts.find_by_name($1)
context = @current_user.contexts.where(:name => $1).first
done_todos_context_path(context, options)
when /the done actions page for project "([^"]*)"/i
@source_view = "done"
project = @current_user.projects.find_by_name($1)
project = @current_user.projects.where(:name => $1).first
done_todos_project_path(project, options)
when /the done actions page for tag "([^"]*)"/i
@source_view = "done"
@ -35,11 +35,11 @@ module NavigationHelpers
done_todos_path(options)
when /the all done actions page for context "([^"]*)"/i
@source_view = "done"
context = @current_user.contexts.find_by_name($1)
context = @current_user.contexts.where(:name => $1).first
all_done_todos_context_path(context, options)
when /the all done actions page for project "([^"]*)"/i
@source_view = "done"
project = @current_user.projects.find_by_name($1)
project = @current_user.projects.where(:name => $1).first
all_done_todos_project_path(project, options)
when /the all done actions page for tag "([^"]*)"/i
@source_view = "done"
@ -93,23 +93,23 @@ module NavigationHelpers
feeds_path(options)
when /the context page for "([^\"]*)" for user "([^\"]*)"/i
@source_view = "context"
@context = User.find_by_login($2).contexts.find_by_name($1)
@context = User.where(:login => $2).first.contexts.where(:name => $1).first
context_path(@context, options)
when /the context page for "([^\"]*)"/i
@source_view = "context"
@context = @current_user.contexts.find_by_name($1)
@context = @current_user.contexts.where(:name => $1).first
context_path(@context, options)
when /the "([^\"]*)" context/i
@source_view = "context"
@context = @current_user.contexts.find_by_name($1)
@context = @current_user.contexts.where(:name => $1).first
context_path(@context, options)
when /the "([^\"]*)" project for user "([^\"]*)"/i
@source_view = "project"
@project = User.find_by_login($2).projects.find_by_name($1)
@project = User.where(:login => $2).first.projects.where(:name => $1).first
project_path(@project, options)
when /the "([^\"]*)" project/i
@source_view = "project"
@project = @current_user.projects.find_by_name($1)
@project = @current_user.projects.where(:name => $1).first
project_path(@project, options)
when /the tag page for "([^"]*)"/i
@source_view = "tag"
@ -121,7 +121,7 @@ module NavigationHelpers
# Here is an example that pulls values out of the Regexp:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
# user_profile_path(User.where(:login => $1))first.
else
begin

View file

@ -112,14 +112,14 @@ module TracksStepHelper
end
def context_list_find_index(context_name)
div_id = "context_#{@current_user.contexts.find_by_name(context_name).id}"
div_id = "context_#{@current_user.contexts.where(:name => context_name).first.id}"
contexts = page.all("div.context").map { |x| x[:id] }
return contexts.find_index(div_id)
end
def project_list_find_index(project_name)
# TODO: refactor with context_list_find_index
div_id = "project_#{@current_user.projects.find_by_name(project_name).id}"
div_id = "project_#{@current_user.projects.where(:name => project_name).first.id}"
project = page.all("div.project").map { |x| x[:id] }
return project.find_index(div_id)
end