squixtures 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +148 -0
- data/Rakefile +2 -0
- data/lib/squixtures.rb +170 -0
- data/lib/squixtures/exceptions.rb +38 -0
- data/lib/squixtures/fixture.rb +96 -0
- data/lib/squixtures/fixtures.rb +17 -0
- data/lib/squixtures/helper_factory.rb +29 -0
- data/lib/squixtures/loader.rb +74 -0
- data/lib/squixtures/postgres_helper.rb +77 -0
- data/lib/squixtures/sqlite3_helper.rb +51 -0
- data/lib/squixtures/version.rb +6 -0
- data/squixtures.gemspec +20 -0
- data/test/README.md +41 -0
- data/test/config/database.yml +17 -0
- data/test/db/migrations/0001_create_users.rb +16 -0
- data/test/db/migrations/0002_create_orders.rb +15 -0
- data/test/db/migrations/0003_create_categories.rb +14 -0
- data/test/db/migrations/0004_create_products.rb +16 -0
- data/test/db/migrations/0005_create_order_products.rb +16 -0
- data/test/test/fixtures/alternative/categories.yml +10 -0
- data/test/test/fixtures/alternative/users.yml +12 -0
- data/test/test/fixtures/categories.yml +20 -0
- data/test/test/fixtures/order_products.yml +34 -0
- data/test/test/fixtures/orders.yml +18 -0
- data/test/test/fixtures/products.yml +27 -0
- data/test/test/fixtures/users.yml +19 -0
- data/test/test_squixtures_include.rb +139 -0
- metadata +125 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
one:
|
2
|
+
id: 1
|
3
|
+
name: Jackets
|
4
|
+
created: <%= Time.now %>
|
5
|
+
|
6
|
+
two:
|
7
|
+
id: 2
|
8
|
+
name: Footwear
|
9
|
+
created: <%= Time.now - 5400 %>
|
10
|
+
updated: <%= Time.now %>
|
11
|
+
|
12
|
+
three:
|
13
|
+
id: 3
|
14
|
+
name: Shirts
|
15
|
+
created: <%= Time.now %>
|
16
|
+
|
17
|
+
four:
|
18
|
+
id: 4
|
19
|
+
name: Sweaters
|
20
|
+
created: <%= Time.now %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
one:
|
2
|
+
id: 1
|
3
|
+
order_id: 1
|
4
|
+
product_id: 1
|
5
|
+
quantity: 1
|
6
|
+
created: <%= Time.now %>
|
7
|
+
|
8
|
+
two:
|
9
|
+
id: 2
|
10
|
+
order_id: 1
|
11
|
+
product_id: 2
|
12
|
+
quantity: 1
|
13
|
+
created: <%= Time.now %>
|
14
|
+
|
15
|
+
three:
|
16
|
+
id: 3
|
17
|
+
order_id: 2
|
18
|
+
product_id: 3
|
19
|
+
quantity: 3
|
20
|
+
created: <%= Time.now %>
|
21
|
+
|
22
|
+
four:
|
23
|
+
id: 4
|
24
|
+
order_id: 3
|
25
|
+
product_id: 4
|
26
|
+
quantity: 2
|
27
|
+
created: <%= Time.now %>
|
28
|
+
|
29
|
+
five:
|
30
|
+
id: 5
|
31
|
+
order_id: 3
|
32
|
+
product_id: 1
|
33
|
+
quantity: 1
|
34
|
+
created: <%= Time.now %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
one:
|
2
|
+
id: 1
|
3
|
+
category_id: 1
|
4
|
+
name: Waterwear Jacket
|
5
|
+
cost: 112.75
|
6
|
+
created: <%= Time.now %>
|
7
|
+
|
8
|
+
two:
|
9
|
+
id: 2
|
10
|
+
category_id: 2
|
11
|
+
name: Hiking Boots
|
12
|
+
cost: 89.99
|
13
|
+
created: <%= Time.now %>
|
14
|
+
|
15
|
+
three:
|
16
|
+
id: 3
|
17
|
+
category_id: 3
|
18
|
+
name: Lumberjack Shirt
|
19
|
+
cost: 31.75
|
20
|
+
created: <%= Time.now %>
|
21
|
+
|
22
|
+
four:
|
23
|
+
id: 4
|
24
|
+
category_id: 2
|
25
|
+
name: Running Shoes
|
26
|
+
cost: 63.50
|
27
|
+
created: <%= Time.now %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
one:
|
2
|
+
id: 1
|
3
|
+
email: jsmith@blah.com
|
4
|
+
passwd: password
|
5
|
+
status: 1
|
6
|
+
created: <%= Time.now %>
|
7
|
+
two:
|
8
|
+
id: 2
|
9
|
+
email: joe.bloggs@lalala.org
|
10
|
+
passwd: blurgh
|
11
|
+
status: 1
|
12
|
+
created: <%= Time.now %>
|
13
|
+
three:
|
14
|
+
id: 3
|
15
|
+
email: a.stanton@good.bad.ugly.com
|
16
|
+
passwd: heyhey!
|
17
|
+
status: -1
|
18
|
+
created: <%= Time.now - 36000 %>
|
19
|
+
updated: <%= Time.now %>
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'squixtures'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'stringio'
|
5
|
+
require 'turn'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
LogJam.configure({:loggers => [{:default => true,
|
9
|
+
:file => "sqixtures.log",
|
10
|
+
:level => "DEBUG",
|
11
|
+
:name => "main"}]})
|
12
|
+
|
13
|
+
class TestSquixturesInclude < Test::Unit::TestCase
|
14
|
+
include Squixtures::Fixtures
|
15
|
+
|
16
|
+
def setup
|
17
|
+
settings = YAML.load_file("./config/database.yml")
|
18
|
+
url = Squixtures.get_connection_url(settings['test'])
|
19
|
+
@connection = Sequel.connect(url)
|
20
|
+
clear_all_tables
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
@connection.disconnect
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_single_fixture_load
|
28
|
+
fixtures :users
|
29
|
+
|
30
|
+
users = @connection[:users]
|
31
|
+
assert_equal(3, users.all.count)
|
32
|
+
|
33
|
+
user = users[:id => 1]
|
34
|
+
assert(!user.nil?)
|
35
|
+
assert_equal("jsmith@blah.com", user[:email])
|
36
|
+
assert_equal("password", user[:passwd])
|
37
|
+
assert_equal(1, user[:status])
|
38
|
+
assert(!user[:created].nil?)
|
39
|
+
assert(user[:updated].nil?)
|
40
|
+
|
41
|
+
user = users[:id => 2]
|
42
|
+
assert(!user.nil?)
|
43
|
+
assert_equal("joe.bloggs@lalala.org", user[:email])
|
44
|
+
assert_equal("blurgh", user[:passwd])
|
45
|
+
assert_equal(1, user[:status])
|
46
|
+
assert(!user[:created].nil?)
|
47
|
+
assert(user[:updated].nil?)
|
48
|
+
|
49
|
+
user = users[:id => 3]
|
50
|
+
assert(!user.nil?)
|
51
|
+
assert_equal("a.stanton@good.bad.ugly.com", user[:email])
|
52
|
+
assert_equal("heyhey!", user[:passwd])
|
53
|
+
assert_equal(-1, user[:status])
|
54
|
+
assert(!user[:created].nil?)
|
55
|
+
assert(!user[:updated].nil?)
|
56
|
+
assert(user[:created] != user[:updated])
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_all_fixtures_load
|
60
|
+
fixtures :all
|
61
|
+
|
62
|
+
users = @connection[:users]
|
63
|
+
assert_equal(3, users.all.count)
|
64
|
+
|
65
|
+
categories = @connection[:categories]
|
66
|
+
assert_equal(4, categories.all.count)
|
67
|
+
|
68
|
+
products = @connection[:products]
|
69
|
+
assert_equal(4, products.all.count)
|
70
|
+
|
71
|
+
orders = @connection[:orders]
|
72
|
+
assert_equal(3, orders.all.count)
|
73
|
+
|
74
|
+
order_products = @connection[:order_products]
|
75
|
+
assert_equal(5, order_products.all.count)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_with_clear_tables_off
|
79
|
+
users = @connection[:users]
|
80
|
+
users.insert(:id => 1000,
|
81
|
+
:email => 'fblack@outthere.com',
|
82
|
+
:passwd => 'obscure',
|
83
|
+
:status => 1,
|
84
|
+
:created => Time.now)
|
85
|
+
|
86
|
+
Squixtures.configuration[:clear_tables] = false
|
87
|
+
fixtures :users
|
88
|
+
|
89
|
+
assert_equal(4, users.all.count)
|
90
|
+
|
91
|
+
user = users[:id => 1000]
|
92
|
+
assert(!user.nil?)
|
93
|
+
Squixtures.configuration[:clear_tables] = true
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_loading_from_alternative_fixtures_dir
|
97
|
+
Squixtures.fixtures_dir = "#{Dir.getwd}/test/fixtures/alternative"
|
98
|
+
fixtures :users
|
99
|
+
|
100
|
+
users = @connection[:users]
|
101
|
+
assert_equal(2, users.all.count)
|
102
|
+
|
103
|
+
user = users[:id => 10]
|
104
|
+
assert(!user.nil?)
|
105
|
+
|
106
|
+
user = users[:id => 11]
|
107
|
+
assert(!user.nil?)
|
108
|
+
Squixtures.fixtures_dir = nil
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_transactional_load_with_failure
|
112
|
+
Squixtures.fixtures_dir = "#{Dir.getwd}/test/fixtures/alternative"
|
113
|
+
Squixtures.transactional = true
|
114
|
+
|
115
|
+
# Should fail on second fixture but load first without issue.
|
116
|
+
assert_raise(Squixtures::SquixtureError) do
|
117
|
+
fixtures :users, :categories
|
118
|
+
end
|
119
|
+
|
120
|
+
users = @connection[:users]
|
121
|
+
assert_equal(2, users.all.count)
|
122
|
+
|
123
|
+
categories = @connection[:categories]
|
124
|
+
assert_equal(0, categories.all.count)
|
125
|
+
|
126
|
+
Squixtures.transactional = false
|
127
|
+
Squixtures.fixtures_dir = nil
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def clear_all_tables
|
133
|
+
@connection[:order_products].delete
|
134
|
+
@connection[:orders].delete
|
135
|
+
@connection[:products].delete
|
136
|
+
@connection[:categories].delete
|
137
|
+
@connection[:users].delete
|
138
|
+
end
|
139
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: squixtures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Wood
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sequel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.36.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.36.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: logjam
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.3
|
46
|
+
description: Squixtures is a library that provides a data fixtures facility ala the
|
47
|
+
fixtures typically used in unit tests. The library makes use of the Sequel library
|
48
|
+
to provide a degree of database independence (needs more work) and use the LogJam
|
49
|
+
library to unify logging output.
|
50
|
+
email:
|
51
|
+
- ruby@blacknorth.com
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/squixtures.rb
|
62
|
+
- lib/squixtures/exceptions.rb
|
63
|
+
- lib/squixtures/fixture.rb
|
64
|
+
- lib/squixtures/fixtures.rb
|
65
|
+
- lib/squixtures/helper_factory.rb
|
66
|
+
- lib/squixtures/loader.rb
|
67
|
+
- lib/squixtures/postgres_helper.rb
|
68
|
+
- lib/squixtures/sqlite3_helper.rb
|
69
|
+
- lib/squixtures/version.rb
|
70
|
+
- squixtures.gemspec
|
71
|
+
- test/README.md
|
72
|
+
- test/config/database.yml
|
73
|
+
- test/db/migrations/0001_create_users.rb
|
74
|
+
- test/db/migrations/0002_create_orders.rb
|
75
|
+
- test/db/migrations/0003_create_categories.rb
|
76
|
+
- test/db/migrations/0004_create_products.rb
|
77
|
+
- test/db/migrations/0005_create_order_products.rb
|
78
|
+
- test/test/fixtures/alternative/categories.yml
|
79
|
+
- test/test/fixtures/alternative/users.yml
|
80
|
+
- test/test/fixtures/categories.yml
|
81
|
+
- test/test/fixtures/order_products.yml
|
82
|
+
- test/test/fixtures/orders.yml
|
83
|
+
- test/test/fixtures/products.yml
|
84
|
+
- test/test/fixtures/users.yml
|
85
|
+
- test/test_squixtures_include.rb
|
86
|
+
homepage: ''
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.24
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Simple fixtures functionality.
|
110
|
+
test_files:
|
111
|
+
- test/README.md
|
112
|
+
- test/config/database.yml
|
113
|
+
- test/db/migrations/0001_create_users.rb
|
114
|
+
- test/db/migrations/0002_create_orders.rb
|
115
|
+
- test/db/migrations/0003_create_categories.rb
|
116
|
+
- test/db/migrations/0004_create_products.rb
|
117
|
+
- test/db/migrations/0005_create_order_products.rb
|
118
|
+
- test/test/fixtures/alternative/categories.yml
|
119
|
+
- test/test/fixtures/alternative/users.yml
|
120
|
+
- test/test/fixtures/categories.yml
|
121
|
+
- test/test/fixtures/order_products.yml
|
122
|
+
- test/test/fixtures/orders.yml
|
123
|
+
- test/test/fixtures/products.yml
|
124
|
+
- test/test/fixtures/users.yml
|
125
|
+
- test/test_squixtures_include.rb
|