Skip to content
This repository
Browse code

Swith to RSpec and added few unit tests

  • Loading branch information...
commit a9071bf2be0ac2ee5046a54976cb81c11038c42d 1 parent f6755ac
Roman Smirnov authored April 17, 2012
3  .gitignore
@@ -8,5 +8,4 @@ tmp
8 8
 nbproject
9 9
 *.swp
10 10
 *.bak
11  
-spec/test_app
12  
-Gemfile
  11
+spec/dummy
3  .rspec
... ...
@@ -0,0 +1,3 @@
  1
+--color
  2
+--format
  3
+progress
6  Gemfile
... ...
@@ -0,0 +1,6 @@
  1
+source "http://rubygems.org"
  2
+
  3
+gemspec
  4
+
  5
+gem 'spree', '~> 1.0.0'
  6
+gem 'sqlite3'
228  Gemfile.lock
... ...
@@ -0,0 +1,228 @@
  1
+PATH
  2
+  remote: .
  3
+  specs:
  4
+    spree_address_book (1.0.0.rc)
  5
+      spree_auth (~> 1.0.0)
  6
+      spree_core (~> 1.0.0)
  7
+
  8
+GEM
  9
+  remote: http://rubygems.org/
  10
+  specs:
  11
+    actionmailer (3.1.4)
  12
+      actionpack (= 3.1.4)
  13
+      mail (~> 2.3.0)
  14
+    actionpack (3.1.4)
  15
+      activemodel (= 3.1.4)
  16
+      activesupport (= 3.1.4)
  17
+      builder (~> 3.0.0)
  18
+      erubis (~> 2.7.0)
  19
+      i18n (~> 0.6)
  20
+      rack (~> 1.3.6)
  21
+      rack-cache (~> 1.1)
  22
+      rack-mount (~> 0.8.2)
  23
+      rack-test (~> 0.6.1)
  24
+      sprockets (~> 2.0.3)
  25
+    active_utils (1.0.3)
  26
+      activesupport (>= 2.3.11)
  27
+      i18n
  28
+    activemerchant (1.20.1)
  29
+      active_utils (>= 1.0.1)
  30
+      activesupport (>= 2.3.11)
  31
+      braintree (>= 2.0.0)
  32
+      builder (>= 2.0.0)
  33
+      i18n
  34
+      json (>= 1.5.1)
  35
+      money (<= 3.7.1)
  36
+    activemodel (3.1.4)
  37
+      activesupport (= 3.1.4)
  38
+      builder (~> 3.0.0)
  39
+      i18n (~> 0.6)
  40
+    activerecord (3.1.4)
  41
+      activemodel (= 3.1.4)
  42
+      activesupport (= 3.1.4)
  43
+      arel (~> 2.2.3)
  44
+      tzinfo (~> 0.3.29)
  45
+    activeresource (3.1.4)
  46
+      activemodel (= 3.1.4)
  47
+      activesupport (= 3.1.4)
  48
+    activesupport (3.1.4)
  49
+      multi_json (~> 1.0)
  50
+    acts_as_list (0.1.4)
  51
+    arel (2.2.3)
  52
+    bcrypt-ruby (3.0.1)
  53
+    braintree (2.15.0)
  54
+      builder (>= 2.0.0)
  55
+    builder (3.0.0)
  56
+    cancan (1.6.7)
  57
+    capybara (1.1.2)
  58
+      mime-types (>= 1.16)
  59
+      nokogiri (>= 1.3.3)
  60
+      rack (>= 1.0.0)
  61
+      rack-test (>= 0.5.4)
  62
+      selenium-webdriver (~> 2.0)
  63
+      xpath (~> 0.1.4)
  64
+    childprocess (0.3.1)
  65
+      ffi (~> 1.0.6)
  66
+    cocaine (0.2.1)
  67
+    deface (0.8.0)
  68
+      nokogiri (~> 1.5.0)
  69
+      rails (>= 3.0.9)
  70
+    devise (1.4.8)
  71
+      bcrypt-ruby (~> 3.0)
  72
+      orm_adapter (~> 0.0.3)
  73
+      warden (~> 1.0.3)
  74
+    diff-lcs (1.1.3)
  75
+    erubis (2.7.0)
  76
+    factory_girl (2.6.0)
  77
+      activesupport (>= 2.3.9)
  78
+    ffaker (1.12.1)
  79
+    ffi (1.0.11)
  80
+    highline (1.6.8)
  81
+    hike (1.2.1)
  82
+    i18n (0.6.0)
  83
+    jquery-rails (1.0.19)
  84
+      railties (~> 3.0)
  85
+      thor (~> 0.14)
  86
+    json (1.6.6)
  87
+    json_pure (1.6.5)
  88
+    kaminari (0.13.0)
  89
+      actionpack (>= 3.0.0)
  90
+      activesupport (>= 3.0.0)
  91
+      railties (>= 3.0.0)
  92
+    mail (2.3.3)
  93
+      i18n (>= 0.4.0)
  94
+      mime-types (~> 1.16)
  95
+      treetop (~> 1.4.8)
  96
+    meta_search (1.1.1)
  97
+      actionpack (~> 3.1.0)
  98
+      activerecord (~> 3.1.0)
  99
+      activesupport (~> 3.1.0)
  100
+      polyamorous (~> 0.5.0)
  101
+    mime-types (1.18)
  102
+    money (3.7.1)
  103
+      i18n (~> 0.4)
  104
+    multi_json (1.2.0)
  105
+    nested_set (1.6.8)
  106
+      activerecord (>= 3.0.0)
  107
+      railties (>= 3.0.0)
  108
+    nokogiri (1.5.2)
  109
+    orm_adapter (0.0.7)
  110
+    paperclip (2.5.0)
  111
+      activerecord (>= 2.3.0)
  112
+      activesupport (>= 2.3.2)
  113
+      cocaine (>= 0.0.2)
  114
+      mime-types
  115
+    polyamorous (0.5.0)
  116
+      activerecord (~> 3.0)
  117
+    polyglot (0.3.3)
  118
+    rack (1.3.6)
  119
+    rack-cache (1.2)
  120
+      rack (>= 0.4)
  121
+    rack-mount (0.8.3)
  122
+      rack (>= 1.0.0)
  123
+    rack-ssl (1.3.2)
  124
+      rack
  125
+    rack-test (0.6.1)
  126
+      rack (>= 1.0)
  127
+    rails (3.1.4)
  128
+      actionmailer (= 3.1.4)
  129
+      actionpack (= 3.1.4)
  130
+      activerecord (= 3.1.4)
  131
+      activeresource (= 3.1.4)
  132
+      activesupport (= 3.1.4)
  133
+      bundler (~> 1.0)
  134
+      railties (= 3.1.4)
  135
+    railties (3.1.4)
  136
+      actionpack (= 3.1.4)
  137
+      activesupport (= 3.1.4)
  138
+      rack-ssl (~> 1.3.2)
  139
+      rake (>= 0.8.7)
  140
+      rdoc (~> 3.4)
  141
+      thor (~> 0.14.6)
  142
+    rake (0.9.2.2)
  143
+    rdoc (3.12)
  144
+      json (~> 1.4)
  145
+    rspec (2.8.0)
  146
+      rspec-core (~> 2.8.0)
  147
+      rspec-expectations (~> 2.8.0)
  148
+      rspec-mocks (~> 2.8.0)
  149
+    rspec-core (2.8.0)
  150
+    rspec-expectations (2.8.0)
  151
+      diff-lcs (~> 1.1.2)
  152
+    rspec-mocks (2.8.0)
  153
+    rspec-rails (2.8.1)
  154
+      actionpack (>= 3.0)
  155
+      activesupport (>= 3.0)
  156
+      railties (>= 3.0)
  157
+      rspec (~> 2.8.0)
  158
+    rubyzip (0.9.6.1)
  159
+    selenium-webdriver (2.12.2)
  160
+      childprocess (>= 0.2.1)
  161
+      ffi (~> 1.0.9)
  162
+      json_pure
  163
+      rubyzip
  164
+    spree (1.0.3)
  165
+      spree_api (= 1.0.3)
  166
+      spree_auth (= 1.0.3)
  167
+      spree_cmd (= 1.0.3)
  168
+      spree_core (= 1.0.3)
  169
+      spree_dash (= 1.0.3)
  170
+      spree_promo (= 1.0.3)
  171
+      spree_sample (= 1.0.3)
  172
+    spree_api (1.0.3)
  173
+      spree_auth (= 1.0.3)
  174
+      spree_core (= 1.0.3)
  175
+    spree_auth (1.0.3)
  176
+      cancan (= 1.6.7)
  177
+      devise (= 1.4.8)
  178
+      spree_core (= 1.0.3)
  179
+    spree_cmd (1.0.3)
  180
+    spree_core (1.0.3)
  181
+      activemerchant (= 1.20.1)
  182
+      acts_as_list (= 0.1.4)
  183
+      deface (>= 0.7.2)
  184
+      ffaker (~> 1.12.0)
  185
+      highline (= 1.6.8)
  186
+      jquery-rails (>= 1.0.18, <= 1.0.19)
  187
+      kaminari (>= 0.13.0)
  188
+      meta_search (= 1.1.1)
  189
+      nested_set (= 1.6.8)
  190
+      paperclip (= 2.5.0)
  191
+      rails (>= 3.1.1, <= 3.1.4)
  192
+      state_machine (= 1.1.1)
  193
+      stringex (~> 1.3.0)
  194
+    spree_dash (1.0.3)
  195
+      spree_core (= 1.0.3)
  196
+    spree_promo (1.0.3)
  197
+      spree_auth (= 1.0.3)
  198
+      spree_core (= 1.0.3)
  199
+    spree_sample (1.0.3)
  200
+      spree_core (= 1.0.3)
  201
+    sprockets (2.0.3)
  202
+      hike (~> 1.2)
  203
+      rack (~> 1.0)
  204
+      tilt (~> 1.1, != 1.3.0)
  205
+    sqlite3 (1.3.5)
  206
+    state_machine (1.1.1)
  207
+    stringex (1.3.2)
  208
+    thor (0.14.6)
  209
+    tilt (1.3.3)
  210
+    treetop (1.4.10)
  211
+      polyglot
  212
+      polyglot (>= 0.3.1)
  213
+    tzinfo (0.3.33)
  214
+    warden (1.0.6)
  215
+      rack (>= 1.0)
  216
+    xpath (0.1.4)
  217
+      nokogiri (~> 1.3)
  218
+
  219
+PLATFORMS
  220
+  ruby
  221
+
  222
+DEPENDENCIES
  223
+  capybara
  224
+  factory_girl (~> 2.6)
  225
+  rspec-rails (~> 2.7)
  226
+  spree (~> 1.0.0)
  227
+  spree_address_book!
  228
+  sqlite3
66  Rakefile
... ...
@@ -1,30 +1,18 @@
1  
-require 'rubygems'
  1
+# encoding: utf-8
2 2
 require 'rake'
3 3
 require 'rake/testtask'
  4
+require 'rake/packagetask'
4 5
 require 'rubygems/package_task'
  6
+require 'rspec/core/rake_task'
  7
+require 'spree/core/testing_support/common_rake'
5 8
 
6  
-gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
7  
-if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
8  
-  require 'bundler'
9  
-  ENV['BUNDLE_GEMFILE'] = gemfile
10  
-  Bundler.setup
  9
+RSpec::Core::RakeTask.new
11 10
 
12  
-  require 'rspec'
13  
-  require 'rspec/core/rake_task'
14  
-  RSpec::Core::RakeTask.new
15  
-
16  
-  require 'cucumber/rake/task'
17  
-  Cucumber::Rake::Task.new do |t|
18  
-    t.cucumber_opts = %w{--format progress}
19  
-  end
20  
-end
21  
-
22  
-desc "Default Task"
23  
-task :default => [:spec, :cucumber ]
  11
+task :default => [:spec]
24 12
 
25 13
 spec = eval(File.read('spree_address_book.gemspec'))
26 14
 
27  
-Rake::GemPackageTask.new(spec) do |p|
  15
+Gem::PackageTask.new(spec) do |p|
28 16
   p.gem_spec = spec
29 17
 end
30 18
 
@@ -35,42 +23,8 @@ task :release => :package do
35 23
   Rake::Task['gem:push'].invoke
36 24
 end
37 25
 
38  
-desc "Default Task"
39  
-task :default => [ :spec ]
40  
-
41  
-desc "Regenerates a rails 3 app for testing"
  26
+desc "Generates a dummy app for testing"
42 27
 task :test_app do
43  
-  require '../spree/lib/generators/spree/test_app_generator'
44  
-  class AddressBookTestAppGenerator < Spree::Generators::TestAppGenerator
45  
-
46  
-    def install_gems
47  
-      inside "test_app" do
48  
-        run 'rake spree_core:install'
49  
-        run 'rake spree_auth:install'
50  
-        run 'rake spree_address_book:install'
51  
-      end
52  
-    end
53  
-
54  
-    def migrate_db
55  
-      run_migrations
56  
-    end
57  
-
58  
-    protected
59  
-    def full_path_for_local_gems
60  
-      <<-gems
61  
-gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
62  
-gem 'spree_auth', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "auth")}\'
63  
-gem 'spree_address_book', :path => \'#{File.dirname(__FILE__)}\'
64  
-      gems
65  
-    end
66  
-
67  
-  end
68  
-  AddressBookTestAppGenerator.start
69  
-end
70  
-
71  
-namespace :test_app do
72  
-  desc 'Rebuild test and cucumber databases'
73  
-  task :rebuild_dbs do
74  
-    system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
75  
-  end
  28
+  ENV['LIB_NAME'] = 'spree_address_book'
  29
+  Rake::Task['common:test_app'].invoke
76 30
 end
4  app/models/order_decorator.rb
@@ -17,7 +17,7 @@ def clone_billing_address
17 17
   end
18 18
   
19 19
   def bill_address_id=(id)
20  
-    address = Spree::Address.find(id)
  20
+    address = Spree::Address.where(:id => id).first
21 21
     if address && address.user_id == self.user_id
22 22
       self["bill_address_id"] = address.id
23 23
       self.bill_address.reload
@@ -31,7 +31,7 @@ def bill_address_attributes=(attributes)
31 31
   end
32 32
 
33 33
   def ship_address_id=(id)
34  
-    address = Spree::Address.find(id)
  34
+    address = Spree::Address.where(:id => id).first
35 35
     if address && address.user_id == self.user_id
36 36
       self["ship_address_id"] = address.id
37 37
       self.ship_address.reload
25  features/support/env.rb
... ...
@@ -1,22 +1,3 @@
1  
-FEATURES_PATH = File.expand_path('../..', __FILE__)
2  
-
3  
-# load shared env with features
4  
-require File.expand_path('../../../../spree/features/support/env', __FILE__)
5  
-
6  
-# load the rest of files for support and step definitions
7  
-directories = [ File.expand_path('../../../../spree/features/support', __FILE__),
8  
-                File.expand_path('../../../../spree/features/step_definitions', __FILE__),
9  
-                File.expand_path('../../../spec/factories', __FILE__) ]
10  
-
11  
-files = directories.map do |dir|
12  
-  Dir["#{dir}/**/*.rb"]
13  
-end.flatten.uniq
14  
-
15  
-files.each do |path|
16  
-  if path !~ /env.rb$/
17  
-    fp = File.expand_path(path)
18  
-    #puts fp
19  
-    load(fp)
20  
-  end
21  
-end
22  
-
  1
+require File.expand_path("../../../spec/dummy/config/environment.rb",  __FILE__)
  2
+require 'spree/core/testing_support/factories'
  3
+require 'spree/core/testing_support/env'
4  spec/models/address_spec.rb
... ...
@@ -1,5 +1,5 @@
1  
-require File.dirname(__FILE__) + '/../spec_helper'
  1
+require 'spec_helper'
2 2
 
3  
-describe Address do
  3
+describe Spree::Address do
4 4
 
5 5
 end
21  spec/models/order_spec.rb
... ...
@@ -0,0 +1,21 @@
  1
+require 'spec_helper'
  2
+
  3
+describe Spree::Order do
  4
+
  5
+  describe "Create order with the same bill & ship addresses" do
  6
+    it "should have equal ids when set ids" do
  7
+      address = Factory(:address)
  8
+      @order = Factory(:order, :bill_address_id => address.id, :ship_address_id => address.id)
  9
+      @order.bill_address_id.should == @order.ship_address_id
  10
+    end
  11
+  
  12
+    it "should have equal ids when option use_billing is active" do
  13
+      address = Factory(:address)
  14
+      @order  = Factory(:order, :use_billing => true,
  15
+                        :bill_address_id => address.id, 
  16
+                        :ship_address_id => nil)
  17
+      @order = @order.reload
  18
+      @order.bill_address_id.should == @order.ship_address_id
  19
+    end
  20
+  end
  21
+end
25  spec/spec_helper.rb
... ...
@@ -1,14 +1,19 @@
1  
-# This file is copied to ~/spec when you run 'ruby script/generate rspec'
2  
-# from the project root directory.
3  
-ENV["RAILS_ENV"] ||= 'test'
4  
-require File.expand_path("../test_app/config/environment", __FILE__)
  1
+# Configure Rails Environment
  2
+ENV["RAILS_ENV"] ||= "test"
  3
+
  4
+require File.expand_path("../dummy/config/environment.rb",  __FILE__)
  5
+
5 6
 require 'rspec/rails'
6 7
 
7  
-# Requires supporting files with custom matchers and macros, etc,
8  
-# in ./support/ and its subdirectories.
9  
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
  8
+# Requires supporting ruby files with custom matchers and macros, etc,
  9
+# in spec/support/ and its subdirectories.
  10
+Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
10 11
 
11  
-require 'spree_core/testing_support/factories'
  12
+# Requires factories defined in spree_core
  13
+require 'spree/core/testing_support/factories'
  14
+require 'spree/core/testing_support/env'
  15
+
  16
+require 'ffaker'
12 17
 
13 18
 RSpec.configure do |config|
14 19
   # == Mock Framework
@@ -20,6 +25,7 @@
20 25
   # config.mock_with :rr
21 26
   config.mock_with :rspec
22 27
 
  28
+  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
23 29
   config.fixture_path = "#{::Rails.root}/spec/fixtures"
24 30
 
25 31
   #config.include Devise::TestHelpers, :type => :controller
@@ -27,6 +33,5 @@
27 33
   # examples within a transaction, comment the following line or assign false
28 34
   # instead of true.
29 35
   config.use_transactional_fixtures = true
  36
+  
30 37
 end
31  
-
32  
-@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
5  spree_address_book.gemspec
@@ -18,4 +18,9 @@ Gem::Specification.new do |s|
18 18
 
19 19
   s.add_dependency('spree_core', '~> 1.0.0')
20 20
   s.add_dependency('spree_auth', '~> 1.0.0')
  21
+  
  22
+  s.add_development_dependency('rspec-rails',  '~> 2.7')
  23
+  s.add_development_dependency('sqlite3')
  24
+  s.add_development_dependency('capybara')
  25
+  s.add_development_dependency('factory_girl', '~> 2.6')
21 26
 end

0 notes on commit a9071bf

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