get the first cucumber feature running: calendar

This commit is contained in:
Reinier Balt 2012-04-30 13:51:42 +02:00
parent 393eae1937
commit c9d64e6f4b
28 changed files with 400 additions and 418 deletions

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before After
Before After

View file

@ -9,18 +9,14 @@ class ContextsController < ApplicationController
prepend_before_filter :login_or_feed_token_required, :only => [:index]
def index
# #true is passed here to force an immediate load so that size and empty?
# checks later don't result in separate SQL queries
@active_contexts = current_user.contexts.active(true)
@hidden_contexts = current_user.contexts.hidden(true)
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
@new_context = current_user.contexts.build
# save all contexts here as @new_context will add an empty one to current_user.contexts
@all_contexts = @active_contexts + @hidden_contexts
@count = @all_contexts.size
init_not_done_counts(['context'])
respond_to do |format|
format.html &render_contexts_html
format.m &render_contexts_mobile
@ -200,6 +196,7 @@ class ContextsController < ApplicationController
@no_hidden_contexts = @hidden_contexts.empty?
@active_count = @active_contexts.size
@hidden_count = @hidden_contexts.size
init_not_done_counts(['context'])
render
end
end

View file

@ -8,60 +8,38 @@ class LoginController < ApplicationController
protect_from_forgery :except => [:check_expiry, :login]
if ( SITE_CONFIG['authentication_schemes'].include? 'cas')
# This will allow the user to view the index page without authentication
# but will process CAS authentication data if the user already
# has an SSO session open.
if defined? CASClient
# Only require sub-library if gem is installed and loaded
require 'casclient/frameworks/rails/filter'
before_filter CASClient::Frameworks::Rails::GatewayFilter, :only => :login_cas
# This requires the user to be authenticated for viewing all other pages.
before_filter CASClient::Frameworks::Rails::Filter, :only => [:login_cas ]
end
end
def login
if cas_enabled?
@username = session[:cas_user]
@login_url = CASClient::Frameworks::Rails::Filter.login_url(self)
@page_title = "TRACKS::Login"
cookies[:preferred_auth] = prefered_auth? unless cookies[:preferred_auth]
case request.method
when 'POST'
if @user = User.authenticate(params['user_login'], params['user_password'])
session['user_id'] = @user.id
# If checkbox on login page checked, we don't expire the session after 1 hour
# of inactivity and we remember this user for future browser sessions
session['noexpiry'] = params['user_noexpiry']
msg = (should_expire_sessions?) ? "will expire after 1 hour of inactivity." : "will not expire."
notify :notice, "Login successful: session #{msg}"
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
unless should_expire_sessions?
@user.remember_me
cookies[:auth_token] = { :value => @user.remember_token , :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
end
redirect_back_or_home
return
else
@login = params['user_login']
notify :warning, t('login.unsuccessful')
end
when 'GET'
if User.no_users_yet?
redirect_to signup_path
return
end
end
if cas_enabled? && session[:cas_user]
login_cas
else
@page_title = "TRACKS::Login"
cookies[:preferred_auth] = prefered_auth? unless cookies[:preferred_auth]
case request.method
when 'POST'
if @user = User.authenticate(params['user_login'], params['user_password'])
session['user_id'] = @user.id
# If checkbox on login page checked, we don't expire the session after 1 hour
# of inactivity and we remember this user for future browser sessions
session['noexpiry'] = params['user_noexpiry']
msg = (should_expire_sessions?) ? "will expire after 1 hour of inactivity." : "will not expire."
notify :notice, "Login successful: session #{msg}"
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
unless should_expire_sessions?
@user.remember_me
cookies[:auth_token] = { :value => @user.remember_token , :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
end
redirect_back_or_home
return
else
@login = params['user_login']
notify :warning, t('login.unsuccessful')
end
when 'GET'
if User.no_users_yet?
redirect_to signup_path
return
end
end
respond_to do |format|
format.html
format.m { render :action => 'login_mobile.html.erb', :layout => 'mobile' }
end
respond_to do |format|
format.html
format.m { render :action => 'login_mobile.html.erb', :layout => 'mobile' }
end
end
@ -109,64 +87,10 @@ class LoginController < ApplicationController
end
end
def login_cas
# If checkbox on login page checked, we don't expire the session after 1 hour
# of inactivity and we remember this user for future browser sessions
session['noexpiry'] ||= params['user_noexpiry']
if session[:cas_user]
if @user = User.find_by_login(session[:cas_user])
session['user_id'] = @user.id
msg = (should_expire_sessions?) ? t('login.session_will_expire', :hours => 1) : t('login.session_will_not_expire')
notify :notice, (t('login.successful_with_session_info') + msg)
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
unless should_expire_sessions?
@user.remember_me
cookies[:auth_token] = { :value => @user.remember_token, :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
end
else
notify :warning, t('login.cas_username_not_found', :username => session[:cas_user])
redirect_to signup_url ; return
end
else
notify :warning, result.message
end
redirect_back_or_home
end
private
def should_expire_sessions?
session['noexpiry'] != "on"
end
protected
def login_openid
# If checkbox on login page checked, we don't expire the session after 1 hour
# of inactivity and we remember this user for future browser sessions
session['noexpiry'] ||= params['user_noexpiry']
authenticate_with_open_id do |result, identity_url|
if result.successful?
if @user = User.find_by_open_id_url(identity_url)
session['user_id'] = @user.id
msg = (should_expire_sessions?) ? t('login.session_will_expire', :hours => 1) : t('login.session_will_not_expire')
notify :notice, (t('login.successful_with_session_info') + msg)
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
unless should_expire_sessions?
@user.remember_me
cookies[:auth_token] = { :value => @user.remember_token , :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
end
redirect_back_or_home
else
notify :warning, t('login.openid_identity_url_not_found', :identity_url => identity_url)
end
else
notify :warning, result.message
end
end
end
end

View file

@ -108,8 +108,7 @@ class TodosController < ApplicationController
includes(:project, :context, :tags)
else
@todos = current_user.todos.includes(Todo::DEFAULT_INCLUDES)
@not_done_todos = current_user.todos.
where('contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', false, 'active').
@not_done_todos = current_user.todos.active.not_hidden.
reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC").
includes(Todo::DEFAULT_INCLUDES)
end
@ -360,7 +359,7 @@ class TodosController < ApplicationController
end
def edit
@todo = current_user.todos.find_by_id(params['id']).includes(Todo::DEFAULT_INCLUDES)
@todo = current_user.todos.find(params['id'])
@source_view = params['_source_view'] || 'todo'
@tag_name = params['_tag_name']
respond_to do |format|

View file

@ -447,7 +447,7 @@ module TodosHelper
}
page.todo { container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0 }
end
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);"
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);".html_safe
end
def render_animation(animation)

View file

@ -433,7 +433,7 @@ class RecurringTodo < ActiveRecord::Base
end
else
if self.every_other2>1
n_months = "#{self.every_other2} " + I18n.t('common.months')
n_months = "#{self.every_other2} #{I18n.t('common.months')}"
else
n_months = I18n.t('common.month')
end

View file

@ -3,7 +3,6 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%= stylesheet_link_tag "scaffold" %>
<%= javascript_include_tag 'jquery-1.7.1.min', 'jquery.cookie' %>
<title><%= @page_title -%></title>

View file

@ -24,7 +24,7 @@
setup_periodic_check("<%=check_deferred_todos_path(:format => 'js')%>", 10*60, 'POST');
<%= generate_i18n_strings %>
</script>
<link rel="shortcut icon" href="<%= url_for(:controller => 'favicon.ico') %>" />
<link rel="shortcut icon" href="<%= image_path ('favicon.ico') %>" />
<%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => t('layouts.next_actions_rss_feed')}) %>
<link rel="search" type="application/opensearchdescription+xml" title="Tracks" href="<%= search_plugin_path %>" />
<title><%= @page_title %></title>
@ -48,7 +48,7 @@
&nbsp;|&nbsp;
<%= link_to(t('layouts.toggle_notes'), "#", {:accesskey => "S", :title => t('layouts.toggle_notes_title'), :id => "toggle-notes-nav"}) %>
&nbsp;|&nbsp;
<%= link_to( t('common.logout') + " (#{current_user.display_name}) »", logout_path) %>
<%= link_to("#{t('common.logout')} (#{current_user.display_name}) &raquo;".html_safe, logout_path) %>
</div>
<div id="navcontainer">
<ul class="sf-menu">

View file

@ -1,16 +1,9 @@
<% auth_schemes = Tracks::Config.auth_schemes
show_database_form = auth_schemes.include?('database') || auth_schemes.include?('ldap')
show_openid_form = auth_schemes.include?('open_id')
show_cas_form = auth_schemes.include?('cas')
-%>
<div title="<%= t('login.account_login') %>" id="loginform" class="form">
<%= render_flash %>
<h3><%= t('login.please_login') %>:</h3>
<% if show_database_form %>
<div id="database_auth_form" style="display:<%=(@prefered_auth.eql?('database')) ? "block" : "none"%>">
<div id="database_auth_form" style="display:block">
<%= form_tag :action=> 'login' do %>
<table>
<tr>
@ -27,111 +20,9 @@
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %> &#187;" class="primary" /></td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %>" class="primary" /></td>
</tr>
</table>
<% end %>
</div>
<% end %>
<% if show_openid_form %>
<div id="openid_auth_form" style="display:<%=(@prefered_auth.eql?('openid')) ? "block" : "none"%>">
<%= form_tag :action=> 'login' do %>
<table>
<tr>
<td><label for="openid_url"><%= User.human_attribute_name('open_id_url') %>:</label></td>
<td><input type="text" name="openid_url" id="openid_url" value="<%= @openid_url %>" class="login_text open_id" /></td>
</tr>
<tr>
<td><label for="user_noexpiry"><%= t('login.user_no_expiry') %>:</label></td>
<td><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %> &#187;" class="primary" /></td>
</tr>
</table>
<% end %>
</div>
<% end %>
<% if show_cas_form %>
<div id="cas_auth_form" style="display:<%=(@prefered_auth.eql?('cas')) ? "block" : "none"%>">
<table>
<tr>
<td>
<% if @username && @user%>
<p><%= t('login.cas_logged_in_greeting', :username => @username) %></p>
<% elsif @username %>
<p><%= t('login.cas_no_user_found', :username => @username) %>
<%if SITE_CONFIG['open_signups']%>
<%= t('login.cas_create_account', :signup_link => link_to(t('login.cas_signup_link'), signup_url)) %>
<%end%>
</p>
<% else %>
<p><%= link_to(t('login.cas_login'), login_cas_url) %> </p>
<% end %>
</td>
</tr>
</table>
</div>
<% end %>
</div>
<% if show_openid_form %><p id="alternate_auth_openid" class="alternate_auth"><%= t('login.option_separator') %> <a href="#" onclick="Login.showOpenid();return false;"><%= t('login.login_with_openid') %></a></p><% end %>
<% if show_database_form %><p id="alternate_auth_database" class="alternate_auth"><%= t('login.option_separator') %> <a href="#" onclick="Login.showDatabase();return false;"><%= t('login.login_standard') %></a></p><% end %>
<% if show_cas_form %><p id="alternate_auth_cas" class="alternate_auth"><%= t('login.option_separator') %> <a href="#" onclick="Login.showCAS();return false;"><%= t('login.login_cas')%></a></p><% end %>
<script type="text/javascript">
function showPreferredAuth() {
var preferredAuth = $.cookie('preferred_auth');
var casEnabled = <%= show_cas_form ? 'true' : 'false' %>;
var databaseEnabled = <%= show_database_form ? 'true' : 'false' %>;
var openidEnabled = <%= show_openid_form ? 'true' : 'false' %>;
if (preferredAuth && preferredAuth == 'openid' && openidEnabled) {
Login.showOpenid();
}
else if (preferredAuth && preferredAuth == 'database' && databaseEnabled) {
Login.showDatabase();
}
else if (preferredAuth && preferredAuth == 'cas' && casEnabled) {
Login.showCAS();
}
}
$(document).ready(showPreferredAuth);
var Login = {
showOpenid: function() {
$('#database_auth_form').hide();
$('#openid_auth_form').show();
$('#alternate_auth_openid').hide();
$('#alternate_auth_database').show(); ;
$('#alternate_auth_cas').show();
$('#openid_url').focus();
$('#openid_url').select();
$.cookie('preferred_auth', 'openid');
},
showDatabase: function(container) {
$('#openid_auth_form').hide();
$('#database_auth_form').show();
$('#alternate_auth_database').hide();
$('#alternate_auth_openid').show();
$('#alternate_auth_cas').show();
$('#user_login').focus();
$('#user_login').select();
$.cookie('preferred_auth', 'database');
},
showCAS: function(container) {
$('#database_auth_form').hide();
$('#openid_auth_form').hide();
$('#cas_auth_form').show();
$('#alternate_auth_cas').hide();
$('#alternate_auth_openid').show();
$('#alternate_auth_database').show();
$.cookie('preferred_auth', 'cas');
}
}
</script>

View file

@ -2,7 +2,7 @@
<div class="container">
<h2><%= t('todos.calendar.due_today') %></h2>
<div id="empty_due_today" <%= "style=\"display:none\"" unless @due_today.empty? %>>
<div id="empty_due_today" <%= raw "style=\"display:none\"" unless @due_today.empty? %>>
<%= t('todos.calendar.no_actions_due_today') %>
</div>
<div id="due_today">
@ -12,7 +12,7 @@
<div class="container">
<h2><%= t('todos.calendar.due_this_week') %></h2>
<div id="empty_due_this_week" <%= "style=\"display:none\"" unless @due_this_week.empty? %>>
<div id="empty_due_this_week" <%= raw "style=\"display:none\"" unless @due_this_week.empty? %>>
<%= t('todos.no_actions_due_this_week') %>
</div>
<div id="due_this_week">
@ -22,7 +22,7 @@
<div class="container">
<h2><%= t('todos.calendar.due_next_week') %></h2>
<div id="empty_due_next_week" <%= "style=\"display:none\"" unless @due_next_week.empty? %>>
<div id="empty_due_next_week" <%= raw "style=\"display:none\"" unless @due_next_week.empty? %>>
<%= t('todos.calendar.no_actions_due_next_week') %>
</div>
<div id="due_next_week">
@ -32,7 +32,7 @@
<div class="container">
<h2><%= t('todos.calendar.due_this_month', :month => l(Time.zone.now, :format => "%B")) %></h2>
<div id="empty_due_this_month" <%= "style=\"display:none\"" unless @due_this_month.empty? %>>
<div id="empty_due_this_month" <%= raw "style=\"display:none\"" unless @due_this_month.empty? %>>
<%= t('todos.calendar.no_actions_due_this_month') %>
</div>
<div id="due_this_month">
@ -42,7 +42,7 @@
<div class="container">
<h2><%= t('todos.calendar.due_next_month_and_later', :month => l(Time.zone.now+1.month, :format => "%B")) %></h2>
<div id="empty_due_after_this_month" <%= "style=\"display:none\"" unless @due_after_this_month.empty? %>>
<div id="empty_due_after_this_month" <%= raw "style=\"display:none\"" unless @due_after_this_month.empty? %>>
<%= t('todos.calendar.no_actions_due_after_this_month') %>
</div>
<div id="due_after_this_month">
@ -52,6 +52,6 @@
</div><!-- End of display_box -->
<div class="input_box" id="input_box">
<p><%= link_to('<span class="feed">iCal</span>', {:format => 'ics', :token => current_user.token}, :title => "iCal feed" ) %>
<p><%= link_to('<span class="feed">iCal</span>'.html_safe, {:format => 'ics', :token => current_user.token}, :title => "iCal feed" ) %>
- <%= t('todos.calendar.get_in_ical_format') %></p>
</div>

View file

@ -57,7 +57,7 @@ function update_predecessors() {
}
function html_for_error_messages() {
return "<%= escape_javascript(error_messages_for('todo', :object_name => 'action')) %>";
return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>";
}
function html_for_new_context() {

View file

@ -1,17 +1,15 @@
<div id="display_box">
<div id="no_todos_in_view" class="container context" style="display:<%= @not_done_todos.empty? ? "block" : "none" %>">
<h2><%= t('todos.no_actions_found_title')%></h2>
<h2><%= t('todos.no_actions_found_title')%></h2>
<div class="message"><p><%= t('todos.no_actions_found') %></p></div>
</div>
<%= render(:partial => @contexts_to_show, :locals => { :collapsible => true }) -%>
<% unless @done.nil? -%>
<%= render(
:partial => "todos/completed",
:object => @done,
:locals => { :collapsible => true, :append_descriptor => nil }) -%>
<%= render(:partial => "todos/completed", :object => @done,
:locals => { :collapsible => true, :append_descriptor => nil }) -%>
<% end -%>
</div><!-- End of display_box -->
</div>
<div id="input_box">
<%= render :partial => "shared/add_new_item_form" %>
<%= render :file => "sidebar/sidebar" %>
</div><!-- End of input box -->
</div>

70
backup.rails2.3/env.rb Normal file
View file

@ -0,0 +1,70 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
# require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'aruba/cucumber'
require 'capybara/rails'
require 'capybara/cucumber'
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.javascript_driver = ENV["JS_DRIVER"] ? ENV["JS_DRIVER"].to_sym : :selenium
if Capybara.javascript_driver == :webkit
require 'capybara/webkit'
end
# 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
# steps to use the XPath syntax.
Capybara.default_selector = :css
Capybara.prefer_visible_elements = true
# If you set this to false, any error raised from within your app will bubble
# up to your step definition and out to cucumber unless you catch it somewhere
# on the way. You can make Rails rescue errors and render error pages on a
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
#
# If you set this to true, Rails will rescue all errors and render error
# pages, more or less in the same way your application would behave in the
# default production environment. It's not recommended to do this for all
# of your scenarios, as this makes it hard to discover errors in your application.
ActionController::Base.allow_rescue = false
# If you set this to true, each scenario will run in a database transaction.
# You can still turn off transactions on a per-scenario basis, simply tagging
# a feature or scenario with the @no-txn tag. If you are using Capybara,
# tagging with @culerity or @javascript will also turn transactions off.
#
# If you set this to false, transactions will be off for all scenarios,
# regardless of whether you use @no-txn or not.
#
# Beware that turning transactions off will leave data in your database
# after each scenario, which can lead to hard-to-debug failures in
# 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)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end

View file

@ -69,5 +69,6 @@ module Tracksapp
# allow onenote:// and message:// as protocols for urls
config.action_view.sanitized_allowed_protocols = 'onenote', 'message'
end
end

View file

@ -1,8 +1,8 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:15 --wip features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip

View file

@ -1,5 +1,8 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
# Initialize the rails application
Tracksapp::Application.initialize!

View file

@ -6,7 +6,7 @@ end
Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
user = User.find_by_login(login)
user.should_not be_nil
@context = user.contexts.find_or_create(:name => context_name, :hide => false)
@context = user.contexts.find_or_create_by_name(:name => context_name, :hide => false)
end
Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|

View file

@ -3,7 +3,7 @@ Given /^I have logged in as "(.*)" with password "(.*)"$/ do |username, password
fill_in "Login", :with => username
fill_in "Password", :with => password
uncheck "Stay logged in:"
click_button "Sign in »"
click_button "Sign in"
logout_regexp = @mobile_interface ? "Logout" : "Logout \(#{username}\)"
page.should have_content(logout_regexp)
@ -14,7 +14,7 @@ When /^I submit the login form as user "([^\"]*)" with password "([^\"]*)"$/ do
fill_in 'Login', :with => username
fill_in 'Password', :with => password
uncheck "Stay logged in:"
click_button "Sign in »"
click_button "Sign in"
end
When /^my session expires$/ do

View file

@ -14,7 +14,7 @@ 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(:name => context_name)
context = @current_user.contexts.find_or_create_by_name(context_name)
@todo = @current_user.todos.create!(:context_id => context.id, :description => description)
@todo.due = @todo.created_at + 1.day
@todo.save!

View file

@ -1,7 +1,7 @@
Given /^the following user records?$/ do |table|
User.delete_all
table.hashes.each do |hash|
user = Factory(:user, hash)
user = FactoryGirl.create(:user, hash)
user.create_preference({:locale => 'en'})
end
end

View file

@ -4,27 +4,7 @@
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'aruba/cucumber'
require 'capybara/rails'
require 'capybara/cucumber'
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.javascript_driver = ENV["JS_DRIVER"] ? ENV["JS_DRIVER"].to_sym : :selenium
if Capybara.javascript_driver == :webkit
require 'capybara/webkit'
end
require 'cucumber/rails'
# 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
@ -32,39 +12,48 @@ end
# steps to use the XPath syntax.
Capybara.default_selector = :css
Capybara.prefer_visible_elements = true
# If you set this to false, any error raised from within your app will bubble
# up to your step definition and out to cucumber unless you catch it somewhere
# on the way. You can make Rails rescue errors and render error pages on a
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
# By default, any exception happening in your Rails application will bubble up
# to Cucumber so that your scenario will fail. This is a different from how
# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
# exceptions and display an error page (just like when the app is running in production).
# Typical scenarios where you want to do this is when you test your error pages.
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with @allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
#
# If you set this to true, Rails will rescue all errors and render error
# pages, more or less in the same way your application would behave in the
# default production environment. It's not recommended to do this for all
# of your scenarios, as this makes it hard to discover errors in your application.
ActionController::Base.allow_rescue = false
# If you set this to true, each scenario will run in a database transaction.
# You can still turn off transactions on a per-scenario basis, simply tagging
# a feature or scenario with the @no-txn tag. If you are using Capybara,
# tagging with @culerity or @javascript will also turn transactions off.
#
# If you set this to false, transactions will be off for all scenarios,
# regardless of whether you use @no-txn or not.
#
# Beware that turning transactions off will leave data in your database
# after each scenario, which can lead to hard-to-debug failures in
# 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)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
# # { :except => [:widgets] } may not do what you expect here
# # as tCucumber::Rails::Database.javascript_strategy overrides
# # this setting.
# DatabaseCleaner.strategy = :truncation
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
# DatabaseCleaner.strategy = :transaction
# end
#
# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation

View file

@ -0,0 +1,23 @@
FactoryGirl.define do
factory :user do
sequence(:login) { |n| "testuser#{n}" }
password "secret"
password_confirmation { |user| user.password }
is_admin false
end
factory :context do
sequence(:name) { |n| "testcontext#{n}" }
hide false
created_at Time.now.utc
end
factory :project do
sequence(:name) { |n| "testproject#{n}" }
end
factory :todo do
sequence(:description) { |n| "testtodo#{n}" }
association :context
end
end

View file

@ -1,2 +1,2 @@
require 'factory_girl'
Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/*.rb')).each {|f| require f }
# require 'factory_girl'
# Dir.glob(File.join(File.dirname(__FILE__), 'factories/*.rb')).each {|f| require f }

View file

@ -0,0 +1,13 @@
require 'aruba/cucumber'
require 'capybara/rails'
require 'capybara/cucumber'
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.javascript_driver = ENV["JS_DRIVER"] ? ENV["JS_DRIVER"].to_sym : :selenium
if Capybara.javascript_driver == :webkit
require 'capybara/webkit'
end

65
lib/tasks/cucumber.rake Normal file
View file

@ -0,0 +1,65 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
end
desc 'Run all features'
task :all => [:ok, :wip]
task :statsetup do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
end
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'
task :default => :cucumber
task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
task 'db:test:prepare' do
end
task :stats => 'cucumber:statsetup'
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end
end

View file

@ -1,10 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class TodosControllerTest < ActionController::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings, :recurring_todos
def setup
end
def test_get_index_when_not_logged_in
get :index
@ -129,6 +125,20 @@ class TodosControllerTest < ActionController::TestCase
end
end
def test_create_todo_via_xhr
login_as(:admin_user)
assert_difference 'Todo.count' do
xhr :put, :create, "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
assert_response 200
end
end
def test_get_edit_form_using_xhr
login_as(:admin_user)
xhr :get, :edit, :id => todos(:call_bill).id
assert_response 200
end
def test_fail_to_create_todo_via_xml
login_as(:admin_user)
# try to create with no context, which is not valid