Skip to content
Browse files

migrate calendar feature

  • Loading branch information...
1 parent e9c9e79 commit 600f110335023084bbdc575cef895c001a11ea5d @lrbalt lrbalt committed Jan 30, 2012
View
2 app/views/todos/_todo.html.erb
@@ -12,7 +12,7 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
<%= remote_toggle_checkbox(todo) %>
<%= remote_edit_button(todo) unless suppress_edit_button %>
<ul class="sf-menu sf-item-menu">
- <li style="z-index:<%=@z_index_counter%>"><%= image_tag "downarrow.png", :alt=> "" %>
+ <li style="z-index:<%=@z_index_counter%>"><%= image_tag "downarrow.png", :id => "todo-submenu", :alt=> "" %>
<ul id="ul<%= dom_id(todo) %>">
<li><%= remote_delete_menu_item(todo) %></li>
<% unless todo.completed? || todo.deferred? -%>
View
7 config/database.yml.tmpl
@@ -6,7 +6,7 @@ development:
# encoding: utf8
host: localhost
username: root
- password:
+ password:
test: &TEST
adapter: sqlite3
@@ -20,10 +20,7 @@ production:
# encoding: utf8
host: localhost
username: root
- password:
+ password:
cucumber:
<<: *TEST
-
-selenium:
- <<: *TEST
View
1 config/environments/cucumber.rb
@@ -21,7 +21,6 @@
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
-# Unique cookies
# Unique cookies and use cookies for session
config.action_controller.session_store = :cookie_store
config.action_controller.session = { :key => 'TracksCucumber', :secret => SITE_CONFIG['salt'] * (30.0 / SITE_CONFIG['salt'].length).ceil }
View
26 config/environments/selenium.rb
@@ -1,26 +0,0 @@
-# Edit at your own peril - it's recommended to regenerate this file
-# in the future when you upgrade to a newer version of Cucumber.
-
-# IMPORTANT: Setting config.cache_classes to false is known to
-# break Cucumber's use_transactional_fixtures method.
-# For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165
-config.cache_classes = true
-
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
-
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_controller.perform_caching = false
-
-# Disable request forgery protection in test environment
-config.action_controller.allow_forgery_protection = false
-
-# Tell Action Mailer not to deliver emails to the real world.
-# The :test delivery method accumulates sent emails in the
-# ActionMailer::Base.deliveries array.
-config.action_mailer.delivery_method = :test
-
-# Unique cookies
-config.action_controller.session = { :key => 'TracksSelenium' }
-
View
107 config/initializers/mongrel_workaround.rb
@@ -1,107 +0,0 @@
-# adapted from https://gist.github.com/471663 and https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238
-
-def check_mongrel_around_115
-begin
- # Gem.available? is deprecated from rubygems 1.8.2
- Gem::Specification::find_by_name "mongrel", "~>1.1.5"
- rescue
- if RUBY_VERSION[2] == "9"
- false
- else
- Gem.available?('mongrel', '~>1.1.5')
- end
- end
-end
-
-mongrel115 = check_mongrel_around_115
-
-if Rails.version == '2.3.14' && mongrel115 && self.class.const_defined?(:Mongrel)
-
- # Pulled right from latest rack. Old looked like this in 1.1.0 version.
- #
- # def [](k)
- # super(@names[k] ||= @names[k.downcase])
- # end
- #
- module Rack
- module Utils
- class HeaderHash < Hash
- def [](k)
- super(@names[k]) if @names[k]
- super(@names[k.downcase])
- end
- end
- end
- end
-
- # Code pulled from the ticket above.
- #
- class Mongrel::CGIWrapper
- def header_with_rails_fix(options = 'text/html')
- @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie']
- header_without_rails_fix(options)
- end
- alias_method_chain :header, :rails_fix
- end
-
- # Pulled right from 2.3.10 ActionPack. Simple diff was
- #
- # if headers.include?('Set-Cookie')
- # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
- # end
- #
- # to
- #
- # if headers['Set-Cookie']
- # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
- # end
- #
- module ActionController
- class CGIHandler
- def self.dispatch_cgi(app, cgi, out = $stdout)
- env = cgi.__send__(:env_table)
- env.delete "HTTP_CONTENT_LENGTH"
-
- cgi.stdinput.extend ProperStream
-
- env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
-
- env.update({
- "rack.version" => [0,1],
- "rack.input" => cgi.stdinput,
- "rack.errors" => $stderr,
- "rack.multithread" => false,
- "rack.multiprocess" => true,
- "rack.run_once" => false,
- "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
- })
-
- env["QUERY_STRING"] ||= ""
- env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
- env["REQUEST_PATH"] ||= "/"
- env.delete "PATH_INFO" if env["PATH_INFO"] == ""
-
- status, headers, body = app.call(env)
- begin
- out.binmode if out.respond_to?(:binmode)
- out.sync = false if out.respond_to?(:sync=)
-
- headers['Status'] = status.to_s
-
- if headers['Set-Cookie']
- headers['cookie'] = headers.delete('Set-Cookie').split("\n")
- end
-
- out.write(cgi.header(headers))
-
- body.each { |part|
- out.write part
- out.flush if out.respond_to?(:flush)
- }
- ensure
- body.close if body.respond_to?(:close)
- end
- end
- end
- end
-end
View
55 features/calendar.feature
@@ -10,48 +10,49 @@ Feature: Show all due actions in a calendar view
And I have logged in as "testuser" with password "secret"
And I have a context called "@calendar"
- @selenium
+ @javascript
Scenario: Setting due date of a todo will show it in the calendar
- When I submit a new action with description "a new next action" in the context "@calendar"
+ When I submit a new action with description "something new" in the context "@calendar"
And I go to the calendar page
Then the badge should show 0
- And I should not see "a new next action"
+ And I should not see "something new"
When I go to the home page
- And I edit the due date of "a new next action" to tomorrow
+ Then I should see "something new"
+ When I edit the due date of "something new" to tomorrow
And I go to the calendar page
- Then the badge should show 1
- And I should see "a new next action"
+ Then I should see "something new"
+ And the badge should show 1
- @selenium
+ @javascript
Scenario: Clearing the due date of a todo will remove it from the calendar
When I go to the home page
- And I submit a new action with description "a new next action" in the context "@calendar"
- And I edit the due date of "a new next action" to tomorrow
+ And I submit a new action with description "something new" in the context "@calendar"
+ And I edit the due date of "something new" to tomorrow
And I go to the calendar page
- Then I should see "a new next action"
- When I clear the due date of "a new next action"
- Then I should not see "a new next action"
+ Then I should see "something new"
+ When I clear the due date of "something new"
+ Then I should not see "something new"
- @selenium
+ @javascript
Scenario: Marking a todo complete will remove it from the calendar
- Given I have a todo "a new next action" in the context "@calendar" which is due tomorrow
+ Given I have a todo "something new" in the context "@calendar" which is due tomorrow
When I go to the calendar page
- Then I should see "a new next action"
- When I clear the due date of "a new next action"
- Then I should not see "a new next action"
+ Then I should see "something new"
+ When I clear the due date of "something new"
+ Then I should not see "something new"
- @selenium
+ @javascript
Scenario: Deleting a todo will remove it from the calendar
- Given I have a todo "a new next action" in the context "@calendar" which is due tomorrow
+ Given I have a todo "something new" in the context "@calendar" which is due tomorrow
When I go to the calendar page
- Then I should see "a new next action"
- When I delete the action "a new next action"
- Then I should not see "a new next action"
+ Then I should see "something new"
+ When I delete the action "something new"
+ Then I should not see "something new"
- @selenium
+ @javascript
Scenario: Changing due date of a todo will move it in the calendar
- Given I have a todo "a new next action" in the context "@calendar" which is due tomorrow
+ Given I have a todo "something new" in the context "@calendar" which is due tomorrow
When I go to the calendar page
- Then I should see "a new next action"
- When I edit the due date of "a new next action" to next month
- Then I should see "a new next action" in the due next month container
+ Then I should see "something new"
+ When I edit the due date of "something new" to next month
+ Then I should see "something new" in the due next month container
View
6 features/step_definitions/container_steps.rb
@@ -193,10 +193,8 @@
todo = @current_user.todos.find_by_description(todo_description)
todo.should_not be_nil
- xpath = "//div[@id='due_after_this_month']//div[@id='line_todo_#{todo.id}']"
-
- wait_for :timeout => 5 do
- selenium.is_element_present(xpath)
+ within "div#due_after_this_month" do
+ find("div#line_todo_#{todo.id}").should_not be_nil
end
end
View
13 features/step_definitions/generic_steps.rb
@@ -11,18 +11,7 @@
end
Then /the badge should show (.*)/ do |number|
- badge = -1
- xpath= "//span[@id='badge_count']"
-
- if response.respond_to? :selenium
- response.should have_xpath(xpath)
- badge = response.selenium.get_text("xpath=#{xpath}").to_i
- else
- response.should have_xpath(xpath) do |node|
- badge = node.first.content.to_i
- end
- end
-
+ badge = find("span#badge_count").text.to_i
badge.should == number.to_i
end
View
2 features/step_definitions/login_steps.rb
@@ -6,7 +6,7 @@
click_button "Sign in »"
logout_regexp = @mobile_interface ? "Logout" : "Logout \(#{username}\)"
- response.should contain(logout_regexp)
+ page.should have_content(logout_regexp)
@current_user = User.find_by_login(username)
end
View
7 features/step_definitions/todo_edit_steps.rb
@@ -117,7 +117,12 @@
todo = @current_user.todos.find_by_description(action_description)
todo.should_not be_nil
open_edit_form_for(todo)
- selenium.click("//div[@id='edit_todo_#{todo.id}']//a[@id='due_x_todo_#{todo.id}']/img", :wait_for => :ajax, :javascript_framework => :jquery)
+ within "div#edit_todo_#{todo.id}" do
+ find("a#due_x_todo_#{todo.id}").click
+ wait_until do
+ find("input#due_todo_#{todo.id}").value == ""
+ end
+ end
submit_edit_todo_form(todo)
end
View
10 features/step_definitions/todo_steps.rb
@@ -4,13 +4,11 @@
todo = @current_user.todos.find_by_description(action_description)
todo.should_not be_nil
- delete_todo_button = "xpath=//a[@id='delete_todo_#{todo.id}']/img"
- selenium.click delete_todo_button
- selenium.get_confirmation.should == "Are you sure that you want to delete the action '#{todo.description}'?"
-
- wait_for :timeout => 5 do
- !selenium.is_element_present("//div[@id='line_todo_#{todo.id}']")
+ handle_js_confirm do
+ open_submenu_for(todo)
+ find("a#delete_todo_#{todo.id}").click
end
+ get_confirm_text.should == "Are you sure that you want to delete the action '#{todo.description}'?"
end
When /^I delete the todo "([^"]*)"$/ do |action_description|
View
3 features/support/env.rb
@@ -18,6 +18,8 @@
require 'capybara/session'
# BUG in this version of cucumber/capybara: require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
+Capybara.default_wait_time = 5
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
@@ -48,6 +50,7 @@
# subsequent scenarios. If you do this, we recommend you create a Before
# block that will explicitly put your database in a known state.
Cucumber::Rails::World.use_transactional_fixtures = true
+
# How to clean your database when transactions are turned off. See
# http://github.com/bmabey/database_cleaner for more info.
if defined?(ActiveRecord::Base)
View
19 features/support/selenium.rb
@@ -1,19 +0,0 @@
-if ENV["RAILS_ENV"] == "selenium"
- puts "Configuring to use Selenium with Webrat for Cucumber stories"
- Webrat.configure do |config|
- config.mode = :selenium
-
- config.application_environment = :selenium
- # use only if you run a separate rails test server instance and do not
- # want webrat to start one for you
- # config.application_port = 3001
-
- config.selenium_browser_startup_timeout = 30
- # use only if you run a separate selenium server instance and do not
- # want webrat to start one for you
- # config.selenium_server_address = "localhost"
- # config.selenium_server_port = "4444"
- end
-
- Cucumber::Rails::World.use_transactional_fixtures = false
-end
View
51 features/support/world.rb
@@ -4,7 +4,9 @@ def submit_multiple_next_action_form
end
def submit_next_action_form
- selenium.click("xpath=//form[@id='todo-form-new-action']//button[@id='todo_new_action_submit']", :wait_for => :ajax, :javascript_framework => :jquery)
+ within("#todo-form-new-action") do
+ click_button("todo_new_action_submit")
+ end
sleep(1)
end
@@ -16,11 +18,16 @@ def submit_new_project_form
selenium.click("xpath=//form[@id='project_form']//button[@id='project_new_project_submit']", :wait_for => :ajax, :javascript_framework => :jquery)
end
+ def wait_for_form_to_go_away(todo)
+ page.should_not have_content("button#submit_todo_#{todo.id}")
+ end
+
def submit_edit_todo_form (todo)
- selenium.click("//div[@id='edit_todo_#{todo.id}']//button[@id='submit_todo_#{todo.id}']", :wait_for => :ajax, :javascript_framework => :jquery)
- wait_for do
- !selenium.is_element_present("//form[@id='form_todo_#{todo.id}']")
+ within "div#edit_todo_#{todo.id}" do
+ click_button "submit_todo_#{todo.id}"
end
+ wait_for_form_to_go_away(todo)
+ wait_for_animations_to_end
end
def format_date(date)
@@ -29,7 +36,7 @@ def format_date(date)
end
def execute_javascript(js)
- selenium.get_eval "(function() {with(this) {#{js}}}).call(selenium.browserbot.getCurrentWindow());"
+ page.execute_script(js)
end
def clear_context_name_from_next_action_form
@@ -39,19 +46,37 @@ def clear_context_name_from_next_action_form
def clear_project_name_from_next_action_form
execute_javascript("$('#todo_project_name').val('');")
end
-
+
def open_edit_form_for(todo)
- edit_button = "xpath=//div[@id='line_todo_#{todo.id}']//img[@id='edit_icon_todo_#{todo.id}']"
-
- wait_for :timeout => 5 do
- selenium.is_element_present(edit_button)
+ within "div#line_todo_#{todo.id}" do
+ find("a#icon_edit_todo_#{todo.id}").click
end
+ wait_for_animations_to_end
+ end
+
+ def wait_for_animations_to_end
+ wait_until do
+ page.evaluate_script('$(":animated").length') == 0
+ end
+ end
- selenium.click(edit_button, :wait_for => :ajax, :javascript_framework => :jquery)
+ def handle_js_confirm(accept=true)
+ page.execute_script "window.original_confirm_function = window.confirm"
+ page.execute_script "window.confirmMsg = null"
+ page.execute_script "window.confirm = function(msg) { window.confirmMsg = msg; return #{!!accept}; }"
+ yield
+ ensure
+ page.execute_script "window.confirm = window.original_confirm_function"
+ end
+
+ def get_confirm_text
+ page.evaluate_script "window.confirmMsg"
end
- def wait_for_ajax
- selenium.wait_for :wait_for => :ajax, :javascript_framework => :jquery
+ def open_submenu_for(todo)
+ within "div#line_todo_#{todo.id}" do
+ find("img#todo-submenu").click
+ end
end
end

0 comments on commit 600f110

Please sign in to comment.
Something went wrong with that request. Please try again.