2012-03-19 14:05:54 +01:00
Given / ^I have no projects$ / do
Project . delete_all
end
2012-01-30 09:56:58 -05:00
Given / ^I have an outdated project "([^"]*)" with ( \ d+) todos$ / do | project_name , num_todos |
2012-03-01 20:31:16 +01:00
step " I have a project \" #{ project_name } \" with #{ num_todos } todos "
2013-02-27 20:02:01 +01:00
@project = @current_user . projects . where ( :name = > project_name ) . first
2012-01-30 09:56:58 -05:00
@project . last_reviewed = @current_user . time - @current_user . prefs . review_period . days - 1
@project . save
end
2012-03-19 14:05:54 +01:00
Given / ^I have a project "([^"]*)" with ( \ d+) deferred actions$ / do | name , deferred |
step " I have a project \" #{ name } \" with #{ deferred } deferred todos "
end
Given / ^I have a project "([^"]*)" with ( \ d+) active actions and ( \ d+) deferred actions$ / do | name , active_count , deferred_count |
step " I have a project \" #{ name } \" with #{ active_count } active todos "
step " I have a project \" #{ name } \" with #{ deferred_count } deferred todos "
end
2012-03-23 20:39:04 +01:00
Given / ^I have a project "([^"]*)" with ( \ d+) (todo|active todo|deferred todo)s prefixed by "([^ \ "]*)"$ / do | project_name , num_todos , state , prefix |
2013-02-27 20:02:01 +01:00
@context = @current_user . contexts . where ( :name = > " Context A " ) . first_or_create
@project = @current_user . projects . where ( :name = > project_name ) . first_or_create
2011-09-14 13:49:06 +02:00
# acts_as_list adds at top by default, but that is counter-intuitive when reading scenario's, so reverse this
@project . move_to_bottom
2011-09-14 20:50:21 +02:00
@todos = [ ]
2010-03-02 11:14:45 +01:00
1 . upto num_todos . to_i do | i |
2011-09-14 20:50:21 +02:00
todo = @current_user . todos . create! (
2011-08-11 17:13:01 +02:00
:project_id = > @project . id ,
:context_id = > @context . id ,
2012-03-23 20:39:04 +01:00
:description = > " #{ prefix } #{ state } #{ i } " )
2012-03-19 14:05:54 +01:00
todo . show_from = Time . zone . now + 1 . week if state == " deferred todo "
2011-09-14 20:50:21 +02:00
todo . save!
2012-03-19 14:05:54 +01:00
@todos << todo
2010-03-02 11:14:45 +01:00
end
2010-02-12 12:35:19 +01:00
end
2012-03-23 20:39:04 +01:00
Given / ^I have a project "([^"]*)" with ( \ d+) (todos|active todos|deferred todos)$ / do | project_name , num_todos , state |
step " I have a project \" #{ project_name } \" with #{ num_todos } #{ state } prefixed by \" \" "
end
2012-03-19 14:05:54 +01:00
Given / ^there exists a project (?:|called )"([^"]*)" for user "([^"]*)"$ / do | project_name , user_name |
2013-02-27 20:02:01 +01:00
user = User . where ( :login = > user_name ) . first
2010-02-12 12:35:19 +01:00
user . should_not be_nil
2010-08-12 14:39:58 +02:00
@project = user . projects . create! ( :name = > project_name )
2011-09-14 13:49:06 +02:00
# acts_as_list adds at top by default, but that is counter-intuitive when reading scenario's, so reverse this
@project . move_to_bottom
2010-02-12 12:35:19 +01:00
end
2012-03-19 14:05:54 +01:00
Given / ^I have a project (?:|called )"([^"]*)"$ / do | project_name |
@project = @current_user . projects . create! ( :name = > project_name )
2010-07-30 21:06:12 +02:00
end
2011-02-26 11:38:39 +01:00
Given / ^I have a project "([^"]*)" with a default context of "([^"]*)"$ / do | project_name , context_name |
2012-03-19 14:05:54 +01:00
step " I have a project \" #{ project_name } \" "
2011-02-26 11:38:39 +01:00
context = @current_user . contexts . create! ( :name = > context_name )
@project . default_context = context
@project . save!
end
2010-11-27 17:12:09 +01:00
Given / ^I have the following projects:$ / do | table |
table . hashes . each do | project |
2012-03-19 14:05:54 +01:00
step " I have a project called \" #{ project [ :project_name ] } \" "
2011-09-13 11:15:14 +02:00
# acts_as_list puts the last added project at the top, but we want it
# at the bottom to be consistent with the table in the scenario
@project . move_to_bottom
@project . save!
2010-11-27 17:12:09 +01:00
end
end
2012-03-19 14:05:54 +01:00
Given / ^I have a (completed|hidden) project called "([^"]*)"$ / do | state , project_name |
2012-02-15 21:42:06 +01:00
step " I have a project called \" #{ project_name } \" "
2012-03-19 14:05:54 +01:00
@project . send ( state == " completed " ? " complete! " : " hide! " )
2011-06-20 06:50:25 +02:00
@project . reload
2012-03-19 14:05:54 +01:00
assert @project . send ( state == " completed " ? " completed? " : " hidden? " )
2011-06-20 06:50:25 +02:00
end
Given / ^I have ( \ d+) completed projects$ / do | number_of_projects |
1 . upto number_of_projects . to_i do | i |
2012-02-15 21:42:06 +01:00
step " I have a completed project called \" Project #{ i } \" "
2011-06-20 06:50:25 +02:00
end
end
2012-03-19 14:05:54 +01:00
Given / ^I have one project "([^ \ "]*)" with no notes$ / do | project_name |
step " I have a project called \" #{ project_name } \" "
2010-11-27 17:12:09 +01:00
end
2012-03-19 14:05:54 +01:00
Given / ^I have two projects with one note each$ / do
step " I have a project \" project A \" "
@project . notes . create! ( :user_id = > @current_user . id , :body = > 'note for project A' )
step " I have a project \" project B \" "
@project . notes . create! ( :user_id = > @current_user . id , :body = > 'note for project B' )
end
Given / ^I have a project "([^ \ "]*)" with (.*) notes?$ / do | project_name , num |
project = @current_user . projects . create! ( :name = > project_name )
1 . upto num . to_i do | i |
project . notes . create! ( :user_id = > @current_user . id , :body = > " A note #{ i } . This is the very long body of note #{ i } where you should not see the last part of the note after 50 characters " )
end
2011-01-08 19:50:19 +01:00
end
2012-07-11 16:25:24 +02:00
Given / ^the default tags for "(.*?)" are "(.*?)"$ / do | project_name , default_tags |
2013-02-27 20:02:01 +01:00
project = @current_user . projects . where ( :name = > project_name ) . first
2012-07-11 16:25:24 +02:00
project . should_not be_nil
project . default_tags = default_tags
project . save!
end
2011-08-15 17:04:59 +02:00
When / ^I open the project edit form$ / do
click_link " link_edit_project_ #{ @project . id } "
2012-03-01 20:31:16 +01:00
page . should have_css ( " button # submit_project_ #{ @project . id } " , :visible = > true )
2011-08-15 17:04:59 +02:00
end
When / ^I cancel the project edit form$ / do
click_link " cancel_project_ #{ @project . id } "
2012-03-19 14:05:54 +01:00
page . should_not have_css ( " submit_project_ #{ @project . id } " )
2012-03-22 16:10:37 +01:00
wait_for_animations_to_end
2011-08-15 17:04:59 +02:00
end
2010-02-12 12:35:19 +01:00
When / ^I edit the project description to "([^ \ "]*)"$ / do | new_description |
2012-03-01 20:31:16 +01:00
edit_project ( @project ) do
fill_in " project[description] " , :with = > new_description
2011-08-15 17:04:59 +02:00
end
2009-08-05 16:28:06 +02:00
end
2010-03-24 20:45:59 +01:00
2010-07-05 08:24:58 -07:00
When / ^I edit the project name to "([^ \ "]*)"$ / do | new_title |
2012-03-01 20:31:16 +01:00
edit_project ( @project ) do
fill_in " project[name] " , :with = > new_title
2010-11-09 23:12:21 +01:00
end
end
When / ^I try to edit the project name to "([^ \ "]*)"$ / do | new_title |
2012-03-01 20:31:16 +01:00
edit_project_no_wait ( @project ) do
2013-02-15 20:51:35 +01:00
within " form.edit-project-form " do
fill_in " project[name] " , :with = > new_title
end
2010-11-09 23:12:21 +01:00
end
2010-08-03 20:55:07 +02:00
end
2011-09-14 20:50:21 +02:00
When / ^I edit the default context to "([^"]*)"$ / do | default_context |
2012-03-01 20:31:16 +01:00
edit_project ( @project ) do
fill_in " project[default_context_name] " , :with = > default_context
2011-09-14 20:50:21 +02:00
end
end
2010-08-03 20:55:07 +02:00
When / ^I edit the project name of "([^"]*)" to "([^"]*)"$ / do | project_current_name , project_new_name |
2013-02-27 20:02:01 +01:00
@project = @current_user . projects . where ( :name = > project_current_name ) . first
2010-08-03 20:55:07 +02:00
@project . should_not be_nil
2012-02-15 21:42:06 +01:00
step " I edit the project name to \" #{ project_new_name } \" "
2010-07-05 08:24:58 -07:00
end
2010-11-09 23:12:21 +01:00
When / ^I try to edit the project name of "([^"]*)" to "([^"]*)"$ / do | project_current_name , project_new_name |
2013-02-27 20:02:01 +01:00
@project = @current_user . projects . where ( :name = > project_current_name ) . first
2010-11-09 23:12:21 +01:00
@project . should_not be_nil
2012-02-15 21:42:06 +01:00
step " I try to edit the project name to \" #{ project_new_name } \" "
2010-11-09 23:12:21 +01:00
end
2010-11-08 22:36:35 +01:00
When / ^I edit the project name in place to be "([^"]*)"$ / do | new_project_name |
2013-03-17 15:41:36 +01:00
page . find ( " span # project_name " ) . click
2010-11-08 22:36:35 +01:00
fill_in " value " , :with = > new_project_name
2011-02-09 20:41:34 +01:00
click_button " Ok "
2010-11-08 22:36:35 +01:00
end
2010-10-08 21:07:17 +02:00
2011-12-12 12:34:28 -06:00
When / ^I click to edit the project name in place$ / do
2013-03-17 15:41:36 +01:00
page . find ( " span # project_name " ) . click
2011-12-12 12:34:28 -06:00
end
When / ^I edit the project settings$ / do
@project . should_not be_nil
click_link " link_edit_project_ #{ @project . id } "
2012-03-19 14:05:54 +01:00
page . should have_xpath ( " //div[@id='edit_project_ #{ @project . id } ']/form//button[@id='submit_project_ #{ @project . id } '] " )
2011-12-12 12:34:28 -06:00
end
When / ^I close the project settings$ / do
2012-02-15 21:42:06 +01:00
@project . should_not be_nil
click_link " Cancel "
2012-03-01 20:31:16 +01:00
wait_for_ajax
wait_for_animations_to_end
2011-12-12 12:34:28 -06:00
end
2010-10-08 21:07:17 +02:00
When / ^I edit the project state of "([^"]*)" to "([^"]*)"$ / do | project_name , state_name |
2013-02-27 20:02:01 +01:00
project = @current_user . projects . where ( :name = > project_name ) . first
2010-10-08 21:07:17 +02:00
project . should_not be_nil
2012-03-01 20:31:16 +01:00
edit_project_settings ( project ) do
choose " project_state_ #{ state_name } "
2010-10-15 11:49:34 +02:00
end
2010-10-08 21:07:17 +02:00
end
2012-03-29 16:05:17 +02:00
When / ^I edit project "([^"]*)" and mark the project as reviewed$ / do | project_name |
2013-02-27 20:02:01 +01:00
project = @current_user . projects . where ( :name = > project_name ) . first
2012-03-29 16:05:17 +02:00
project . should_not be_nil
open_project_edit_form ( project )
click_link " reviewed_project_ #{ project . id } "
end
When / ^I edit project settings and mark the project as reviewed$ / do
open_project_edit_form ( @project )
click_link " reviewed_project_ #{ @project . id } "
end
2010-11-24 22:01:23 +01:00
When / ^I add a note "([^"]*)" to the project$ / do | note_body |
2013-02-15 20:51:35 +01:00
submit_button = " div.widgets button # submit_note "
2010-11-24 22:01:23 +01:00
click_link " Add a note "
2013-02-15 20:51:35 +01:00
page . should have_css submit_button
2010-11-24 22:01:23 +01:00
fill_in " note[body] " , :with = > note_body
2012-07-11 15:35:21 +02:00
elem = find ( submit_button )
2013-02-15 20:51:35 +01:00
elem . should_not be_nil
elem . click
wait_until do
! elem . visible?
end
2010-11-24 22:01:23 +01:00
end
When / ^I click on the first note icon$ / do
@project . should_not be_nil
@note = @project . notes . first # assume first note is also first on screen
@note . should_not be_nil
click_link " link_note_ #{ @note . id } "
end
When / ^I cancel adding a note to the project$ / do
click_link " Add a note "
fill_in " note[body] " , :with = > " will not save this "
click_link " neg_edit_form_note "
end
2012-03-19 16:00:48 +01:00
Then / ^I edit the default tags to "([^"]*)"$ / do | default_tags |
edit_project ( @project ) do
fill_in " project[default_tags] " , :with = > default_tags
end
end
Then / ^I should be able to change the project name in place$ / do
2013-02-15 20:51:35 +01:00
# Note that this is not changing the project name
2013-03-17 15:41:36 +01:00
page . should have_css ( " span # project_name>form>input " )
page . find ( " span # project_name > form > button[type=cancel] " ) . click
page . should_not have_css ( " span # project_name>form>input " )
2012-03-19 16:00:48 +01:00
end
Then / ^I should not be able to change the project name in place$ / do
step " I click to edit the project name in place "
2013-03-17 15:41:36 +01:00
page . should_not have_xpath ( " //span[@id='project_name']/form/input " )
2012-03-19 16:00:48 +01:00
end
2010-11-24 22:01:23 +01:00
Then / ^the form for adding a note should not be visible$ / do
2012-03-01 20:31:16 +01:00
page . should_not have_css ( " edit_form_note " )
2010-11-24 22:01:23 +01:00
end
Then / ^I should go to that note page$ / do
current_path = URI . parse ( current_url ) . path
note_path = note_path ( @note )
current_path . should == note_path
end
Then / ^I should see one note in the project$ / do
2012-03-01 20:31:16 +01:00
page . should have_xpath ( " //div[@class='note_wrapper'] " )
2010-11-24 22:01:23 +01:00
end
2012-03-01 20:31:16 +01:00
Then / ^I should see the bold text "([^ \ "]*)" in the project description$ / do | text_in_bold |
2010-03-24 20:45:59 +01:00
xpath = " //div[@class='project_description']/p/strong "
2012-03-01 20:31:16 +01:00
page . should have_xpath ( xpath )
bold_text = page . find ( :xpath , xpath ) . text
bold_text . should =~ / #{ text_in_bold } /
2010-03-24 20:45:59 +01:00
end
2012-03-01 20:31:16 +01:00
Then / ^I should see the italic text "([^ \ "]*)" in the project description$ / do | text_in_italic |
2010-03-24 20:45:59 +01:00
xpath = " //div[@class='project_description']/p/em "
2012-03-01 20:31:16 +01:00
page . should have_xpath ( xpath )
italic_text = page . find ( :xpath , xpath ) . text
italic_text . should =~ / #{ text_in_italic } /
2010-04-10 15:23:38 -04:00
end
2010-07-05 08:24:58 -07:00
Then / ^the project title should be "(.*)"$ / do | title |
2012-03-01 20:31:16 +01:00
wait_until do
2013-03-17 15:41:36 +01:00
page . find ( " h2 # project_name_container span # project_name " ) . text == title
2011-09-14 20:50:21 +02:00
end
2010-11-08 22:36:35 +01:00
end
Then / ^I should see the project name is "([^"]*)"$ / do | project_name |
2012-02-15 21:42:06 +01:00
step " the project title should be \" #{ project_name } \" "
2011-02-26 11:38:39 +01:00
end
2012-03-01 20:31:16 +01:00
Then / ^I should (see|not see) the default project settings$ / do | visible |
default_settings = " This project is active with no default context and with no default tags "
2012-03-21 19:33:06 +01:00
page . should have_css ( " div.project_settings " )
2012-03-19 14:05:54 +01:00
elem = page . find ( " div.project_settings " )
2012-03-01 20:31:16 +01:00
if visible == " see "
2012-03-19 14:05:54 +01:00
elem . should be_visible
2012-03-01 20:31:16 +01:00
elem . text . should =~ / #{ default_settings } /
else
2012-03-19 14:05:54 +01:00
elem . should_not be_visible
2012-03-01 20:31:16 +01:00
end
2012-03-19 16:00:48 +01:00
end
Then / ^I should have a project called "([^"]*)"$ / do | project_name |
2013-02-27 20:02:01 +01:00
project = @current_user . projects . where ( :name = > project_name ) . first
2012-03-19 16:00:48 +01:00
project . should_not be_nil
end
Then / ^I should have ( \ d+) todo in project "([^"]*)"$ / do | todo_count , project_name |
2013-02-27 20:02:01 +01:00
project = @current_user . projects . where ( :name = > project_name ) . first
2012-03-19 16:00:48 +01:00
project . should_not be_nil
project . todos . count . should == todo_count . to_i
end