Skip to content
Browse files

Added test infrastructure, started write cukes.

Added few minor improvements.
  • Loading branch information...
1 parent 74e4ab6 commit 496be4b4e900d5480fcfc2ee8630389f397dd133 @romul romul committed Mar 5, 2011
View
2 .gitignore
@@ -8,3 +8,5 @@ tmp
nbproject
*.swp
*.bak
+spec/test_app
+Gemfile
View
62 Rakefile
@@ -1,11 +1,28 @@
-require File.expand_path('../../config/application', __FILE__)
-
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
+gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
+if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
+ require 'bundler'
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ Bundler.setup
+
+ require 'rspec'
+ require 'rspec/core/rake_task'
+ RSpec::Core::RakeTask.new
+
+ require 'cucumber/rake/task'
+ Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = %w{--format progress}
+ end
+end
+
+desc "Default Task"
+task :default => [:spec, :cucumber ]
+
spec = eval(File.read('spree_address_book.gemspec'))
Rake::GemPackageTask.new(spec) do |p|
@@ -22,10 +39,39 @@ end
desc "Default Task"
task :default => [ :spec ]
-require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new
+desc "Regenerates a rails 3 app for testing"
+task :test_app do
+ require '../spree/lib/generators/spree/test_app_generator'
+ class AdvancedCartTestAppGenerator < Spree::Generators::TestAppGenerator
-# require 'cucumber/rake/task'
-# Cucumber::Rake::Task.new do |t|
-# t.cucumber_opts = %w{--format pretty}
-# end
+ def install_gems
+ inside "test_app" do
+ run 'rake spree_core:install'
+ run 'rake spree_auth:install'
+ run 'rake spree_address_book:install'
+ end
+ end
+
+ def migrate_db
+ run_migrations
+ end
+
+ protected
+ def full_path_for_local_gems
+ <<-gems
+gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
+gem 'spree_auth', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "auth")}\'
+gem 'spree_address_book', :path => \'#{File.dirname(__FILE__)}\'
+ gems
+ end
+
+ end
+ AdvancedCartTestAppGenerator.start
+end
+
+namespace :test_app do
+ desc 'Rebuild test and cucumber databases'
+ task :rebuild_dbs do
+ system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
+ end
+end
View
2 app/models/user_decorator.rb
@@ -1,3 +1,3 @@
User.class_eval do
- has_many :addresses
+ has_many :addresses, :conditions => {:deleted_at => nil}
end
View
5 app/views/addresses/_form.html.erb
@@ -1,10 +1,11 @@
<% ["firstname", "lastname", "address1", "address2", "city", "state", "zipcode", "country", "phone"].each do |field| %>
<p id="<%= [address_name, field].join('_') %>" class="field">
- <%= address_form.label field, t(field, :scope => [:activerecord, :attributes, :address]) %>
<% if field == "country" %>
+ <%= address_form.label :country_id, t(field, :scope => [:activerecord, :attributes, :address]) %>
<span><%= address_form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %></span>
<span class="req">*</span>
<% elsif field == "state" && Spree::Config[:address_requires_state] %>
+ <%= address_form.label :state_id, t(field, :scope => [:activerecord, :attributes, :address]) %>
<span id="state">
<% have_states = !address.country.states.empty? %>
<noscript>
@@ -29,8 +30,10 @@
</span>
<span class="req">*</span>
<% elsif field == "address2" %>
+ <%= address_form.label field, t(field, :scope => [:activerecord, :attributes, :address]) %>
<%= address_form.text_field field %>
<% else %>
+ <%= address_form.label field, t(field, :scope => [:activerecord, :attributes, :address]) %>
<%= address_form.text_field field, :class => 'required' %><span class="req">*</span>
<% end %>
</p>
View
12 features/address_book.feature
@@ -0,0 +1,12 @@
+Feature: Address Book
+
+ @selenium
+ Scenario: User fill new address
+ Given an order from registered user "email@person.com/password" at address step
+ When I fill billing address with correct data
+ And I fill shipping address with correct data
+ And press "Save and Continue"
+ Then user "email@person.com" should have 1 address
+ When I choose "UPS Ground" as shipping method and "Check" as payment method
+ Then I should see "Your order has been processed successfully"
+
View
12 features/step_definitions/address_book_steps.rb
@@ -0,0 +1,12 @@
+Given /^an order from registered user "([^"]*)" at address step$/ do |user_data|
+ Given "a shipping method exists"
+ Given "a payment method exists"
+ Given "I am signed up as \"#{user_data}\""
+ Given "I add a product with name: \"RoR Mug\" to cart"
+ Given "I follow \"Checkout\""
+ Given "I sign in as \"email@person.com/password\""
+end
+
+Then /^user "([^"]*)" should have (\d+) address$/ do |email, count|
+ User.find_by_email(email).addresses.count.should == count.to_i
+end
View
22 features/support/env.rb
@@ -0,0 +1,22 @@
+FEATURES_PATH = File.expand_path('../..', __FILE__)
+
+# load shared env with features
+require File.expand_path('../../../../spree/features/support/env', __FILE__)
+
+# load the rest of files for support and step definitions
+directories = [ File.expand_path('../../../../spree/features/support', __FILE__),
+ File.expand_path('../../../../spree/features/step_definitions', __FILE__),
+ File.expand_path('../../../spec/factories', __FILE__) ]
+
+files = directories.map do |dir|
+ Dir["#{dir}/**/*.rb"]
+end.flatten.uniq
+
+files.each do |path|
+ if path !~ /env.rb$/
+ fp = File.expand_path(path)
+ #puts fp
+ load(fp)
+ end
+end
+
View
40 features/support/paths.rb
@@ -0,0 +1,40 @@
+module NavigationHelpers
+ # Maps a name to a path. Used by the
+ #
+ # When /^I go to (.+)$/ do |page_name|
+ #
+ # step definition in web_steps.rb
+ #
+ def path_to(page_name)
+ case page_name
+
+ when "admin promotions page"
+ admin_promotions_path
+ when /the home\s?page/
+ '/'
+ when /the sign in page/
+ new_user_session_path
+ when /the sign up page/
+ new_user_registration_path
+
+ # Add more mappings here.
+ # Here is an example that pulls values out of the Regexp:
+ #
+ # when /^(.*)'s profile page$/i
+ # user_profile_path(User.find_by_login($1))
+
+ else
+ begin
+ page_name =~ /the (.*) page/
+ path_components = $1.split(/\s+/)
+ self.send(path_components.push('path').join('_').to_sym)
+ rescue Object => e
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+ end
+end
+
+World(NavigationHelpers)
+
View
2 spec/spec_helper.rb
@@ -1,7 +1,7 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
-require File.expand_path("../../../config/environment", __FILE__)
+require File.expand_path("../test_app/config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting files with custom matchers and macros, etc,
View
12 spree_address_book.gemspec
@@ -2,20 +2,22 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_address_book'
s.version = '0.40.0'
- s.summary = 'Add gem summary here'
+ s.summary = 'Adds address book for users to Spree'
#s.description = 'Add (optional) gem description here'
s.required_ruby_version = '>= 1.8.7'
- # s.author = 'David Heinemeier Hansson'
- # s.email = 'david@loudthinking.com'
- # s.homepage = 'http://www.rubyonrails.org'
+ s.author = 'Roman Smirnov'
+ s.email = 'roman@railsdog.com'
+ s.homepage = 'http://github.com/romul/spree_address_book'
# s.rubyforge_project = 'actionmailer'
- s.files = Dir['CHANGELOG', 'README.md', 'LICENSE', 'lib/**/*', 'app/**/*', 'db/**/*', 'public/**/*']
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_path = 'lib'
s.requirements << 'none'
s.has_rdoc = true
s.add_dependency('spree_core', '>= 0.40.0')
+ s.add_dependency('spree_auth', '>= 0.40.0')
end

0 comments on commit 496be4b

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