Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Swith to RSpec and added few unit tests

  • Loading branch information...
commit a9071bf2be0ac2ee5046a54976cb81c11038c42d 1 parent f6755ac
@romul authored
View
3  .gitignore
@@ -8,5 +8,4 @@ tmp
nbproject
*.swp
*.bak
-spec/test_app
-Gemfile
+spec/dummy
View
3  .rspec
@@ -0,0 +1,3 @@
+--color
+--format
+progress
View
6 Gemfile
@@ -0,0 +1,6 @@
+source "http://rubygems.org"
+
+gemspec
+
+gem 'spree', '~> 1.0.0'
+gem 'sqlite3'
View
228 Gemfile.lock
@@ -0,0 +1,228 @@
+PATH
+ remote: .
+ specs:
+ spree_address_book (1.0.0.rc)
+ spree_auth (~> 1.0.0)
+ spree_core (~> 1.0.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.4)
+ actionpack (= 3.1.4)
+ mail (~> 2.3.0)
+ actionpack (3.1.4)
+ activemodel (= 3.1.4)
+ activesupport (= 3.1.4)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.6)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ active_utils (1.0.3)
+ activesupport (>= 2.3.11)
+ i18n
+ activemerchant (1.20.1)
+ active_utils (>= 1.0.1)
+ activesupport (>= 2.3.11)
+ braintree (>= 2.0.0)
+ builder (>= 2.0.0)
+ i18n
+ json (>= 1.5.1)
+ money (<= 3.7.1)
+ activemodel (3.1.4)
+ activesupport (= 3.1.4)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.4)
+ activemodel (= 3.1.4)
+ activesupport (= 3.1.4)
+ arel (~> 2.2.3)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.4)
+ activemodel (= 3.1.4)
+ activesupport (= 3.1.4)
+ activesupport (3.1.4)
+ multi_json (~> 1.0)
+ acts_as_list (0.1.4)
+ arel (2.2.3)
+ bcrypt-ruby (3.0.1)
+ braintree (2.15.0)
+ builder (>= 2.0.0)
+ builder (3.0.0)
+ cancan (1.6.7)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
+ cocaine (0.2.1)
+ deface (0.8.0)
+ nokogiri (~> 1.5.0)
+ rails (>= 3.0.9)
+ devise (1.4.8)
+ bcrypt-ruby (~> 3.0)
+ orm_adapter (~> 0.0.3)
+ warden (~> 1.0.3)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ factory_girl (2.6.0)
+ activesupport (>= 2.3.9)
+ ffaker (1.12.1)
+ ffi (1.0.11)
+ highline (1.6.8)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.6)
+ json_pure (1.6.5)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
+ mail (2.3.3)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ meta_search (1.1.1)
+ actionpack (~> 3.1.0)
+ activerecord (~> 3.1.0)
+ activesupport (~> 3.1.0)
+ polyamorous (~> 0.5.0)
+ mime-types (1.18)
+ money (3.7.1)
+ i18n (~> 0.4)
+ multi_json (1.2.0)
+ nested_set (1.6.8)
+ activerecord (>= 3.0.0)
+ railties (>= 3.0.0)
+ nokogiri (1.5.2)
+ orm_adapter (0.0.7)
+ paperclip (2.5.0)
+ activerecord (>= 2.3.0)
+ activesupport (>= 2.3.2)
+ cocaine (>= 0.0.2)
+ mime-types
+ polyamorous (0.5.0)
+ activerecord (~> 3.0)
+ polyglot (0.3.3)
+ rack (1.3.6)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.4)
+ actionmailer (= 3.1.4)
+ actionpack (= 3.1.4)
+ activerecord (= 3.1.4)
+ activeresource (= 3.1.4)
+ activesupport (= 3.1.4)
+ bundler (~> 1.0)
+ railties (= 3.1.4)
+ railties (3.1.4)
+ actionpack (= 3.1.4)
+ activesupport (= 3.1.4)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
+ rubyzip (0.9.6.1)
+ selenium-webdriver (2.12.2)
+ childprocess (>= 0.2.1)
+ ffi (~> 1.0.9)
+ json_pure
+ rubyzip
+ spree (1.0.3)
+ spree_api (= 1.0.3)
+ spree_auth (= 1.0.3)
+ spree_cmd (= 1.0.3)
+ spree_core (= 1.0.3)
+ spree_dash (= 1.0.3)
+ spree_promo (= 1.0.3)
+ spree_sample (= 1.0.3)
+ spree_api (1.0.3)
+ spree_auth (= 1.0.3)
+ spree_core (= 1.0.3)
+ spree_auth (1.0.3)
+ cancan (= 1.6.7)
+ devise (= 1.4.8)
+ spree_core (= 1.0.3)
+ spree_cmd (1.0.3)
+ spree_core (1.0.3)
+ activemerchant (= 1.20.1)
+ acts_as_list (= 0.1.4)
+ deface (>= 0.7.2)
+ ffaker (~> 1.12.0)
+ highline (= 1.6.8)
+ jquery-rails (>= 1.0.18, <= 1.0.19)
+ kaminari (>= 0.13.0)
+ meta_search (= 1.1.1)
+ nested_set (= 1.6.8)
+ paperclip (= 2.5.0)
+ rails (>= 3.1.1, <= 3.1.4)
+ state_machine (= 1.1.1)
+ stringex (~> 1.3.0)
+ spree_dash (1.0.3)
+ spree_core (= 1.0.3)
+ spree_promo (1.0.3)
+ spree_auth (= 1.0.3)
+ spree_core (= 1.0.3)
+ spree_sample (1.0.3)
+ spree_core (= 1.0.3)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
+ state_machine (1.1.1)
+ stringex (1.3.2)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+ warden (1.0.6)
+ rack (>= 1.0)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ factory_girl (~> 2.6)
+ rspec-rails (~> 2.7)
+ spree (~> 1.0.0)
+ spree_address_book!
+ sqlite3
View
66 Rakefile
@@ -1,30 +1,18 @@
-require 'rubygems'
+# encoding: utf-8
require 'rake'
require 'rake/testtask'
+require 'rake/packagetask'
require 'rubygems/package_task'
+require 'rspec/core/rake_task'
+require 'spree/core/testing_support/common_rake'
-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
+RSpec::Core::RakeTask.new
- 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 ]
+task :default => [:spec]
spec = eval(File.read('spree_address_book.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
@@ -35,42 +23,8 @@ task :release => :package do
Rake::Task['gem:push'].invoke
end
-desc "Default Task"
-task :default => [ :spec ]
-
-desc "Regenerates a rails 3 app for testing"
+desc "Generates a dummy app for testing"
task :test_app do
- require '../spree/lib/generators/spree/test_app_generator'
- class AddressBookTestAppGenerator < Spree::Generators::TestAppGenerator
-
- 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
- AddressBookTestAppGenerator.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
+ ENV['LIB_NAME'] = 'spree_address_book'
+ Rake::Task['common:test_app'].invoke
end
View
4 app/models/order_decorator.rb
@@ -17,7 +17,7 @@ def clone_billing_address
end
def bill_address_id=(id)
- address = Spree::Address.find(id)
+ address = Spree::Address.where(:id => id).first
if address && address.user_id == self.user_id
self["bill_address_id"] = address.id
self.bill_address.reload
@@ -31,7 +31,7 @@ def bill_address_attributes=(attributes)
end
def ship_address_id=(id)
- address = Spree::Address.find(id)
+ address = Spree::Address.where(:id => id).first
if address && address.user_id == self.user_id
self["ship_address_id"] = address.id
self.ship_address.reload
View
25 features/support/env.rb
@@ -1,22 +1,3 @@
-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
-
+require File.expand_path("../../../spec/dummy/config/environment.rb", __FILE__)
+require 'spree/core/testing_support/factories'
+require 'spree/core/testing_support/env'
View
4 spec/models/address_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
-describe Address do
+describe Spree::Address do
end
View
21 spec/models/order_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe Spree::Order do
+
+ describe "Create order with the same bill & ship addresses" do
+ it "should have equal ids when set ids" do
+ address = Factory(:address)
+ @order = Factory(:order, :bill_address_id => address.id, :ship_address_id => address.id)
+ @order.bill_address_id.should == @order.ship_address_id
+ end
+
+ it "should have equal ids when option use_billing is active" do
+ address = Factory(:address)
+ @order = Factory(:order, :use_billing => true,
+ :bill_address_id => address.id,
+ :ship_address_id => nil)
+ @order = @order.reload
+ @order.bill_address_id.should == @order.ship_address_id
+ end
+ end
+end
View
25 spec/spec_helper.rb
@@ -1,14 +1,19 @@
-# 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("../test_app/config/environment", __FILE__)
+# Configure Rails Environment
+ENV["RAILS_ENV"] ||= "test"
+
+require File.expand_path("../dummy/config/environment.rb", __FILE__)
+
require 'rspec/rails'
-# Requires supporting files with custom matchers and macros, etc,
-# in ./support/ and its subdirectories.
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
-require 'spree_core/testing_support/factories'
+# Requires factories defined in spree_core
+require 'spree/core/testing_support/factories'
+require 'spree/core/testing_support/env'
+
+require 'ffaker'
RSpec.configure do |config|
# == Mock Framework
@@ -20,6 +25,7 @@
# config.mock_with :rr
config.mock_with :rspec
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
#config.include Devise::TestHelpers, :type => :controller
@@ -27,6 +33,5 @@
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
+
end
-
-@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
View
5 spree_address_book.gemspec
@@ -18,4 +18,9 @@ Gem::Specification.new do |s|
s.add_dependency('spree_core', '~> 1.0.0')
s.add_dependency('spree_auth', '~> 1.0.0')
+
+ s.add_development_dependency('rspec-rails', '~> 2.7')
+ s.add_development_dependency('sqlite3')
+ s.add_development_dependency('capybara')
+ s.add_development_dependency('factory_girl', '~> 2.6')
end
Please sign in to comment.
Something went wrong with that request. Please try again.