Class: ODDB::TestReadonlyServer

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
ext/readonly/test/test_readonly_server.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



20
21
22
# File 'ext/readonly/test/test_readonly_server.rb', line 20

def setup
  @serv = ReadonlyServer.new 
end

- (Object) test_remote_comparables



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ext/readonly/test/test_readonly_server.rb', line 23

def test_remote_comparables
  sequence = flexmock('sequence') do |seq|
    seq.should_receive(:atc_code)
    seq.should_receive(:comparable?).and_return(true)
  end
  package = flexmock('package') do |pac|
    pac.should_receive(:sequence).and_return(sequence)
    pac.should_receive(:comparable?).and_return(true)
  end
  flexstub(sequence) do |seq|
    seq.should_receive(:packages).and_return({1=>package})
  end
  flexstub(ODDB::Remote::Package) do |pac|
    pac.should_receive(:new).and_return(package)
  end
  atc = flexmock('atcs') do |at|
    at.should_receive(:sequences).and_return([sequence])
  end
  atcs = [atc]
  flexstub(ODBA) do |odba|
    odba.should_receive(:cache).and_return(flexmock('cache') do |cache|
      cache.should_receive(:retrieve_from_index).and_return(atcs)
    end)
  end
  assert_equal([package], @serv.remote_comparables(package))
end

- (Object) test_remote_each_atc_class



49
50
51
52
53
54
55
56
# File 'ext/readonly/test/test_readonly_server.rb', line 49

def test_remote_each_atc_class
  flexstub(ODDB::AtcClass) do |atc|
    atc.should_receive(:odba_extent).and_yield('atc')
  end
  @serv.remote_each_atc_class do |atc|
    assert_equal('atc', atc)
  end
end

- (Object) test_remote_each_company



57
58
59
60
61
62
63
64
65
# File 'ext/readonly/test/test_readonly_server.rb', line 57

def test_remote_each_company
  flexstub(ODDB::Company) do |comp|
    comp.should_receive(:odba_extent).and_return(['company'])
  end
  return_value = @serv.remote_each_company do |company|
    assert_equal('company', company)
  end
  assert_equal(nil, return_value)
end

- (Object) test_remote_each_package



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/readonly/test/test_readonly_server.rb', line 66

def test_remote_each_package
  package = flexmock('package') do |pac|
    pac.should_receive(:public?).and_return(true)
    pac.should_receive(:narcotic?).and_return(false)
  end
  flexstub(ODDB::Package) do |pac|
    pac.should_receive(:odba_extent).and_return([package])
  end
  flexstub(ODBA::DRbWrapper) do |drb|
    drb.should_receive(:new).and_return(package)
  end
  return_value = @serv.remote_each_package do |pac|
    assert_equal(package, pac)
  end
  assert_equal(nil, return_value)
end

- (Object) test_remote_export



82
83
84
85
86
87
88
89
90
91
# File 'ext/readonly/test/test_readonly_server.rb', line 82

def test_remote_export
  flexstub(ODDB::Exporter) do |klass|
    klass.should_receive(:new).and_return(flexmock('exp') do |exp|
      exp.should_receive(:export_helper).once.with('name', Proc).and_yield('path')
    end)
  end
  @serv.remote_export('name') do |path|
    assert_equal('path', path)
  end
end

- (Object) test_remote_packages



92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/readonly/test/test_readonly_server.rb', line 92

def test_remote_packages
  sequence = flexmock('sequence') do |seq|
    seq.should_receive(:public_packages).and_return('package')
  end
  flexstub(ODBA) do |odba|
    odba.should_receive(:cache).and_return(flexmock('cache') do |cache|
      cache.should_receive(:retrieve_from_index).once\
        .with('sequence_index_exact', 'query').and_return([sequence])
    end)
  end
  assert_equal(['package'], @serv.remote_packages('query'))
end