spree_multi_currency 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.coveralls.yml +0 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +21 -3
  6. data/README.markdown +8 -0
  7. data/Rakefile +4 -2
  8. data/app/assets/javascripts/admin/spree_multi_currency.js +0 -0
  9. data/app/assets/javascripts/store/spree_multi_currency.js +0 -0
  10. data/app/assets/stylesheets/admin/spree_multi_currency.css +0 -0
  11. data/app/assets/stylesheets/store/spree_multi_currency.css +0 -0
  12. data/app/controllers/spree/admin/currencies_controller.rb +3 -1
  13. data/app/controllers/spree/admin/currency_converters_controller.rb +2 -0
  14. data/app/controllers/spree/base_controller_decorator.rb +5 -2
  15. data/app/controllers/spree/currency_controller.rb +7 -2
  16. data/app/helpers/base_helper_decorator.rb +8 -0
  17. data/app/helpers/number_helper_decorator.rb +19 -17
  18. data/app/models/spree/adjustment_decorator.rb +2 -0
  19. data/app/models/spree/controller_helper_order.rb +11 -0
  20. data/app/models/spree/currency.rb +82 -38
  21. data/app/models/spree/currency_converter.rb +2 -0
  22. data/app/models/spree/line_item_decorator.rb +19 -6
  23. data/app/models/spree/money_decorator.rb +15 -0
  24. data/app/models/spree/order_decorator.rb +63 -55
  25. data/app/models/spree/product_decorator.rb +33 -0
  26. data/app/models/spree/stock/estimator_decorator.rb +18 -0
  27. data/app/models/spree/variant_decorator.rb +93 -16
  28. data/app/overrides/add_currencies_admin_configurations_menu.rb +8 -7
  29. data/app/overrides/add_currency_selection.rb +15 -0
  30. data/app/views/spree/admin/currencies/new.html.erb +4 -4
  31. data/app/views/spree/admin/currency_converters/edit.html.erb +4 -4
  32. data/app/views/spree/admin/currency_converters/new.html.erb +3 -3
  33. data/config/routes.rb +2 -0
  34. data/db/migrate/20101109134351_create_currencies.rb +2 -0
  35. data/db/migrate/20101109134453_create_currency_converters.rb +2 -0
  36. data/db/seeds.rb +2 -0
  37. data/features/step_definitions/product.rb +2 -0
  38. data/features/support/env.rb +2 -0
  39. data/features/support/paths.rb +2 -0
  40. data/lib/generators/spree_multi_currency/install/install_generator.rb +27 -15
  41. data/lib/spree_multi_currency.rb +13 -9
  42. data/lib/spree_multi_currency/engine.rb +6 -0
  43. data/lib/tasks/spree_multi_currency.rake +57 -38
  44. data/spec/changing_currency_spec.rb +44 -15
  45. data/spec/controllers/spree/currency_controller_spec.rb +16 -0
  46. data/spec/features/buy_spec.rb +103 -0
  47. data/spec/helpers/number_helper_spec.rb +21 -0
  48. data/spec/models/spree/currency_spec.rb +32 -0
  49. data/spec/models/spree/variant_spec.rb +32 -0
  50. data/spec/spec_helper.rb +50 -10
  51. data/spree_multi_currency.gemspec +2 -4
  52. metadata +29 -34
  53. data.tar.gz.sig +0 -3
  54. data/Versionfile +0 -9
  55. metadata.gz.sig +0 -1
@@ -10,7 +10,7 @@
10
10
 
11
11
  <%= form_for(:currency_converter, :url => collection_url) do |f| %>
12
12
  <fieldset class="no-border-top">
13
- <%= render :partial => "form", :locals => { :f => f } %>
14
- <%= render :partial => 'spree/admin/shared/new_resource_links' %>
13
+ <%= render 'form', :f => f %>
14
+ <%= render 'spree/admin/shared/new_resource_links' %>
15
15
  </fieldset>
16
- <% end %>
16
+ <% end %>
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # Put your extension routes here.
2
4
  Spree::Core::Engine.routes.prepend do
3
5
  match "currency/:id" => "currency#set", :as => :currency
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # -*- coding: utf-8 -*-
2
4
  class CreateCurrencies < ActiveRecord::Migration
3
5
  def self.up
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class CreateCurrencyConverters < ActiveRecord::Migration
2
4
  def self.up
3
5
  create_table :spree_currency_converters do |t|
data/db/seeds.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # encoding: utf-8
2
+
1
3
  # Use this file to load your own seed data from extensions.
2
4
  # See the db/seeds.rb file in the Spree core for some ideas on what you can do here.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  Given /^the custom taxons and custom products exist$/ do
2
4
  Fixtures.reset_cache
3
5
  fixtures_folder = File.join(Rails.root.to_s, 'db', 'sample')
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  FEATURES_PATH = File.expand_path('../..', __FILE__)
2
4
  # require define path to spree project
3
5
  ENV['SPREE_GEM_PATH'] = "/home/dima/project/spree"
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module NavigationHelpers
2
4
  # Maps a name to a path. Used by the
3
5
  #
@@ -1,28 +1,40 @@
1
+ # encoding: utf-8
1
2
  module SpreeMultiCurrency
2
3
  module Generators
3
4
  class InstallGenerator < Rails::Generators::Base
5
+ class_option :auto_run_migrations, type: :boolean, default: true
4
6
 
5
- # def add_javascripts
6
- # append_file "app/assets/javascripts/store/all.js", "//= require store/spree_multi_lingual\n"
7
- # append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_multi_lingual\n"
8
- # end
9
- #
10
- # def add_stylesheets
11
- # inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_multi_lingual\n", :before => /\*\//, :verbose => true
12
- # inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_multi_lingual\n", :before => /\*\//, :verbose => true
13
- # end
7
+ def add_javascripts
8
+ append_file 'app/assets/javascripts/store/all.js',
9
+ "//= require store/spree_frontend\n"
10
+ append_file 'app/assets/javascripts/admin/all.js',
11
+ "//= require admin/spree_backend\n"
12
+ end
13
+
14
+ def add_stylesheets
15
+ inject_into_file 'app/assets/stylesheets/store/all.css',
16
+ " *= require store/spree_frontend\n",
17
+ before: /\*\//,
18
+ verbose: true
19
+ inject_into_file 'app/assets/stylesheets/admin/all.css',
20
+ " *= require admin/spree_backend\n",
21
+ before: /\*\//,
22
+ verbose: true
23
+ end
14
24
 
15
25
  def add_migrations
16
26
  run 'bundle exec rake railties:install:migrations FROM=spree_multi_currency'
17
27
  end
18
28
 
19
29
  def run_migrations
20
- res = ask "Would you like to run the migrations now? [Y/n]"
21
- if res == "" || res.downcase == "y"
22
- run 'bundle exec rake db:migrate'
23
- else
24
- puts "Skipping rake db:migrate, don't forget to run it!"
25
- end
30
+ message = 'Would you like to run the migrations now? [Y/n]'
31
+ run_migrations = options[:auto_run_migrations] ||
32
+ ['', 'y', 'Y'].include?(ask message)
33
+ if run_migrations
34
+ run 'bundle exec rake db:migrate'
35
+ else
36
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
37
+ end
26
38
  end
27
39
  end
28
40
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # -*- coding: utf-8 -*-
2
4
  require 'spree/core'
3
5
  require 'spree_multi_currency/engine'
@@ -12,25 +14,27 @@ module Spree::MultiCurrency
12
14
  # rate_at_date - use the exchange rate at the specified date
13
15
  def multi_currency(*args)
14
16
  options = args.extract_options!
17
+
15
18
  [args].flatten.compact.each do |number_field|
19
+
20
+ # define for example method price
16
21
  define_method(number_field.to_sym) do
17
- if options.has_key?(:rate_at_date) && options[:rate_at_date].is_a?(Proc)
22
+ num_field = read_attribute(number_field.to_sym)
23
+ if options.has_key?(:rate_at_date) &&
24
+ options[:rate_at_date].is_a?(Proc)
18
25
  Spree::Currency.conversion_to_current(
19
- read_attribute(number_field.to_sym),
20
- { :date => options[:rate_at_date].call(self) }
26
+ num_field,
27
+ { date: options[:rate_at_date].call(self) }
21
28
  )
22
29
  else
23
- Spree::Currency.conversion_to_current(read_attribute(number_field.to_sym))
30
+ Spree::Currency.conversion_to_current(num_field)
24
31
  end
25
32
  end
26
33
 
27
- define_method("base_#{number_field}") do
28
- read_attribute(number_field.to_sym)
29
- end
30
-
31
34
  unless options[:only_read]
32
35
  define_method(:"#{number_field}=") do |value|
33
- write_attribute(number_field.to_sym, Spree::Currency.conversion_from_current(value))
36
+ write_attribute(number_field.to_sym,
37
+ Spree::Currency.conversion_from_current(value))
34
38
  end
35
39
  end
36
40
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module SpreeMultiCurrency
2
4
  # mattr_reader :languages
3
5
  # @@languages = [:en]
@@ -21,6 +23,10 @@ module SpreeMultiCurrency
21
23
  Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
22
24
  Rails.configuration.cache_classes ? require(c) : load(c)
23
25
  end
26
+
27
+ Dir[File.join(File.dirname(__FILE__), "../../app/assets/**/**/**.*")].sort.each do |c|
28
+ Rails.env.production? ? require(c) : load(c)
29
+ end
24
30
  end
25
31
 
26
32
  # after rails config/initializers loading, setup spree_multi_lingual's language by getting
@@ -4,88 +4,109 @@ require 'open-uri'
4
4
  require 'nokogiri'
5
5
  # add custom rake tasks here
6
6
  namespace :spree_multi_currency do
7
+ eur_hash = { num_code: '978', char_code: 'EUR', name: 'Euro' }
7
8
 
8
9
  namespace :currency do
9
10
  desc "Общероссийский классификатор валют (сокращ. ОКВ) - http://ru.wikipedia.org/wiki/Общероссийский_классификатор_валют"
10
11
 
12
+ task :from_moneylib => :environment do
13
+ ::Money::Currency.table.each do |x|
14
+ Spree::Currency.create(char_code: x[1][:iso_code],
15
+ name: x[0],
16
+ num_code: x[1][:iso_numeric])
17
+ end
18
+ end
19
+
11
20
  task :okv => :environment do
12
- url = "http://ru.wikipedia.org/wiki/%D0%9E%D0%B1%D1%89%D0%B5%D1%80%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B8%D0%B9_%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%82%D0%BE%D1%80_%D0%B2%D0%B0%D0%BB%D1%8E%D1%82"
21
+ url = 'http://ru.wikipedia.org/wiki/%D0%9E%D0%B1%D1%89%D0%B5%D1%80%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B8%D0%B9_%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%82%D0%BE%D1%80_%D0%B2%D0%B0%D0%BB%D1%8E%D1%82'
13
22
  data = Nokogiri::HTML.parse(open(url))
14
23
  keys = [:char_code, :num_code, :discharge, :name, :countries ]
15
- data.css("table:first tr")[1..-1].map{ |d|
16
- Hash[*keys.zip(d.css("td").map {|x| x.text.strip }).flatten]
17
- }.each { |n|
18
- Spree::Currency.find_by_num_code(n[:num_code]) || Spree::Currency.create(n.except(:discharge).except(:countries))
19
- }
24
+ data.css('table:first tr')[1..-1].map{ |d|
25
+ Hash[*keys.zip(d.css('td').map { |x| x.text.strip }).flatten]
26
+ }.each do |n|
27
+ Spree::Currency.find_by_num_code(n[:num_code]) ||
28
+ Spree::Currency.create(n.except(:discharge).except(:countries))
29
+ end
20
30
 
21
31
  end
22
32
 
23
- desc "Load currency ISO4217 http://en.wikipedia.org/wiki/ISO_4217"
33
+ desc 'Load currency ISO4217 http://en.wikipedia.org/wiki/ISO_4217'
24
34
  task :iso4217 => :environment do
25
- url = "http://en.wikipedia.org/wiki/ISO_4217"
35
+ url = 'http://en.wikipedia.org/wiki/ISO_4217'
26
36
  data = Nokogiri::HTML.parse(open(url))
27
37
  keys = [:char_code, :num_code, :discharge, :name, :countries ]
28
- data.css("table:eq(2) tr")[1..-1].map{|d|
29
- Hash[*keys.zip(d.css("td").map {|x| x.text.strip }).flatten]
30
- }.each { |n|
31
- Spree::Currency.find_by_num_code(n[:num_code]) || Spree::Currency.create(n.except(:discharge).except(:countries))
32
- }
38
+ data.css('table:eq(1) tr')[1..-1].map{|d|
39
+ Hash[*keys.zip(d.css('td').map {|x| x.text.strip }).flatten]
40
+ }.each do |n|
41
+ Spree::Currency.find_by_num_code(n[:num_code]) ||
42
+ Spree::Currency.create(n.except(:discharge).except(:countries))
43
+ end
33
44
  end
34
45
 
35
46
  end
36
47
 
37
48
  namespace :rates do
38
- desc "Курс Сбербанка РФ http://www.cbr.ru"
49
+ desc 'Курс Сбербанка РФ http://www.cbr.ru'
39
50
  task :cbr => :environment do
40
- rub = Spree::Currency.get("643", { :num_code => "643", :char_code => "RUB", :name => "Российский рубль"})
51
+ rub = Spree::Currency.get('643', { num_code: '643', char_code: 'RUB', name: 'Российский рубль' })
41
52
  rub.basic!
42
53
  url = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=#{Time.now.strftime('%d/%m/%Y')}"
43
54
  data = Nokogiri::XML.parse(open(url))
44
- date_str = data.xpath("//ValCurs").attr("Date").to_s
55
+ date_str = data.xpath('//ValCurs').attr('Date').to_s
45
56
  date = Date.strptime(date_str, (date_str =~ /\./ ? '%d.%m.%Y' : '%d/%m/%y'))
46
- data.xpath("//ValCurs/Valute").each do |valute|
47
- char_code = valute.xpath("./CharCode").text.to_s
48
- num_code = valute.xpath("./NumCode").text.to_s
49
- name = valute.xpath("./Name").text.to_s
50
- value = valute.xpath("./Value").text.gsub(',','.').to_f
51
- nominal = valute.xpath("./Nominal").text
52
- currency = Spree::Currency.get(num_code, { :num_code => num_code, :char_code => char_code, :name => name})
57
+ data.xpath('//ValCurs/Valute').each do |valute|
58
+ char_code = valute.xpath('./CharCode').text.to_s
59
+ num_code = valute.xpath('./NumCode').text.to_s
60
+ name = valute.xpath('./Name').text.to_s
61
+ value = valute.xpath('./Value').text.gsub(',', '.').to_f
62
+ nominal = valute.xpath('./Nominal').text
63
+ currency = Spree::Currency.get(num_code, { num_code: num_code,
64
+ char_code: char_code,
65
+ name: name })
53
66
  currency && Spree::CurrencyConverter.add(currency, date, value, nominal)
54
67
  end
55
68
  end
56
69
 
57
- desc "Rates from European Central Bank"
70
+ desc 'Rates from European Central Bank'
58
71
  task :ecb, [:load_currencies] => :environment do |t, args|
59
- Rake::Task["spree_multi_currency:currency:iso4217"].invoke if args.load_currencies
60
- euro = Spree::Currency.get("978", { :num_code => "978", :char_code => "EUR", :name => "Euro"})
72
+ if args.load_currencies
73
+ Rake::Task['spree_multi_currency:currency:iso4217'].invoke
74
+ end
75
+
76
+ euro = Spree::Currency.get('978', eur_hash)
61
77
  euro.basic!
62
78
  url = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'
63
79
  data = Nokogiri::XML.parse(open(url))
64
- date = Date.strptime(data.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube').attr("time").to_s, "%Y-%m-%d")
80
+ date = Date.strptime(data.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube').attr('time').to_s, "%Y-%m-%d")
65
81
  data.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube').each do |exchange_rate|
66
- char_code = exchange_rate.attribute("currency").value.to_s.strip
67
- nominal, value = exchange_rate.attribute("rate").value.to_f, 1
82
+ char_code = exchange_rate.attribute('currency').value.to_s.strip
83
+ nominal, value = exchange_rate.attribute('rate').value.to_f, 1
68
84
  currency = Spree::Currency.find_by_char_code(char_code)
69
85
  currency && Spree::CurrencyConverter.add(currency, date, value, nominal)
70
86
  end
71
87
 
72
88
  end
73
89
 
74
- desc "Rates from Google"
90
+ desc 'Rates from Google'
75
91
  task :google, [:currency, :load_currencies] => :environment do |t, args|
76
- Rake::Task["spree_multi_currency:currency:iso4217"].invoke if args.load_currencies
77
- default_currency = Spree::Currency.where("char_code = :currency_code or num_code = :currency_code", :currency_code => args.currency.upcase || 978).first ||
78
- Spree::Currency.get("978", { :num_code => "978", :char_code => "EUR", :name => "Euro"})
92
+ Rake::Task['spree_multi_currency:currency:iso4217'].invoke if args.load_currencies
93
+ if args.currency
94
+ default_currency = Spree::Currency.where('char_code = :currency_code or num_code = :currency_code', currency_code: args.currency.upcase ).first
95
+ else
96
+ default_currency = Spree::Currency.get('978', eur_hash)
97
+ end
79
98
  default_currency.basic!
99
+ # for spree 2.x require set config currency
100
+ Spree::Config.currency = default_currency.char_code
80
101
  date = Time.now
81
102
  puts "Loads currency data from Google using #{default_currency}"
82
103
  Spree::Currency.all.each do |currency|
83
104
  unless currency == default_currency
84
105
  url = "http://www.google.com/ig/calculator?hl=en&q=1#{ currency.char_code }%3D%3F#{ default_currency.char_code }"
85
106
  puts url
86
- @data = JSON.parse(open(url).read.gsub(/lhs:|rhs:|error:|icc:/){ |x| "\"#{x[0..-2]}\":"})
87
- if @data["error"].blank?
88
- @value = BigDecimal(@data["rhs"].split(' ')[0])
107
+ @data = JSON.parse(open(url).read.gsub(/lhs:|rhs:|error:|icc:/){ |x| "\"#{x[0..-2]}\":" })
108
+ if @data['error'].blank?
109
+ @value = BigDecimal(@data['rhs'].split(' ')[0])
89
110
  Spree::CurrencyConverter.add(currency, date, @value, 1)
90
111
  end
91
112
  end
@@ -93,7 +114,5 @@ namespace :spree_multi_currency do
93
114
  end
94
115
  end
95
116
 
96
-
97
-
98
117
  end
99
118
 
@@ -1,18 +1,47 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe "Currencies changing" do
5
+ describe 'Currencies changing' do
6
+ before :each do
7
+ Spree::Product.destroy_all
8
+ Spree::Currency.destroy_all
9
+ Spree::CurrencyConverter.destroy_all
10
+
11
+ @rub = Spree::Currency.create(name: 'rubles', char_code: 'RUB',
12
+ num_code: 623, locale: 'ru', basic: false)
13
+ @usd = Spree::Currency.create(name: 'dollars', char_code: 'USD',
14
+ num_code: 624, locale: 'en', basic: true)
15
+ Spree::CurrencyConverter.add(@rub, Time.now, 1.0, 32.0)
16
+ @shipping_category = create(:shipping_category)
17
+ end
18
+
19
+ it 'changes price when changing locale' do
20
+ product = FactoryGirl.create(:product, :cost_price => 1)
21
+ variant = product.master
22
+ I18n.locale = 'en'
23
+ variant.cost_price.should eql 1.0
24
+ I18n.locale = 'ru'
25
+ Spree::Currency.current!
26
+ Spree::Currency.current.should eql @rub
27
+ variant.cost_price.to_f.should eql 32.0
28
+
29
+ end
4
30
 
5
- it "changes price when changing locale" do
6
- rub = Spree::Currency.create(:name => "rubles", :char_code => "RUB", :num_code => 623, :locale => "ru", :basic => false)
7
- usd = Spree::Currency.create(:name => "dollars", :char_code => "USD", :num_code => 624, :locale => "en", :basic => true)
8
- Spree::CurrencyConverter.create(:nominal => 32, :value => 1.0, :currency => rub, :date_req => Time.now)
9
- product = FactoryGirl.create(:product, :price => 1)
10
- variant = Spree::Variant.last
11
- I18n.locale = "en"
12
- variant.price.should eql 1.0
13
- I18n.locale = "ru"
14
- Spree::Currency.current!
15
- Spree::Currency.current.should eql rub
16
- variant.price.to_f.should eql 32.0
17
- end
18
- end
31
+ it 'check save master_price' do
32
+ I18n.locale = 'en'
33
+ Spree::Currency.current!
34
+ product = Spree::Product.new( name: 'test123',
35
+ price: 123.54)
36
+ product.shipping_category = @shipping_category
37
+ product.save!
38
+ product.reload
39
+ product.price.should eql 123.54
40
+ product.master.price.should eql 123.54
41
+ I18n.locale = 'ru'
42
+ Spree::Currency.current!
43
+ Rails.logger.info "\t\n"*10
44
+ product.price.should eql 3953.28
45
+ product.master.price.should eql 3953.28
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::CurrencyController do
4
+
5
+ it 'attempt to set incorrect currency' do
6
+ controller.stub spree_current_user: mock_model(Spree.user_class,
7
+ has_spree_role?: true,
8
+ last_incomplete_spree_order: nil,
9
+ spree_api_key: 'fake')
10
+ spree_get 'set', id: 'RUBLI'
11
+ response.status.should == 302
12
+ flash[:error].should == I18n.t(:currency_not_found)
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ feature 'Buy' do
6
+ background :each do
7
+ # factories defined in spree/core/lib/spree/testing_support/factories
8
+ # @calculator = create(:calculator)
9
+ Spree::Config.currency = 'USD'
10
+ rub = Spree::Currency.create(name: 'rubles', char_code: 'RUB',
11
+ num_code: 623, locale: 'ru', basic: false)
12
+ usd = Spree::Currency.create(name: 'dollars', char_code: 'USD',
13
+ num_code: 624, locale: 'en', basic: true)
14
+
15
+ Spree::CurrencyConverter.create!(nominal: 1.0, value: 32.0,
16
+ currency: rub, date_req: Time.now)
17
+ Spree::Config.show_products_without_price = true
18
+
19
+ # FIXME looks like created default zone for country factory
20
+ #zone = create(:zone, name: 'CountryZone')
21
+ @ship_cat = create(:shipping_category,name: 'all')
22
+
23
+ @product = create(:base_product, name: 'product1')
24
+ @product.save!
25
+ stock = @product.stock_items.first
26
+ stock.adjust_count_on_hand(100)
27
+ stock.save!
28
+
29
+ @country = create(:country,
30
+ iso_name: 'SWEDEN',
31
+ name: 'Sweden',
32
+ iso: 'SE',
33
+ iso3: 'SE',
34
+ numcode: 46 )
35
+ @country.states_required = false
36
+ @country.save!
37
+ @state = @country.states.create(name: 'Stockholm')
38
+
39
+ ship_meth=FactoryGirl.create(:shipping_method,
40
+ :calculator_type => 'Spree::Calculator::Shipping::FlatRate',
41
+ :display_on => 'both')
42
+ ship_meth.calculator.preferred_amount = 90
43
+ ship_meth.save!
44
+ zone = Spree::Zone.first
45
+ zone.members.create!(zoneable: @country,zoneable_type: 'Country')
46
+ ship_meth.zones << zone
47
+ ship_meth.shipping_categories << @ship_cat
48
+
49
+ # defined in spec/factories/klarna_payment_factory
50
+ @pay_method = create(:payment_method)
51
+ end
52
+
53
+ scenario 'visit root page' do
54
+ # check Spree::Config.show_products_without_price
55
+ @product.prices.each do |price|
56
+ price.amount = nil
57
+ price.save!
58
+ end
59
+ Spree::Config.show_products_without_price = false
60
+ name = @product.name
61
+ visit '/'
62
+ expect(page).to have_no_content(name)
63
+
64
+ Spree::Config.show_products_without_price = true
65
+ visit '/'
66
+ expect(page).to have_content(name)
67
+
68
+ # check change currency on product page
69
+ visit '/currency/RUB'
70
+ expect(page).to have_content('руб')
71
+ visit '/currency/USD'
72
+
73
+ click_link name
74
+ click_button 'add-to-cart-button'
75
+ click_button 'checkout-link'
76
+ fill_in 'order_email', with: 'test2@example.com'
77
+ click_button 'Continue'
78
+
79
+ # fill addresses
80
+ # copy from spree/backend/spec/requests/admin/orders/order_details_spec.rb
81
+ # may will in future require update
82
+ check 'order_use_billing'
83
+ fill_in 'order_bill_address_attributes_firstname', with: 'Joe'
84
+ fill_in 'order_bill_address_attributes_lastname', with: 'User'
85
+ fill_in 'order_bill_address_attributes_address1', with: '7735 Old Georgetown Road'
86
+ fill_in 'order_bill_address_attributes_address2', with: 'Suite 510'
87
+ fill_in 'order_bill_address_attributes_city', with: 'Bethesda'
88
+ fill_in 'order_bill_address_attributes_zipcode', with: '20814'
89
+ fill_in 'order_bill_address_attributes_phone', with: '301-444-5002'
90
+ within('fieldset#billing') do
91
+ select @country.name , from: 'Country'
92
+ end
93
+
94
+ click_button 'Save and Continue'
95
+
96
+ # shipping
97
+ click_button 'Save and Continue'
98
+
99
+ # payment page
100
+ click_button 'Save and Continue'
101
+ expect(page).to have_content('Your order has been processed successfully')
102
+ end
103
+ end