Class: TestMedwinCompanyPlugin

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_plugin/medwin.rb

Defined Under Namespace

Classes: StubApp, StubCompany, StubSession

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



73
74
75
76
77
78
79
80
# File 'test/test_plugin/medwin.rb', line 73

def setup
  @app = StubApp.new
  @plugin = ODDB::MedwinCompanyPlugin.new(@app)
  @plugin.session = StubSession.new
  target = File.expand_path('../../test/data/html/medwin', File.dirname(__FILE__))
  table = 'medwin.html'
  @html = File.read([target, table].join("/"))
end

- (Object) test_report



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'test/test_plugin/medwin.rb', line 81

def test_report
  @plugin.checked = 5
  @plugin.found = 4
  @plugin.updated = ['a','b','c']
  @plugin.errors = {
    'err_comp1'  => 'error one',
    'err_comp2'  => 'error two',
    'err_comp3'  => 'error three',
  }
  lines = @plugin.report
  expected = "Checked 5 Companies\nCompared 4 Medwin Entries\nUpdated  3 Companies:\na\nb\nc\nErrors:\nerr_comp1 => error one\nerr_comp2 => error two\nerr_comp3 => error three"
  assert_equal(expected, lines)
end

- (Object) test_update



94
95
96
97
98
99
100
101
102
103
# File 'test/test_plugin/medwin.rb', line 94

def test_update
  begin
    @plugin.instance_eval "alias :original_update_company :update_company\ndef update_company(comp)\n@update_company_called = true\nend\n"
    @plugin.update
    assert_equal(2, @plugin.checked)
    assert_equal(true, @plugin.update_company_called)
  ensure
    @plugin.instance_eval "alias :update_company :original_update_company\n"
  end
end

- (Object) test_update_company_data



113
114
115
116
117
118
119
120
121
122
123
# File 'test/test_plugin/medwin.rb', line 113

def test_update_company_data
  @plugin.updated.clear
  comp = @app.companies.values.first
  data = {
    :ean13 =>  '1234567891111',
  }
  @plugin.update_company_data(comp, data)
  result = @app.pointers.first
  assert_equal('comp1', result)
  assert_equal(['ecosol ag'], @plugin.updated)
end