Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added selenium, cucumber, and webrat

  • Loading branch information...
commit 368570d1dee81570156fe2ab02f742650d316026 1 parent 6e2a5c0
Shereef Bishay authored
Showing with 328 additions and 24 deletions.
  1. +0 −1  Rakefile
  2. +2 −0  app/controllers/members_controller.rb
  3. +7 −6 app/models/issue.rb
  4. +1 −1  app/views/mailer/_issue_text_html.rhtml
  5. +1 −1  app/views/mailer/_issue_text_plain.rhtml
  6. +5 −1 config/database.yml
  7. +5 −0 config/environments/cucumber.rb
  8. +31 −0 config/environments/selenium.rb
  9. +2 −1  config/environments/test.rb
  10. +6 −1 config/exceptional.yml
  11. +4 −2 config/routes.rb
  12. +5 −1 config/s3.yml
  13. +2 −0  cucumber.yml
  14. +1 −1  db/migrate/20091107051307_create_mails.rb
  15. +36 −4 features/ownership_offer.feature
  16. +50 −0 features/step_definitions/email_steps.rb
  17. +18 −0 features/step_definitions/global_steps.rb
  18. +11 −0 features/step_definitions/workstream_steps.rb
  19. +11 −0 features/support/db_cleaner.rb
  20. +10 −0 features/support/env.rb
  21. +28 −0 features/support/paths.rb
  22. +18 −0 features/support/selenium.rb
  23. +10 −1 lib/redmine/default_data/loader.rb
  24. +2 −1  lib/tasks/cucumber.rake
  25. +12 −0 lib/tasks/custom.rake
  26. +4 −2 lib/tasks/load_default_data.rake
  27. +45 −0 spec/factories.rb
  28. +1 −0  spec/spec_helper.rb
1  Rakefile
View
@@ -6,5 +6,4 @@ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
-
require 'tasks/rails'
2  app/controllers/members_controller.rb
View
@@ -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))
13 app/models/issue.rb
View
@@ -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
@@ -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
@@ -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
2  app/views/mailer/_issue_text_html.rhtml
View
@@ -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>
2  app/views/mailer/_issue_text_plain.rhtml
View
@@ -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 %>
6 config/database.yml
View
@@ -53,4 +53,8 @@ demo:
cucumber:
- <<: *TEST
+ <<: *TEST
+
+selenium:
+ <<: *TEST
+
5 config/environments/cucumber.rb
View
@@ -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 config/environments/selenium.rb
View
@@ -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  config/environments/test.rb
View
@@ -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 config/exceptional.yml
View
@@ -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 config/routes.rb
View
@@ -1,6 +1,4 @@
ActionController::Routing::Routes.draw do |map|
- map.resources :notifications
-
# map.connect 'commit_requests/createdialgoue', :action => 'createdialogue', :controller => 'commit_requesets'
@@ -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'
6 config/s3.yml
View
@@ -17,4 +17,8 @@ test: &TEST
cname_bucket: false
cucumber:
- <<: *TEST
+ <<: *TEST
+
+selenium:
+ <<: *TEST
+
2  cucumber.yml
View
@@ -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  db/migrate/20091107051307_create_mails.rb
View
@@ -11,6 +11,6 @@ def self.up
end
def self.down
- drop_table mails
+ drop_table :mails
end
end
40 features/ownership_offer.feature
View
@@ -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 ""
50 features/step_definitions/email_steps.rb
View
@@ -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 features/step_definitions/global_steps.rb
View
@@ -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 features/step_definitions/workstream_steps.rb
View
@@ -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 features/support/db_cleaner.rb
View
@@ -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 features/support/env.rb
View
@@ -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.
@@ -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'
@@ -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'
28 features/support/paths.rb
View
@@ -10,6 +10,15 @@ def path_to(page_name)
when /the home\s?page/
'/'
+
+ when /the show page for (.+)/
+ polymorphic_path(model($1))
+
+ when /the login page/
+ '/login'
+
+ when /path "(.+)"/
+ $1
# Add more mappings here.
# Here is a more fancy example:
@@ -17,6 +26,25 @@ def path_to(page_name)
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
+ # added by script/generate pickle path
+
+ when /^#{capture_model}(?:'s)? page$/ # eg. the forum's page
+ path_to_pickle $1
+
+ when /^#{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page
+ path_to_pickle $1, $2
+
+ when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
+ path_to_pickle $1, $2, :extra => $3 # or the forum's post's edit page
+
+ when /^#{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page
+ path_to_pickle $1, :extra => $2 # or the forum's edit page
+
+ when /^the (.+?) page$/ # translate to named route
+ send "#{$1.downcase.gsub(' ','_')}_path"
+
+ # end added by pickle path
+
else
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
18 features/support/selenium.rb
View
@@ -0,0 +1,18 @@
+Webrat.configure do |config|
+ config.mode = :selenium
+ config.application_environment = :selenium
+end
+
+Cucumber::Rails::World.use_transactional_fixtures = false
+
+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
11 lib/redmine/default_data/loader.rb
View
@@ -72,7 +72,16 @@ def load(lang=nil)
contributor.permissions.delete(:delete_wiki_pages)
contributor.permissions.delete(:delete_wiki_pages_attachments)
contributor.permissions.delete(:protect_wiki_pages)
- contributor.save!
+ contributor.save!
+
+ #TODO: Check that built in role aren't in there before creating them
+ @nonmember = Role.new(:name => 'Non member', :position => 0)
+ @nonmember.builtin = Role::BUILTIN_NON_MEMBER
+ @nonmember.save
+
+ @anonymous = Role.new(:name => 'Anonymous', :position => 0)
+ @anonymous.builtin = Role::BUILTIN_ANONYMOUS
+ @anonymous.save
Role.non_member.update_attribute :permissions, contributor.permissions
3  lib/tasks/cucumber.rake
View
@@ -6,12 +6,13 @@ unless ARGV.any? {|a| a =~ /^gems/}
begin
require 'cucumber/rake/task'
+
# Use vendored cucumber binary if possible. If it's not vendored,
# Cucumber::Rake::Task will automatically use installed gem's cucumber binary
vendored_cucumber_binary = Dir["#{RAILS_ROOT}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
namespace :cucumber do
- Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
+ Cucumber::Rake::Task.new({:ok => 'custom:load_test_data'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_binary
t.fork = true # You may get faster startup if you set this to false
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
12 lib/tasks/custom.rake
View
@@ -0,0 +1,12 @@
+namespace :custom do
+ task :load_test_data => :environment do
+ # RAILS_ENV='test'
+ # Rake::Task["db:test:prepare"]
+ system 'rake db:test:prepare'
+ system 'rake environment RAILS_ENV=test redmine:load_default_data'
+ # Rake::Task["redmine:load_default_data"].invoke
+ #Rake::Task["cucumber"].invoke
+ # Redmine::DefaultData::Loader.load('en')
+
+ end
+end
6 lib/tasks/load_default_data.rake
View
@@ -3,9 +3,11 @@ desc 'Load Redmine default configuration data. Language is chosen interactively
namespace :redmine do
task :load_default_data => :environment do
include Redmine::I18n
- set_language_if_valid('en')
+ # set_language_if_valid('en')
+ #
+ # envlang = ENV['REDMINE_LANG']
+ envlang = 'en'
- envlang = ENV['REDMINE_LANG']
if !envlang || !set_language_if_valid(envlang)
puts
while true
45 spec/factories.rb
View
@@ -0,0 +1,45 @@
+Factory.define :project do |f|
+ f.sequence(:name) { |n| "Name of project #{n}" }
+ f.sequence(:identifier) { |n| "workstreamid#{n}" }
+ f.trackers Tracker.all
+ f.is_public true
+ f.enabled_module_names Redmine::AccessControl.available_project_modules
+
+end
+
+Factory.define :user do |f|
+ f.sequence(:login) { |n| "username#{n}" }
+ f.password "password"
+ f.sequence(:mail) { |n| "username#{n}@testing.com" }
+ f.sequence(:firstname) { |n| "first#{n}" }
+ f.sequence(:lastname) { |n| "last#{n}" }
+
+end
+
+Factory.define :tracker do |f|
+ f.sequence(:position) { |n| "#{n}"}
+ f.sequence(:name) { |n| "tracker#{n}"}
+end
+
+Factory.define :issue_status do |f|
+ f.sequence(:name) { |n| "status#{n}"}
+end
+
+Factory.define :issue_priority do |f|
+ f.sequence(:name) { |n| "pri#{n}" }
+end
+
+Factory.define :issue do |f|
+ f.sequence(:subject) { |n| "Subject #{n}"}
+ f.sequence(:description) { |n| "Description #{n}"}
+ f.association :tracker, :factory => :tracker
+ f.association :project, :factory => :project
+ f.association :author, :factory => :user
+ f.association :status, :factory => :issue_status
+ # f.status IssueStatus.find(1)
+ # f.status Factory.attributes_for(:issue_status)
+ f.association :status, :factory => :issue_status
+ f.association :priority, :factory => :issue_priority
+ # f.priority IssuePriority.find(4)
+ # f.priority Factory.attributes_for(:issue_priority)
+end
1  spec/spec_helper.rb
View
@@ -4,6 +4,7 @@
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
require 'spec/autorun'
require 'spec/rails'
+# require File.dirname(__FILE__) + "/factories"
# Uncomment the next line to use webrat's matchers
#require 'webrat/integrations/rspec-rails'
Please sign in to comment.
Something went wrong with that request. Please try again.