|
2 | 2 | require 'browser/database/sql'
|
3 | 3 |
|
4 | 4 | describe Browser::Database::SQL do
|
5 |
| - SQL = Browser::Database::SQL |
| 5 | + SQL = Browser::Database::SQL |
| 6 | + SIZE = 1024 * 1024 |
6 | 7 |
|
7 | 8 | describe '#new' do
|
8 | 9 | it 'sets the attributes properly' do
|
9 |
| - sql = SQL.new('test', description: 'trains', size: 1024) |
| 10 | + sql = SQL.new('test', description: 'trains', size: SIZE) |
10 | 11 |
|
11 | 12 | expect(sql.name).to eq('test')
|
12 | 13 | expect(sql.description).to eq('trains')
|
13 |
| - expect(sql.size).to eq(1024) |
| 14 | + expect(sql.size).to eq(SIZE) |
14 | 15 | end
|
15 | 16 |
|
16 | 17 | it 'sets the version properly' do
|
17 |
| - sql = SQL.new('test2', version: '1.0') |
| 18 | + sql = SQL.new('test2', version: '1.0', size: SIZE) |
18 | 19 | expect(sql.version).to eq('1.0')
|
19 | 20 |
|
20 |
| - sql = SQL.new('test') |
| 21 | + sql = SQL.new('test', size: SIZE) |
21 | 22 | expect(sql.version).to eq('')
|
22 | 23 | end
|
23 | 24 | end
|
24 | 25 |
|
25 | 26 | describe '#transaction' do
|
26 | 27 | async 'calls the block with the transaction' do
|
27 |
| - sql = SQL.new('test') |
| 28 | + sql = SQL.new('test', size: SIZE) |
28 | 29 |
|
29 | 30 | sql.transaction {|t|
|
30 | 31 | async {
|
|
34 | 35 | end
|
35 | 36 |
|
36 | 37 | async 'the transaction database is the right one' do
|
37 |
| - sql = SQL.new('test') |
| 38 | + sql = SQL.new('test', size: SIZE) |
38 | 39 |
|
39 | 40 | sql.transaction {|t|
|
40 | 41 | async {
|
|
47 | 48 | describe SQL::Transaction do
|
48 | 49 | describe '#query' do
|
49 | 50 | async 'returns a promise' do
|
50 |
| - sql = SQL.new('test') |
| 51 | + sql = SQL.new('test', size: SIZE) |
51 | 52 |
|
52 | 53 | sql.transaction {|t|
|
53 | 54 | async {
|
|
57 | 58 | end
|
58 | 59 |
|
59 | 60 | async 'resolves on success' do
|
60 |
| - sql = SQL.new('test') |
| 61 | + sql = SQL.new('test', size: SIZE) |
61 | 62 |
|
62 | 63 | sql.transaction {|t|
|
63 | 64 | t.query('CREATE TABLE IF NOT EXISTS test(ID INTEGER PRIMARY KEY ASC, a TEXT)').then {|r|
|
|
69 | 70 | end
|
70 | 71 |
|
71 | 72 | async 'rejects on failure' do
|
72 |
| - sql = SQL.new('test') |
| 73 | + sql = SQL.new('test', size: SIZE) |
73 | 74 |
|
74 | 75 | sql.transaction {|t|
|
75 | 76 | t.query('huehue').rescue {|e|
|
|
85 | 86 | describe SQL::Result do
|
86 | 87 | describe '#length' do
|
87 | 88 | async 'has the proper length' do
|
88 |
| - sql = SQL.new('test') |
| 89 | + sql = SQL.new('test', size: SIZE) |
89 | 90 |
|
90 | 91 | sql.transaction {|t|
|
91 | 92 | t.query('SELECT 1').then {|r|
|
|
99 | 100 |
|
100 | 101 | describe '#[]' do
|
101 | 102 | async 'returns a row' do
|
102 |
| - sql = SQL.new('test') |
| 103 | + sql = SQL.new('test', size: SIZE) |
103 | 104 |
|
104 | 105 | sql.transaction {|t|
|
105 | 106 | t.query('SELECT 1, 2, 3').then {|r|
|
|
114 | 115 | end
|
115 | 116 |
|
116 | 117 | async 'returns nil on missing row' do
|
117 |
| - sql = SQL.new('test') |
| 118 | + sql = SQL.new('test', size: SIZE) |
118 | 119 |
|
119 | 120 | sql.transaction {|t|
|
120 | 121 | t.query('SELECT 1, 2, 3').then {|r|
|
|
0 commit comments