From af6edfd0aa3e00cd3c90667d121c98421f7c847d Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 17 Jul 2015 12:44:52 +0200 Subject: [PATCH] Switch to official couch_potato version --- Gemfile | 5 +- Gemfile.lock | 64 +++++++++++-------- app/models/section.rb | 2 - app/models/supplier/counters.rb | 13 ++-- .../suppliers/dashboard_steps.rb | 2 +- spec/models/section_spec.rb | 4 ++ spec/models/supplier/counters_spec.rb | 40 ++++++++++++ spec/models/supplier_spec.rb | 42 +++--------- spec/spec_helper.rb | 4 +- 9 files changed, 106 insertions(+), 70 deletions(-) create mode 100644 spec/models/supplier/counters_spec.rb diff --git a/Gemfile b/Gemfile index 696c4a3f..9bbd2afb 100644 --- a/Gemfile +++ b/Gemfile @@ -53,7 +53,7 @@ end # gem 'couchbase-docstore' # gem 'couchbase-structures', github: 'bterkuile/couchbase-structures' -gem 'couch_potato' , github: 'bterkuile/couch_potato' +gem 'couch_potato', '~> 1.4.0' #, github: 'bterkuile/couch_potato' #gem 'simply_stored', path: './../components/simply_stored' #, github: 'bterkuile/simply_stored' gem 'simply_stored', github: 'bterkuile/simply_stored' #gem 'orm_adapter', github: 'bterkuile/orm_adapter' @@ -120,8 +120,9 @@ end group :test do #gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks #gem 'selenium-webdriver', '~> 2.45.0.dev3' + gem 'selenium-webdriver' #gem 'poltergeist' - gem 'capybara-webkit' + #gem 'capybara-webkit' gem 'capybara-screenshot' gem 'turnip' gem 'rspec-its' diff --git a/Gemfile.lock b/Gemfile.lock index 32876ee0..b905e475 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,15 +10,6 @@ GIT slim-rails tinymce-rails -GIT - remote: git://github.com/bterkuile/couch_potato.git - revision: 8929326ee855e964a441a8ede941b52c0ee88a16 - specs: - couch_potato (0.7.1) - activemodel - couchrest (>= 1.0.1) - json (~> 1.6) - GIT remote: git://github.com/bterkuile/devise_simply_stored.git revision: 86f93782c607958e7f99a6fdbae5566e17047273 @@ -28,7 +19,7 @@ GIT GIT remote: git://github.com/bterkuile/simply_stored.git - revision: 652caf8c2cfe4f828477f8b76d0cd201851cd53d + revision: 4f3d144096a7deb457a9e6b92c3ced0f4a9eeff0 specs: simply_stored (1.0.0) activesupport @@ -134,11 +125,10 @@ GEM capybara (>= 1.0, < 3) colored launchy - capybara-webkit (1.6.0) - capybara (>= 2.3.0, < 2.5.0) - json celluloid (0.16.0) timers (~> 4.0.0) + childprocess (0.5.6) + ffi (~> 1.0, >= 1.0.11) climate_control (0.0.3) activesupport (>= 3.0) cocaine (0.5.7) @@ -154,10 +144,14 @@ GEM colored (1.2) colorize (0.7.7) cookiejar (0.3.2) - couchrest (1.2.0) - mime-types (~> 1.15) - multi_json (~> 1.0) - rest-client (~> 1.6.1) + couch_potato (1.4.0) + activemodel + couchrest (~> 1.2.0) + json (~> 1.6) + couchrest (1.2.1) + mime-types (>= 1.15) + multi_json (~> 1.7, ~> 1.0) + rest-client (~> 1.8.0) crack (0.4.2) safe_yaml (~> 1.0.0) debug_inspector (0.0.2) @@ -171,6 +165,8 @@ GEM devise-i18n (0.11.4) diff-lcs (1.2.5) docile (1.1.5) + domain_name (0.5.24) + unf (>= 0.0.5, < 1.0.0) dotenv (1.0.2) em-http-request (1.1.2) addressable (>= 2.3.4) @@ -227,6 +223,7 @@ GEM faye-websocket (0.9.2) eventmachine (>= 0.12.0) websocket-driver (>= 0.5.1) + ffi (1.9.10) font-awesome-rails (4.3.0.0) railties (>= 3.2, < 5.0) foreman (0.77.0) @@ -246,6 +243,8 @@ GEM hashie (3.4.0) hike (1.2.3) hitimes (1.2.2) + http-cookie (1.0.2) + domain_name (~> 0.5) http_parser.rb (0.6.0) i18n (0.7.0) iso_country_codes (0.6.1) @@ -258,7 +257,7 @@ GEM js-routes (1.0.0) railties (>= 3.2) sprockets-rails - json (1.8.2) + json (1.8.3) jwt (1.3.0) kaminari (0.16.3) actionpack (>= 3.0.0) @@ -272,17 +271,18 @@ GEM mail (2.6.3) mime-types (>= 1.16, < 3) method_source (0.8.2) - mime-types (1.25.1) + mime-types (2.6.1) mini_magick (4.1.0) mini_portile (0.6.2) - minitest (5.5.1) - multi_json (1.11.0) + minitest (5.7.0) + multi_json (1.11.2) multi_xml (0.5.5) multipart-post (2.0.0) naught (1.0.0) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.2) + netrc (0.10.3) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) oauth2 (1.0.0) @@ -351,12 +351,12 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) - rdoc (4.2.0) responders (2.1.0) railties (>= 4.2.0, < 5) - rest-client (1.6.8) - mime-types (~> 1.16) - rdoc (>= 2.4.2) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) rqrcode (0.4.2) rspec (3.2.0) rspec-core (~> 3.2.0) @@ -383,6 +383,7 @@ GEM rspec-support (~> 3.2.0) rspec-support (3.2.2) ruby-progressbar (1.7.1) + rubyzip (1.1.7) safe_yaml (1.0.4) sass (3.4.13) sass-rails (5.0.1) @@ -391,6 +392,11 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (~> 1.1) + selenium-webdriver (2.46.2) + childprocess (~> 0.5) + multi_json (~> 1.0) + rubyzip (~> 1.0) + websocket (~> 1.0) simplecov (0.9.2) docile (~> 1.1.0) multi_json (~> 1.0) @@ -442,6 +448,9 @@ GEM uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.1) warden (1.2.3) rack (>= 1.0) web-console (2.0.0) @@ -452,6 +461,7 @@ GEM webmock (1.20.4) addressable (>= 2.3.6) crack (>= 0.3.2) + websocket (1.2.2) websocket-driver (0.5.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) @@ -475,10 +485,9 @@ DEPENDENCIES capistrano-rvm capistrano3-puma capybara-screenshot - capybara-webkit cmtool! coffee-rails - couch_potato! + couch_potato (~> 1.4.0) devise devise-i18n devise_simply_stored! @@ -517,6 +526,7 @@ DEPENDENCIES rspec-its rspec-rails sass-rails (~> 5.0.0) + selenium-webdriver simplecov simply_stored! slim-rails diff --git a/app/models/section.rb b/app/models/section.rb index b0477b10..3c5b240d 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -13,8 +13,6 @@ class Section has_many :section_elements has_many :section_areas - attr_protected :supplier_id - validates :title, presence: true validates :supplier_id, presence: true diff --git a/app/models/supplier/counters.rb b/app/models/supplier/counters.rb index 9b3b992c..3881c76e 100644 --- a/app/models/supplier/counters.rb +++ b/app/models/supplier/counters.rb @@ -66,13 +66,18 @@ class Supplier def reset_order_counters_with_spec(spec) # taken from the couch_potato source since we want a model/custom mix here (hmmmm, something that should be fixed in the couchbase version) - results = CouchPotato::View::ViewQuery.new( + view_spec = {spec.view_name => { map: spec.map_function, reduce: spec.reduce_function} } + list_spec = spec.list_name.nil? ? nil : {spec.list_name => spec.list_function} + lib_spec = nil # do not yet know meaning of this param + query_view = CouchPotato::View::ViewQuery.new( database.couchrest_database, spec.design_document, - {spec.view_name => { map: spec.map_function, reduce: spec.reduce_function} }, - ({spec.list_name => spec.list_function} unless spec.list_name.nil?), + view_spec, + list_spec, + lib_spec, spec.language - ).query_view!(spec.view_parameters) + ) + results = query_view.query_view!(spec.view_parameters) Array.wrap(results['rows']).each do |result| supplier_id, state = result['key'] case state diff --git a/spec/acceptance_steps/suppliers/dashboard_steps.rb b/spec/acceptance_steps/suppliers/dashboard_steps.rb index 4935370a..895210a6 100644 --- a/spec/acceptance_steps/suppliers/dashboard_steps.rb +++ b/spec/acceptance_steps/suppliers/dashboard_steps.rb @@ -156,7 +156,7 @@ step "the supplier main board list total should be updated" do end step "the supplier placed orders counter should be reduced" do - sleep 0.5 + sleep 0.8 find('.supplier-orders-placed-count-number').text.should == "10" end diff --git a/spec/models/section_spec.rb b/spec/models/section_spec.rb index fdc55d1c..f238a14b 100644 --- a/spec/models/section_spec.rb +++ b/spec/models/section_spec.rb @@ -5,6 +5,10 @@ describe :section do @section = build :section, path: [[10, 30], [20,30], [20,40], [10, 40]] end + it "creates without problem" do + expect{ @section.save }.not_to raise_error + end + describe :path do describe :width do it "should have 20 width when initialized" do diff --git a/spec/models/supplier/counters_spec.rb b/spec/models/supplier/counters_spec.rb new file mode 100644 index 00000000..cd7a9cc7 --- /dev/null +++ b/spec/models/supplier/counters_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Supplier::Counters do + describe '.reset_counters!' do + it 'sets the counters to the right values for all suppliers' do + supplier1 = create :supplier + supplier2 = create :supplier + create_list :order, 2, :placed, supplier: supplier1 + create_list :order, 7, :active, supplier: supplier1 + create_list :order, 3, :placed, supplier: supplier2 + Supplier.reset_counters! + supplier1.orders_placed_count.should == 2 + supplier1.orders_in_process_count.should == 7 + supplier2.orders_placed_count.should == 3 + end + + # it 'cleans counter values if orders are no longer available', broken: defined?($cb) do + # old_connection = Qwaiter::Counter.connection + # # this spec should run on the couchbase database + # Qwaiter::Counter.connection = $cb + # supplier = create :supplier + # Qwaiter::Counter.set "supplier_counter:#{supplier.id}:orders_placed", 9 + # supplier.orders_placed_count.should == 9 + # Supplier.reset_counters! + # sleep 1 + # supplier.orders_placed_count.should == 0 + # Qwaiter::Counter.connection = old_connection + # end + # + it 'sets the counters to the right values for one supplier' do + supplier = create :supplier + create_list :order, 5, :placed, supplier: supplier + create_list :order, 9, :active, supplier: supplier + supplier.reset_counters! + supplier.orders_placed_count.should == 5 + supplier.orders_in_process_count.should == 9 + end + end + +end diff --git a/spec/models/supplier_spec.rb b/spec/models/supplier_spec.rb index 16d9bdee..bd4a7367 100644 --- a/spec/models/supplier_spec.rb +++ b/spec/models/supplier_spec.rb @@ -3,41 +3,19 @@ require 'spec_helper' describe Supplier do let(:supplier){ build :supplier } - describe '.reset_counters!' do - it 'sets the counters to the right values' do - supplier1 = create :supplier - supplier2 = create :supplier - create_list :order, 2, :placed, supplier: supplier1 - create_list :order, 7, :active, supplier: supplier1 - create_list :order, 3, :placed, supplier: supplier2 - Supplier.reset_counters! - supplier1.orders_placed_count.should == 2 - supplier1.orders_in_process_count.should == 7 - supplier2.orders_placed_count.should == 3 + describe '#add_section_on_create through create' do + it 'calls add_section_on_create only for create' do + supplier = build :supplier + expect( supplier ).to receive(:add_section_on_create).once + supplier.save + supplier.name = "OtherSupplierName7" + expect( supplier ).not_to receive(:add_section_on_create) + supplier.save end - # it 'cleans counter values if orders are no longer available', broken: defined?($cb) do - # old_connection = Qwaiter::Counter.connection - # # this spec should run on the couchbase database - # Qwaiter::Counter.connection = $cb - # supplier = create :supplier - # Qwaiter::Counter.set "supplier_counter:#{supplier.id}:orders_placed", 9 - # supplier.orders_placed_count.should == 9 - # Supplier.reset_counters! - # sleep 1 - # supplier.orders_placed_count.should == 0 - # Qwaiter::Counter.connection = old_connection - # end - end - - describe '#reset_counters!' do - it 'sets the counters to the right values' do + it "creates a default section" do supplier = create :supplier - create_list :order, 5, :placed, supplier: supplier - create_list :order, 9, :active, supplier: supplier - supplier.reset_counters! - supplier.orders_placed_count.should == 5 - supplier.orders_in_process_count.should == 9 + supplier.sections.size.should be 1 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 720bc1a0..35dd0903 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,9 +20,9 @@ Dir.glob("spec/acceptance_steps/**/*steps.rb") { |f| load f, true } I18n.locale =I18n.default_locale Devise.stretches = 1 -Capybara.javascript_driver = :webkit +#Capybara.javascript_driver = :webkit #Capybara.javascript_driver = :poltergeist -#Capybara.javascript_driver = :selenium +Capybara.javascript_driver = :selenium Capybara.default_wait_time = 3 # ember needs more time than the default of 2 Capybara::Screenshot.webkit_options = { width: 1024, height: 768 } WebMock.disable_net_connect!(allow_localhost: true)