bbmb 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2eb42efa3ac9ef669280070946e16ae722ef14c
4
- data.tar.gz: 69a025978a868913d8080c42b4ce574a5a1a33aa
3
+ metadata.gz: 3dbe4ee9956c4b592fa58f23029b197bfddaab36
4
+ data.tar.gz: 7bcba109d2eb190ec0996bb4c6bba86ba201c174
5
5
  SHA512:
6
- metadata.gz: 6aac0c230d1189d36609914bc5a8b495ed3543bf29ecf3563da1efe718ef486da98b8efe32d6924ed54651a5c1b03834ad50e6deb6b9cfb64026fd7847d622f0
7
- data.tar.gz: e552995962a29f4765599c010b53823362198dac681a328bd2ef5ef4f1aab497312462b9c2bb5d92751a32a42b67fcdafd38f01d5d3add14365b4dfdceabf215
6
+ metadata.gz: a0d55dbfa2322c13e3611ced131d1ee6184e21441c297ae78e828e1f708b9a704fe3f750caa86ff04f336e014e091cbbe4a200d2cb8772a8ee7fe8aff1fd32fd
7
+ data.tar.gz: dd46d10aa2c1dc52ddd01569c178bb755ae12eb43570fb8366397e1bbd6e195aa1cdd60e7d1ddc237e1744b95268a1c770ab7f330e85cb96e5056c1b6d0f7a83
data/.travis.yml CHANGED
@@ -8,13 +8,14 @@ sudo: false
8
8
  before_install:
9
9
  - gem --version
10
10
 
11
- script: bundle exec test/suite.rb
11
+ script: bundle exec rake test
12
12
 
13
13
  rvm:
14
14
  - 2.2
15
15
  - 2.3.0
16
+ - 2.3.1
16
17
  - ruby-head
17
-
18
+
18
19
  matrix:
19
20
  allow_failures:
20
21
  - rvm: ruby-head
@@ -23,3 +24,4 @@ notifications:
23
24
  email:
24
25
  recipients:
25
26
  - ngiger@ywesee.com
27
+ - yasaka@ywesee.com
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 2.0.9 / 20.07.2016
2
+
3
+ * Add EAN-Code as search target
4
+ * Create test suite by rake
5
+ * Remove unnecessary require and shebang from test files
6
+
1
7
  === 2.0.8 / 18.07.2016
2
8
 
3
9
  * Replaced Thread.exclusive with Mutex#synchronize
data/Rakefile CHANGED
@@ -1,12 +1,13 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
1
  lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'bbmb/version'
2
+ $:.unshift(lib) unless $:.include?(lib)
3
+
4
+ require 'rake/testtask'
5
+ require 'rake/clean'
6
6
  require "bundler/gem_tasks"
7
7
  require 'rspec/core/rake_task'
8
+ require 'bbmb/version'
8
9
 
9
- RSpec::Core::RakeTask.new(:spec)
10
+ task :default => :test
10
11
 
11
12
  # dependencies are now declared in bbmb.gemspec
12
13
 
@@ -16,6 +17,16 @@ task :gem => :build do
16
17
  end
17
18
 
18
19
  task :spec => :clean
19
-
20
- require 'rake/clean'
21
20
  CLEAN.include FileList['pkg/*.gem']
21
+
22
+ # rspec
23
+ RSpec::Core::RakeTask.new(:spec)
24
+
25
+ # unit test
26
+ dir = File.dirname(__FILE__)
27
+ Rake::TestTask.new do |t|
28
+ t.libs << 'test'
29
+ t.test_files = Dir.glob("#{dir}/test/**/test_*.rb")
30
+ t.warning = false
31
+ t.verbose = false
32
+ end
@@ -1,5 +1,3 @@
1
- # Html::State::Customers -- bbmb.ch -- 18.09.2006 -- hwyss@ywesee.com
2
-
3
1
  require 'ostruct'
4
2
  require 'bbmb/html/state/global_predefine'
5
3
  require 'bbmb/html/state/customer'
@@ -9,74 +7,78 @@ require 'bbmb/model/customer'
9
7
  module BBMB
10
8
  module Html
11
9
  module State
12
- class Customers < Global
13
- DIRECT_EVENT = :customers
14
- VIEW = View::Customers
15
- FILTER = [ :customer_id, :organisation, :plz, :city, :email ]
16
- def init
17
- start = Time.now
18
- @model = BBMB.persistence.all(Model::Customer)
19
- @sortby = [:organisation]
20
- BBMB.logger.debug('State') {
21
- sprintf("Customers#init: loaded %i customers in %1.5fs",
22
- @model.size, Time.now - start)
23
- }
24
- @filter = make_filter
25
- end
26
- def page(model)
27
- page = OpenStruct.new
28
- index = @session.user_input(:index).to_i
29
- step = @session.user.pagestep || BBMB.config.pagestep
30
- page.index = index
31
- page.first = index + 1
32
- page.step = step
33
- page.total = model.size
34
- page.customers = model[index, step]
35
- page.last = index + page.customers.size
36
- page
37
- end
38
- private
39
- def make_filter
40
- Proc.new { |model|
41
- input = @session.event_bound_user_input(:filter)
42
- if input
43
- pattern = Regexp.new(input.gsub('*', '.*'), 'ui')
44
- model = model.select { |customer|
45
- FILTER.any? { |key|
46
- value = customer.send(key).to_s
47
- next if value.empty?
48
- begin
49
- pattern.match(value)
50
- rescue ArgumentError
51
- false
10
+ class Customers < Global
11
+ DIRECT_EVENT = :customers
12
+ VIEW = View::Customers
13
+ FILTER = %i{customer_id ean13 organisation plz city email}
14
+
15
+ def init
16
+ start = Time.now
17
+ @model = BBMB.persistence.all(Model::Customer)
18
+ @sortby = [:organisation]
19
+ BBMB.logger.debug('State') {
20
+ sprintf("Customers#init: loaded %i customers in %1.5fs",
21
+ @model.size, Time.now - start)
22
+ }
23
+ @filter = make_filter
24
+ end
25
+
26
+ private
27
+
28
+ def make_filter
29
+ Proc.new { |model|
30
+ input = @session.event_bound_user_input(:filter)
31
+ if input
32
+ pattern = Regexp.new(input.gsub('*', '.*'), 'ui')
33
+ model = model.select { |customer|
34
+ FILTER.any? { |key|
35
+ value = customer.send(key).to_s
36
+ next if value.empty?
37
+ begin; pattern.match(value); rescue ArgumentError; false; end
38
+ }
39
+ }
40
+ end
41
+ get_sortby!
42
+ if @sortby.include?(:valid) || @sortby.include?(:last_login)
43
+ # decorates customer objects with (yus) session
44
+ model = model.map { |m| CustomerDecorator.new(m, @session) }
52
45
  end
46
+ model.sort! { |a, b| compare_entries(a, b) }
47
+ @sort_reverse && model.reverse!
48
+ page(model)
53
49
  }
54
- }
50
+ end
51
+
52
+ def page(model)
53
+ index = @session.user_input(:index).to_i
54
+ step = @session.user.pagestep || BBMB.config.pagestep
55
+ page = OpenStruct.new
56
+ page.index = index
57
+ page.first = index + 1
58
+ page.step = step
59
+ page.total = model.size
60
+ page.customers = model[index, step]
61
+ page.last = index + page.customers.size
62
+ page
63
+ end
55
64
  end
56
- get_sortby!
57
- if @sortby.include?(:valid) || @sortby.include?(:last_login)
58
- # decorates customer objects with (yus) session
59
- model = model.map { |m| CustomerDecorator.new(m, @session) }
65
+
66
+ class CustomerDecorator < SimpleDelegator
67
+
68
+ def initialize(model, session)
69
+ @source = model
70
+ @session = session
71
+ self.__setobj__(@source)
72
+ end
73
+
74
+ def last_login
75
+ @last_login ||= @session.user.last_login(email)
76
+ end
77
+
78
+ def valid
79
+ @valid ||= @session.user.entity_valid?(email).to_s
80
+ end
60
81
  end
61
- model.sort! { |a, b| compare_entries(a, b) }
62
- @sort_reverse && model.reverse!
63
- page(model)
64
- }
65
- end
66
- end
67
- class CustomerDecorator < SimpleDelegator
68
- def initialize(model, session)
69
- @source = model
70
- @session = session
71
- self.__setobj__(@source)
72
- end
73
- def last_login
74
- @last_login ||= @session.user.last_login(email)
75
- end
76
- def valid
77
- @valid ||= @session.user.entity_valid?(email).to_s
78
- end
79
- end
80
82
  end
81
83
  end
82
84
  end
data/lib/bbmb/version.rb CHANGED
@@ -1,6 +1,3 @@
1
- #!/usr/bin/env ruby
2
- # Bbmb -- bbmb.ch -- 17.12.2019 -- zdavatz@ywesee.com
3
-
4
1
  module BBMB
5
- VERSION = '2.0.8'
2
+ VERSION = '2.0.9'
6
3
  end
@@ -0,0 +1,87 @@
1
+ require 'test_helper'
2
+
3
+ require 'htmlgrid/list'
4
+ require 'bbmb/config'
5
+ require 'bbmb/model/customer'
6
+ require 'bbmb/html/state/viral/admin'
7
+ require 'bbmb/html/state/customers'
8
+
9
+ module BBMB
10
+ module Html
11
+ module State
12
+ class TestCustomers < Minitest::Test
13
+ include FlexMock::TestCase
14
+
15
+ def setup
16
+ super
17
+ BBMB.config = flexmock('config')
18
+ BBMB.logger = flexmock('logger')
19
+ BBMB.logger.should_receive(:debug)
20
+ BBMB.persistence = flexmock('persistence', :all => [])
21
+ app = flexmock('app')
22
+ user = flexmock('user', :pagestep => 1)
23
+ @session = flexmock('session', :app => app, :user => user)
24
+ @model = flexmock('model')
25
+ end
26
+
27
+ def test_filter_finds_customer_by_ean13
28
+ search_input = '7999999999999'
29
+ valid_customer = flexmock(
30
+ :customer_id => '1',
31
+ :organisation => '',
32
+ :plz => '',
33
+ :city => '',
34
+ :email => '',
35
+ :ean13 => '7999999999999'
36
+ )
37
+ unknown_customer = flexmock(
38
+ :customer_id => '99',
39
+ :organisation => '',
40
+ :plz => '',
41
+ :city => '',
42
+ :email => '',
43
+ :ean13 => ''
44
+ )
45
+ flexmock(Customers).new_instances
46
+ .should_receive(:page).with([valid_customer]).once
47
+ @session.should_receive(:event_bound_user_input)
48
+ .and_return(search_input)
49
+ @session.should_receive(:user_input).and_return(search_input)
50
+ state = Customers.new(@session, @model)
51
+ state.init
52
+ filter = state.instance_variable_get(:@filter)
53
+ filter.call([valid_customer, unknown_customer])
54
+ end
55
+
56
+ def test_filter_finds_customer_by_customer_name
57
+ search_input = 'Company'
58
+ valid_customer = flexmock(
59
+ :customer_id => '1',
60
+ :organisation => 'Test Company',
61
+ :plz => '',
62
+ :city => '',
63
+ :email => '',
64
+ :ean13 => ''
65
+ )
66
+ unknown_customer = flexmock(
67
+ :customer_id => '99',
68
+ :organisation => '',
69
+ :plz => '',
70
+ :city => '',
71
+ :email => '',
72
+ :ean13 => ''
73
+ )
74
+ flexmock(Customers).new_instances
75
+ .should_receive(:page).with([valid_customer]).once
76
+ @session.should_receive(:event_bound_user_input)
77
+ .and_return(search_input)
78
+ @session.should_receive(:user_input).and_return(search_input)
79
+ state = Customers.new(@session, @model)
80
+ state.init
81
+ filter = state.instance_variable_get(:@filter)
82
+ filter.call([valid_customer, unknown_customer])
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,15 +1,7 @@
1
- #!/usr/bin/env ruby
2
- # Model::TestCustomer -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
1
+ require 'test_helper'
3
2
 
4
- $: << File.expand_path('..', File.dirname(__FILE__))
5
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
-
7
- require "minitest/autorun"
8
- require 'flexmock/test_unit'
9
- require 'bbmb'
10
3
  require 'bbmb/model/customer'
11
4
  require 'bbmb/model/order'
12
- require 'stub/persistence'
13
5
 
14
6
  module BBMB
15
7
  module Model
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
- # Model::TestOrder -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
1
+ require 'test_helper'
8
2
  require 'bbmb/model/order'
9
3
  require 'date'
10
4
 
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
- # Model::TestProduct -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
1
+ require 'test_helper'
8
2
  require 'bbmb/model/product'
9
3
  require 'bbmb/model/promotion'
10
4
 
@@ -1,10 +1,3 @@
1
- #!/usr/bin/env ruby
2
- # Model::TestPromotion -- bbmb -- 14.08.2007 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
8
1
  require 'bbmb/model/promotion'
9
2
 
10
3
  module BBMB
@@ -1,6 +1,3 @@
1
- #!/usr/bin/env ruby
2
- # Persistence::Test -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
-
4
1
  require 'bbmb/model/customer'
5
2
  require 'bbmb/model/product'
6
3
 
data/test/test_bbmb.rb CHANGED
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
- # TestBbmb -- bbmb.ch -- 15.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'bbmb'
1
+ require 'test_helper'
8
2
 
9
3
  module BBMB
10
4
  class TestBbmb < Minitest::Test
@@ -0,0 +1,16 @@
1
+ require 'pathname'
2
+
3
+ root_dir = Pathname.new(__FILE__).realpath.parent.parent
4
+ lib_dir = root_dir.join('lib')
5
+ test_dir = root_dir.join('test')
6
+
7
+ $:.unshift(root_dir) unless $:.include?(root_dir)
8
+ $:.unshift(lib_dir) unless $:.include?(lib_dir)
9
+ $:.unshift(test_dir) unless $:.include?(test_dir)
10
+
11
+ require 'minitest/autorun'
12
+ require 'flexmock/test_unit'
13
+
14
+ require 'bbmb/config'
15
+
16
+ Dir[root_dir.join('test/support/**/*.rb')].each { |f| require f }
@@ -1,18 +1,8 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestInvoicer -- bbmb.ch -- 05.10.2006 -- hwyss@ywesee.com
3
-
4
-
5
- $: << File.expand_path('..', File.dirname(__FILE__))
6
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
7
-
8
-
9
- require "minitest/autorun"
10
- require 'flexmock/test_unit'
1
+ require 'test_helper'
2
+ require 'ostruct'
11
3
  require 'bbmb/config'
12
4
  require 'bbmb/util/invoicer'
13
5
  require 'bbmb/util/numbers'
14
- require 'ostruct'
15
- require 'stub/persistence'
16
6
 
17
7
  module BBMB
18
8
  module Util
@@ -1,10 +1,5 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestMail -- bbmb.ch -- 27.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
1
+ require 'test_helper'
2
+ require 'bbmb/config'
8
3
  require 'bbmb/util/mail'
9
4
 
10
5
  module BBMB
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestMoney -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
1
+ require 'test_helper'
8
2
  require 'bbmb/util/numbers'
9
3
 
10
4
  module BBMB
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestPasswordGenerator -- bbmb.ch -- 19.10.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
1
+ require 'test_helper'
8
2
  require 'bbmb/util/password_generator'
9
3
 
10
4
  module BBMB
@@ -1,12 +1,6 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestPollingManager -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
-
6
- require "minitest/autorun"
7
- require 'flexmock/test_unit'
8
- require 'bbmb/util/polling_manager'
1
+ require 'test_helper'
9
2
  require 'fileutils'
3
+ require 'bbmb/util/polling_manager'
10
4
 
11
5
  module BBMB
12
6
  module Util
@@ -1,15 +1,5 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestServer -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
3
-
4
- $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
- $: << File.expand_path('..', File.dirname(__FILE__))
6
-
7
- require "minitest/autorun"
8
- require 'flexmock/test_unit'
9
- require 'bbmb'
1
+ require 'test_helper'
10
2
  require 'bbmb/util/server'
11
- require 'stub/persistence'
12
- require 'flexmock'
13
3
 
14
4
  module BBMB
15
5
  module Util
@@ -1,13 +1,6 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestTargetDir -- bbmb -- 19.04.2007 -- hwyss@ywesee.com
3
-
4
-
5
- $: << File.expand_path('../lib', File.dirname(__FILE__))
6
-
7
- require 'minitest/autorun'
8
- require 'flexmock/test_unit'
9
- require 'bbmb/util/target_dir'
1
+ require 'test_helper'
10
2
  require 'fileutils'
3
+ require 'bbmb/util/target_dir'
11
4
 
12
5
  module BBMB
13
6
  module Util
@@ -1,11 +1,6 @@
1
- #!/usr/bin/env ruby
2
- # Util::TestTargetDir -- bbmb -- 19.04.2007 -- hwyss@ywesee.com
3
- $: << File.expand_path('../lib', File.dirname(__FILE__))
4
- require 'minitest/autorun'
5
- require 'flexmock/test_unit'
6
- require 'bbmb'
7
- require 'bbmb/util/transfer_dat'
1
+ require 'test_helper'
8
2
  require 'stringio'
3
+ require 'bbmb/util/transfer_dat'
9
4
 
10
5
  module BBMB
11
6
  module Util
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbmb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: odba
@@ -427,13 +427,14 @@ files:
427
427
  - lib/bbmb/version.rb
428
428
  - readme.md
429
429
  - test/data/ydim.yml
430
+ - test/html/state/test_customers.rb
430
431
  - test/model/test_customer.rb
431
432
  - test/model/test_order.rb
432
433
  - test/model/test_product.rb
433
434
  - test/model/test_promotion.rb
434
- - test/stub/persistence.rb
435
- - test/suite.rb
435
+ - test/support/stub/persistence.rb
436
436
  - test/test_bbmb.rb
437
+ - test/test_helper.rb
437
438
  - test/util/test_invoicer.rb
438
439
  - test/util/test_mail.rb
439
440
  - test/util/test_money.rb
@@ -468,13 +469,14 @@ specification_version: 4
468
469
  summary: ywesee distributed invoice manager
469
470
  test_files:
470
471
  - test/data/ydim.yml
472
+ - test/html/state/test_customers.rb
471
473
  - test/model/test_customer.rb
472
474
  - test/model/test_order.rb
473
475
  - test/model/test_product.rb
474
476
  - test/model/test_promotion.rb
475
- - test/stub/persistence.rb
476
- - test/suite.rb
477
+ - test/support/stub/persistence.rb
477
478
  - test/test_bbmb.rb
479
+ - test/test_helper.rb
478
480
  - test/util/test_invoicer.rb
479
481
  - test/util/test_mail.rb
480
482
  - test/util/test_money.rb
data/test/suite.rb DELETED
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # suite.rb -- oddb -- 08.09.2006 -- hwyss@ywesee.com
3
-
4
- here = File.expand_path(File.dirname(__FILE__))
5
- $: << here
6
-
7
- require 'find'
8
-
9
- failures = []
10
- okay = []
11
- Find.find(here) do |file|
12
- next if /test_invoicer/.match(file)
13
- if /test_.*\.rb$/o.match(file)
14
- short = File.basename(file, '.rb')
15
- if false # Run them all as a simple
16
- require file
17
- else
18
- log = short + '.log'
19
- cmd = "bash -c 'bundle exec #{file} --seed 62766 2>&1 | tee #{log}; ( exit ${PIPESTATUS[0]} )'"
20
- puts cmd
21
- res = system(cmd)
22
- if res
23
- puts "No problem executing #{short}"
24
- okay << short
25
- FileUtils.rm_f(log)
26
- else
27
- failures << short
28
- end
29
- end
30
- end
31
- end
32
- puts
33
- puts "The following tests showed no problems #{okay}"
34
- puts
35
- puts "The following tests had problems #{failures}"
36
- puts "Skipped test_invoicer"
37
- # --seed 33839 hangs
38
- # --seed 62766 passed
39
- exit(failures.size)