diff --git a/app/models/context.rb b/app/models/context.rb index cfc20eb4..cc5f6253 100644 --- a/app/models/context.rb +++ b/app/models/context.rb @@ -7,7 +7,7 @@ class Context < ActiveRecord::Base named_scope :active, :conditions => { :hide => false } named_scope :hidden, :conditions => { :hide => true } - acts_as_list :scope => :user + acts_as_list :scope => :user, :top_of_list => 0 extend NamePartFinder include Tracks::TodoList @@ -25,7 +25,7 @@ class Context < ActiveRecord::Base :description => "Lists all the contexts for #{user.display_name}" } end - + def self.null_object NullContext.new end @@ -33,29 +33,29 @@ class Context < ActiveRecord::Base def hidden? self.hide == true || self.hide == 1 end - + def title name end - + def new_record_before_save? @new_record_before_save - end + end end class NullContext - + def nil? true end - + def id nil end - + def name '' end - + end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 5fd60f24..c78e6ccb 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -10,20 +10,20 @@ class Project < ActiveRecord::Base named_scope :hidden, :conditions => { :state => 'hidden' } named_scope :completed, :conditions => { :state => 'completed'} named_scope :uncompleted, :conditions => ["NOT(state = ?)", 'completed'] - + validates_presence_of :name validates_length_of :name, :maximum => 255 validates_uniqueness_of :name, :scope => "user_id" - acts_as_list :scope => 'user_id = #{user_id} AND state = \'#{state}\'' - + acts_as_list :scope => 'user_id = #{user_id} AND state = \'#{state}\'', :top_of_list => 0 + include AASM aasm_column :state aasm_initial_state :active - + extend NamePartFinder #include Tracks::TodoList - + aasm_state :active aasm_state :hidden, :enter => :hide_todos, :exit => :unhide_todos aasm_state :completed, :enter => :set_completed_at_date, :exit => :clear_completed_at_date @@ -31,29 +31,29 @@ class Project < ActiveRecord::Base aasm_event :activate do transitions :to => :active, :from => [:active, :hidden, :completed] end - + aasm_event :hide do transitions :to => :hidden, :from => [:active, :completed] end - + aasm_event :complete do transitions :to => :completed, :from => [:active, :hidden] end - + attr_protected :user attr_accessor :cached_note_count def self.null_object NullProject.new end - + def self.feed_options(user) { :title => I18n.t('models.project.feed_title'), :description => I18n.t('models.project.feed_description', :username => user.display_name) } end - + def hide_todos todos.each do |t| unless t.completed? || t.deferred? @@ -62,7 +62,7 @@ class Project < ActiveRecord::Base end end end - + def unhide_todos todos.each do |t| if t.project_hidden? @@ -71,27 +71,27 @@ class Project < ActiveRecord::Base end end end - + def set_completed_at_date self.completed_at = Time.zone.now end - + def clear_completed_at_date self.completed_at = nil end - + def note_count # TODO: test this for eager and not eager loading!!! return 0 if notes.size == 0 cached_note_count || notes.count end - + alias_method :original_default_context, :default_context def default_context original_default_context.nil? ? Context.null_object : original_default_context end - + # would prefer to call this method state=(), but that causes an endless loop # as a result of acts_as_state_machine calling state=() to update the attribute def transition_to(candidate_state) @@ -106,29 +106,29 @@ class Project < ActiveRecord::Base complete! end end - + def name=(value) self[:name] = value.gsub(/\s{2,}/, " ").strip end - + def new_record_before_save? @new_record_before_save - end - + end + end class NullProject - + def hidden? false end - + def nil? true end - + def id nil end - + end diff --git a/features/context_list.feature b/features/context_list.feature index 3b864fef..e001ca2c 100644 --- a/features/context_list.feature +++ b/features/context_list.feature @@ -11,10 +11,10 @@ Feature: Manage the list of contexts Scenario: The list of contexts contain all contexts Given I have the following contexts - | name | hide | - | @ipad | false | - | @home | false | - | @boss | false | + | context | hide | + | @ipad | false | + | @home | false | + | @boss | false | When I go to the contexts page Then I should see "@ipad" And I should see "@home" @@ -25,7 +25,7 @@ Feature: Manage the list of contexts Given I have a context called "@computer" When I go to the contexts page And I follow "@computer" - Then I should be on the context page for "@computer" + Then I should be on the context page for "@computer" @selenium Scenario: Delete context from context page should update badge @@ -76,9 +76,9 @@ Feature: Manage the list of contexts @selenium Scenario Outline: Add a new context with state Given I have the following contexts - | name | hide | - | @ipad | true | - | @home | false | + | context | hide | + | @ipad | true | + | @home | false | When I go to the contexts page And I add a new context "" Then I should see the context "" under "" @@ -97,10 +97,10 @@ Feature: Manage the list of contexts @selenium Scenario: I can drag and drop to order the contexts Given I have the following contexts - | name | - | @ipad | - | @home | - | @boss | + | context | + | @ipad | + | @home | + | @boss | When I go to the contexts page Then context "@ipad" should be above context "@home" When I drag context "@ipad" below context "@home" diff --git a/features/step_definitions/container_steps.rb b/features/step_definitions/container_steps.rb index 2dc0e8f4..2f09911b 100644 --- a/features/step_definitions/container_steps.rb +++ b/features/step_definitions/container_steps.rb @@ -61,8 +61,9 @@ Then /^I should see "([^"]*)" in the context container for "([^"]*)"$/ do |todo_ todo.should_not be_nil xpath = "xpath=//div[@id=\"c#{context.id}\"]//div[@id='line_todo_#{todo.id}']" - selenium.wait_for_element(xpath, :timeout_in_seconds => 5) - selenium.is_visible(xpath).should be_true + wait_for :timeout => 5 do + selenium.is_visible(xpath) + end end Then /^I should not see "([^"]*)" in the context container for "([^"]*)"$/ do |todo_description, context_name| diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb index c44691bd..2cbfa34d 100644 --- a/features/step_definitions/context_steps.rb +++ b/features/step_definitions/context_steps.rb @@ -34,9 +34,18 @@ end Given /^I have the following contexts:$/ do |table| table.hashes.each do |context| Given 'I have a context called "'+context[:context]+'"' + @context.hide = context[:hide] == "true" unless context[:hide].blank? + # acts_as_list puts the last added context at the top, but we want it + # at the bottom to be consistent with the table in the scenario + @context.move_to_bottom + @context.save! end end +Given /^I have the following contexts$/ do |table| + Given("I have the following contexts:", table) +end + Given /^I have a context "([^\"]*)" with (.*) actions$/ do |context_name, number_of_actions| context = @current_user.contexts.create!(:name => context_name) 1.upto number_of_actions.to_i do |i| @@ -44,17 +53,6 @@ Given /^I have a context "([^\"]*)" with (.*) actions$/ do |context_name, number end end -Given /^I have the following contexts$/ do |table| - Context.delete_all - table.hashes.each do |hash| - context = @current_user.contexts.create!(:name => hash[:name]) - unless hash[:hide].blank? - context.hide = hash[:hide] == true - context.save! - end - end -end - When /^I edit the context name in place to be "([^\"]*)"$/ do |new_context_name| selenium.click "context_name" fill_in "value", :with => new_context_name diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index d18861fc..cd0c9dc9 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -34,6 +34,10 @@ end Given /^I have the following projects:$/ do |table| table.hashes.each do |project| Given 'I have a project called "'+project[:project_name]+'"' + # 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! end end diff --git a/features/support/hooks.rb b/features/support/hooks.rb new file mode 100644 index 00000000..f53087e8 --- /dev/null +++ b/features/support/hooks.rb @@ -0,0 +1,11 @@ +AfterStep('@pause') do + print "Press Return to continue..." + STDIN.getc +end + +Before('@clear_cookies') do + cookies = selenium.cookies + cookies.split(';').each do | cookie | + selenium.delete_cookie(cookie) + end +end diff --git a/features/support/world.rb b/features/support/world.rb index 899fb801..b379e29d 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -22,7 +22,7 @@ module TracksStepHelper !selenium.is_element_present("//form[@id='form_todo_#{todo.id}']") end end - + def format_date(date) # copy-and-past from ApplicationController::format_date return date ? date.in_time_zone(@current_user.prefs.time_zone).strftime("#{@current_user.prefs.date_format}") : '' @@ -46,14 +46,14 @@ module TracksStepHelper wait_for :timeout => 5 do selenium.is_element_present(edit_button) end - + selenium.click(edit_button, :wait_for => :ajax, :javascript_framework => :jquery) end def wait_for_ajax selenium.wait_for :wait_for => :ajax, :javascript_framework => :jquery end - + end World(TracksStepHelper) \ No newline at end of file diff --git a/features/toggle_context_containers.feature b/features/toggle_context_containers.feature index fc73bb41..fc1bbe37 100644 --- a/features/toggle_context_containers.feature +++ b/features/toggle_context_containers.feature @@ -9,13 +9,13 @@ Feature: Toggle the context containers | testuser | secret | false | And I have logged in as "testuser" with password "secret" - @selenium + @selenium @clear_cookies Scenario: I can toggle a context container Given I have the following contexts - | name | hide | - | @ipad | false | - | @home | false | - | @boss | false | + | context | hide | + | @ipad | false | + | @home | false | + | @boss | false | And I have a project "collapse those contexts" that has the following todos | description | context | | test 1 | @ipad | @@ -38,13 +38,13 @@ Feature: Toggle the context containers And I should not see "test 2" And I should not see "test 3" - @selenium + @selenium @clear_cookies Scenario: I can hide all collapsed containers Given I have the following contexts - | name | hide | - | @ipad | false | - | @home | false | - | @boss | false | + | context | hide | + | @ipad | false | + | @home | false | + | @boss | false | And I have a project "collapse those contexts" that has the following todos | description | context | | test 1 | @ipad | @@ -64,4 +64,3 @@ Feature: Toggle the context containers Then I should not see the context container for "@home" And I should not see the context container for "@boss" And I should not see the context container for "@ipad" -