Skip to content

Commit

Permalink
Added selenium, cucumber, and webrat
Browse files Browse the repository at this point in the history
  • Loading branch information
Shereef Bishay committed Nov 16, 2009
1 parent 6e2a5c0 commit 368570d
Show file tree
Hide file tree
Showing 28 changed files with 328 additions and 24 deletions.
1 change: 0 additions & 1 deletion Rakefile
Expand Up @@ -6,5 +6,4 @@ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
2 changes: 2 additions & 0 deletions app/controllers/members_controller.rb
Expand Up @@ -8,9 +8,11 @@ class MembersController < ApplicationController
before_filter :authorize

def new
logger.info(params.inspect)
members = []
if params[:member] && request.post?
attrs = params[:member].dup
logger.info("Attrs: #{attrs.inspect}")
if (user_ids = attrs.delete(:user_ids))
user_ids.each do |user_id|
members << Member.new(attrs.merge(:user_id => user_id))
Expand Down
13 changes: 7 additions & 6 deletions app/models/issue.rb
Expand Up @@ -36,7 +36,7 @@ class Issue < ActiveRecord::Base
acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
:author_key => :author_id

validates_presence_of :subject, :priority, :project, :tracker, :author, :status
validates_presence_of :subject, :project, :tracker, :author, :status #,:priority,
validates_length_of :subject, :maximum => 255
validates_inclusion_of :done_ratio, :in => 0..100
validates_numericality_of :estimated_hours, :allow_nil => true
Expand All @@ -57,7 +57,7 @@ def after_initialize
if new_record?
# set default values for new records only
self.status ||= IssueStatus.default
self.priority ||= IssuePriority.default
# self.priority ||= IssuePriority.default
end
end

Expand Down Expand Up @@ -134,10 +134,11 @@ def validate
errors.add :start_date, :invalid
end
end

def validate_on_create
errors.add :tracker_id, :invalid unless project.trackers.include?(tracker)
end

# Commenting this since on bettermeans all projects will have same trackers
# def validate_on_create
# errors.add :tracker_id, :invalid unless project.trackers.include?(tracker)
# end

def before_create
# default assignment based on category
Expand Down
2 changes: 1 addition & 1 deletion app/views/mailer/_issue_text_html.rhtml
Expand Up @@ -3,7 +3,7 @@
<ul>
<li><%=l(:field_author)%>: <%= issue.author %></li>
<li><%=l(:field_status)%>: <%= issue.status %></li>
<li><%=l(:field_priority)%>: <%= issue.priority %></li>
<!-- <li><%#=l(:field_priority)%>: <%#= issue.priority %></li> -->
<li><%=l(:field_assigned_to)%>: <%= issue.assigned_to %></li>
<li><%=l(:field_category)%>: <%= issue.category %></li>
<li><%=l(:field_fixed_version)%>: <%= issue.fixed_version %></li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/mailer/_issue_text_plain.rhtml
Expand Up @@ -3,7 +3,7 @@
<%=l(:field_author)%>: <%= issue.author %>
<%=l(:field_status)%>: <%= issue.status %>
<%=l(:field_priority)%>: <%= issue.priority %>
<!-- <%#=l(:field_priority)%>: <%#= issue.priority %> -->
<%=l(:field_assigned_to)%>: <%= issue.assigned_to %>
<%=l(:field_category)%>: <%= issue.category %>
<%=l(:field_fixed_version)%>: <%= issue.fixed_version %>
Expand Down
6 changes: 5 additions & 1 deletion config/database.yml
Expand Up @@ -53,4 +53,8 @@ demo:


cucumber:
<<: *TEST
<<: *TEST

selenium:
<<: *TEST

5 changes: 5 additions & 0 deletions config/environments/cucumber.rb
Expand Up @@ -24,3 +24,8 @@
config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))

require 'rubygems'
require 'factory_girl'

gem 'pickle'

31 changes: 31 additions & 0 deletions config/environments/selenium.rb
@@ -0,0 +1,31 @@
# IMPORTANT: This file was generated by Cucumber 0.4.3
# Edit at your own peril - it's recommended to regenerate this file
# in the future when you upgrade to a newer version of Cucumber.

config.cache_classes = true # This must be true for Cucumber to operate correctly!

# 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

config.gem 'cucumber', :lib => false, :version => '>=0.4.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))

require 'rubygems'
require 'factory_girl'

gem 'pickle'

3 changes: 2 additions & 1 deletion config/environments/test.rb
Expand Up @@ -27,4 +27,5 @@
config.gem "rspec", :lib => false, :version => ">=1.2.2"
config.gem "rspec-rails", :lib => false, :version => ">=1.2.2"
config.gem "webrat", :lib => false, :version => ">=0.4.3"
config.gem "cucumber", :lib => false, :version => ">=0.3.0"
config.gem "cucumber", :lib => false, :version => ">=0.3.0"
config.gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => "http://gems.github.com"
7 changes: 6 additions & 1 deletion config/exceptional.yml
Expand Up @@ -37,4 +37,9 @@ staging:
cucumber:
<<: *default_settings
# No reason to collect exceptions when running cucmber tests by default
enabled: false
enabled: false

selenium:
<<: *default_settings
# No reason to collect exceptions when running cucmber tests by default
enabled: false
6 changes: 4 additions & 2 deletions config/routes.rb
@@ -1,6 +1,4 @@
ActionController::Routing::Routes.draw do |map|
map.resources :notifications


# map.connect 'commit_requests/createdialgoue', :action => 'createdialogue', :controller => 'commit_requesets'

Expand Down Expand Up @@ -281,6 +279,10 @@
mv.resources :votes
end
end

map.resources :notifications
map.resources :projects
map.resources :issues

# Install the default route as the lowest priority.
map.connect ':controller/:action/:id'
Expand Down
6 changes: 5 additions & 1 deletion config/s3.yml
Expand Up @@ -17,4 +17,8 @@ test: &TEST
cname_bucket: false

cucumber:
<<: *TEST
<<: *TEST

selenium:
<<: *TEST

2 changes: 2 additions & 0 deletions cucumber.yml
@@ -0,0 +1,2 @@
default: --tags ~@selenium -r features/support/env.rb -r features/step_definitions features
selenium: --tags @selenium -r features/support/env.rb -r features/support/selenium.rb -r features/step_definitions features
2 changes: 1 addition & 1 deletion db/migrate/20091107051307_create_mails.rb
Expand Up @@ -11,6 +11,6 @@ def self.up
end

def self.down
drop_table mails
drop_table :mails
end
end
40 changes: 36 additions & 4 deletions features/ownership_offer.feature
@@ -1,13 +1,45 @@
# @no-txn
Feature: Ownership offer
In order to ask others to work with me
As a core team member
I want to offer ownership of an issue to someone else

Background:
Given the following users exist
| login | password | firstname | lastname | admin |
| shereef | shereef | shereef | bishay | true |
| karim | shereef | karim | bishay | false |


Given a project "myproject" exists with name: "Workstream1"
And an issue exists with subject: "My issue", project: project "myproject"

@selenium
Scenario: Make an offer for ownership
Given I am logged in
And Karim is a user
When event
Then outcome
Given I am logged in as shereef
When I go to the show page for that project
Then I should see "Workstream1" in "h1"
When I follow "Items"
Then I should see "My issue"
Given karim is a Core Member of project "Workstream1"
And I am a Core Member of project "Workstream1"
When I follow "My issue"
Then I should see "Offer Ownership"
When I follow "Offer Ownership"
Then I should see "Choose someone"
When I select "karim bishay" from "responder_id"
And I press "Offer Ownership"
Then I should see "Recind ownership"


# And I add an issue called "First issue" to the project called "Workstream1"
#Given I go to the show page for that issue
# Then I should see "First issue"
# And the project "Workstream 1" exists
# And the issue "Very important issue" exists
# And the issue "Not as important issue" exists
# When I offer "Very important task" to "Karim"
# Then I should see ""



Expand Down
50 changes: 50 additions & 0 deletions features/step_definitions/email_steps.rb
@@ -0,0 +1,50 @@
# this file generated by script/generate pickle email

ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true

Before do
ActionMailer::Base.deliveries.clear
end

Given(/^all emails? (?:have|has) been delivered$/) do
ActionMailer::Base.deliveries.clear
end

Given(/^(\d)+ emails? should be delivered$/) do |count|
emails.size.should == count.to_i
end

Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
to =~ /^#{capture_model}$/ && to = model($1).email
emails("to: \"#{to}\"").size.should == count.to_i
end

Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
emails(fields).size.should == count.to_i
end

Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
to =~ /^#{capture_model}$/ && to = model($1).email
email(email_ref, "to: \"#{to}\"").should_not be_nil
end

Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
email(email_ref, fields).should_not be_nil
end

Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
email(email_ref).body.should =~ /#{text}/
end

Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
email(email_ref).body.should_not =~ /#{text}/
end

Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
email(email_ref).body.should =~ /#{path_to(page)}/
end

Then(/^show me the emails?$/) do
save_and_open_emails
end
18 changes: 18 additions & 0 deletions features/step_definitions/global_steps.rb
@@ -0,0 +1,18 @@
# Given /^the following (.+) records?$/ do |factory, table|
# # table is a Cucumber::Ast::Table
# table.hashes.each do |hash|
# Factory(factory,hash)
# end
# end
#
Given /^I am logged in as ([^\"]*)$/ do |username|
Then "Login in as #{username} with password #{username}"
end


Given /^Login in as ([^\"]*) with password ([^\"]*)$/ do |username, password|
visit url_for(:controller => 'account', :action => 'login')
fill_in "Login", :with => username
fill_in "Password", :with => password
click_button "Login"
end
11 changes: 11 additions & 0 deletions features/step_definitions/workstream_steps.rb
@@ -0,0 +1,11 @@
Given /^I am a ([^\"]*) of project "([^\"]*)"$/ do |role, project|
Given "#{User.current.login} is a #{role} of project \"#{project}\""
end


Given /([^\"]*) is a ([^\"]*) of project "([^\"]*)"$/ do |user,role, project|
@project = Project.find(:first, :conditions => {:name => project})
@role = Role.find(:first, :conditions => {:name => role})
m = Member.new(:user => User.find(:first, :conditions => {:login => user}), :roles => [@role])
@project.members << m
end
11 changes: 11 additions & 0 deletions features/support/db_cleaner.rb
@@ -0,0 +1,11 @@
# require 'database_cleaner'
# DatabaseCleaner.clean_with :truncation # clean once to ensure clean slate
# DatabaseCleaner.strategy = :truncation
#
# Before('@no-txn') do
# DatabaseCleaner.start
# end
#
# # After('@no-txn') do
# # DatabaseCleaner.clean
# # end
10 changes: 10 additions & 0 deletions features/support/env.rb
Expand Up @@ -8,6 +8,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails/world'


# 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.
Expand Down Expand Up @@ -37,6 +38,13 @@
require 'cucumber/formatter/unicode'
require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
require 'cucumber/rails/rspec'
require "#{Rails.root}/spec/factories"

#require 'db_cleaner.rb'
# require 'database_cleaner'
# require 'database_cleaner/cucumber'
# DatabaseCleaner.strategy = :transaction


require 'webrat'
require 'webrat/core/matchers'
Expand All @@ -52,3 +60,5 @@
# config.adapters = [:machinist]
# config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
# end
require 'pickle/path/world'
require 'pickle/email/world'

0 comments on commit 368570d

Please sign in to comment.