taps 0.2.26 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,88 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
- require File.dirname(__FILE__) + '/../lib/taps/client_session'
3
-
4
- describe Taps::ClientSession do
5
- before do
6
- @client = Taps::ClientSession.new('sqlite://my.db', 'http://example.com:3000', 1000)
7
- @client.stubs(:session_resource).returns(mock('session resource'))
8
- end
9
-
10
- it "starts a session and yields the session object to the block" do
11
- Taps::ClientSession.start('x', 'y', 1000) do |session|
12
- session.database_url.should == 'x'
13
- session.remote_url.should == 'y'
14
- session.default_chunksize.should == 1000
15
- end
16
- end
17
-
18
- it "opens the local db connection via sequel and the database url" do
19
- Sequel.expects(:connect).with('sqlite://my.db').returns(:con)
20
- @client.db.should == :con
21
- end
22
-
23
- it "creates a restclient resource to the remote server" do
24
- @client.server.url.should == 'http://example.com:3000'
25
- end
26
-
27
- it "verifies the db version, receive the schema, data, indexes, then reset the sequences" do
28
- @client.expects(:verify_server)
29
- @client.expects(:cmd_receive_schema)
30
- @client.expects(:cmd_receive_data)
31
- @client.expects(:cmd_receive_indexes)
32
- @client.expects(:cmd_reset_sequences)
33
- @client.cmd_receive.should.be.nil
34
- end
35
-
36
- it "checks the version of the server by seeing if it has access" do
37
- @client.stubs(:server).returns(mock('server'))
38
- @request = mock('request')
39
- @client.server.expects(:[]).with('/').returns(@request)
40
- @request.expects(:get).with({:taps_version => Taps.compatible_version})
41
-
42
- lambda { @client.verify_server }.should.not.raise
43
- end
44
-
45
- it "receives data from a remote taps server" do
46
- @client.stubs(:puts)
47
- @progressbar = mock('progressbar')
48
- ProgressBar.stubs(:new).with('mytable', 2).returns(@progressbar)
49
- @progressbar.stubs(:inc)
50
- @progressbar.stubs(:finish)
51
- @mytable = mock('mytable')
52
- @client.expects(:fetch_remote_tables_info).returns([ { :mytable => 2 }, 2 ])
53
- @client.stubs(:db).returns(mock('db'))
54
- @client.db.stubs(:[]).with(:mytable).returns(@mytable)
55
- @client.expects(:fetch_table_rows).with(:mytable, 1000, 0).returns([ 1000, { :header => [:x, :y], :data => [[1, 2], [3, 4]] } ])
56
- @client.expects(:fetch_table_rows).with(:mytable, 1000, 2).returns([ 1000, { }])
57
- @mytable.expects(:import).with([:x, :y], [[1, 2], [3, 4]])
58
-
59
- lambda { @client.cmd_receive_data }.should.not.raise
60
- end
61
-
62
- it "fetches remote tables info from taps server" do
63
- @marshal_data = Marshal.dump({ :mytable => 2 })
64
- @client.session_resource.stubs(:[]).with('tables').returns(mock('tables'))
65
- @client.session_resource['tables'].stubs(:get).with(:taps_version => Taps.compatible_version).returns(@marshal_data)
66
- @client.fetch_remote_tables_info.should == [ { :mytable => 2 }, 2 ]
67
- end
68
-
69
- it "fetches table rows given a chunksize and offset from taps server" do
70
- @data = { :header => [ :x, :y ], :data => [ [1, 2], [3, 4] ] }
71
- @gzip_data = Taps::Utils.gzip(Marshal.dump(@data))
72
- Taps::Utils.stubs(:calculate_chunksize).with(1000).yields(1000).returns(1000)
73
-
74
- @response = mock('response')
75
- @client.session_resource.stubs(:[]).with('tables/mytable/1000?offset=0').returns(mock('table resource'))
76
- @client.session_resource['tables/mytable/1000?offset=0'].expects(:get).with(:taps_version => Taps.compatible_version).returns(@response)
77
- @response.stubs(:to_s).returns(@gzip_data)
78
- @response.stubs(:headers).returns({ :taps_checksum => Taps::Utils.checksum(@gzip_data) })
79
- @client.fetch_table_rows('mytable', 1000, 0).should == [ 1000, { :header => [:x, :y], :data => [[1, 2], [3, 4]] } ]
80
- end
81
-
82
- it "hides the password in urls" do
83
- @client.safe_url("postgres://postgres:password@localhost/mydb").should == "postgres://postgres:[hidden]@localhost/mydb"
84
- @client.safe_url("postgres://postgres@localhost/mydb").should == "postgres://postgres@localhost/mydb"
85
- @client.safe_url("http://x:y@localhost:5000").should == "http://x:[hidden]@localhost:5000"
86
- end
87
- end
88
-
data/spec/schema_spec.rb DELETED
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
- require File.dirname(__FILE__) + '/../lib/taps/schema'
3
-
4
- describe Taps::Schema do
5
- before do
6
- Taps::AdapterHacks.stubs(:load)
7
- @connection = mock("AR connection")
8
- ActiveRecord::Base.stubs(:connection).returns(@connection)
9
- end
10
-
11
- it "parses a database url and returns a config hash for activerecord" do
12
- Taps::Schema.create_config("postgres://myuser:mypass@localhost/mydb").should == {
13
- 'adapter' => 'postgresql',
14
- 'database' => 'mydb',
15
- 'username' => 'myuser',
16
- 'password' => 'mypass',
17
- 'host' => 'localhost'
18
- }
19
- end
20
-
21
- it "translates sqlite in the database url to sqlite3" do
22
- Taps::Schema.create_config("sqlite://mydb")['adapter'].should == 'sqlite3'
23
- end
24
-
25
- it "translates sqlite database path" do
26
- Taps::Schema.create_config("sqlite://pathtodb/mydb")['database'].should == 'pathtodb/mydb'
27
- Taps::Schema.create_config("sqlite:///pathtodb/mydb")['database'].should == '/pathtodb/mydb'
28
- Taps::Schema.create_config("sqlite:///pathtodb/mydb?encoding=utf8")['database'].should == '/pathtodb/mydb'
29
- end
30
-
31
- it "connects activerecord to the database" do
32
- Taps::Schema.expects(:create_config).with("postgres://myuser:mypass@localhost/mydb").returns("db config")
33
- ActiveRecord::Base.expects(:establish_connection).with("db config").returns(true)
34
- Taps::Schema.connection("postgres://myuser:mypass@localhost/mydb").should == true
35
- end
36
-
37
- it "resets the db tables' primary keys" do
38
- Taps::Schema.stubs(:connection)
39
- ActiveRecord::Base.connection.expects(:respond_to?).with(:reset_pk_sequence!).returns(true)
40
- ActiveRecord::Base.connection.stubs(:tables).returns(['table1'])
41
- ActiveRecord::Base.connection.expects(:reset_pk_sequence!).with('table1')
42
- should.not.raise { Taps::Schema.reset_db_sequences("postgres://myuser:mypass@localhost/mydb") }
43
- end
44
- end
45
-