fixie 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 942d233e8db89efea3069363c9bc729f65b38fed
4
+ data.tar.gz: c8810c4a8e5f7b403394ede43137e0ff081d9917
5
+ SHA512:
6
+ metadata.gz: 12895d4237d004b66be0ac8a4192f10be5fd80609a09ed616f35c3fdeece9d51e18319dbcfa47cd468eddc8da4391daa88c99a4478ca702d1ab12f2e53b92751
7
+ data.tar.gz: a8f886d191335f04b8b105cd305668d445e906f57d659b1656002b93513fb737031257b968f3a5b59b801b040e445eaae4d7a7fd20e9bfd811e6aa6fd536bc93
data/README.md CHANGED
@@ -26,7 +26,7 @@ To use Fixie, you first create some fixture files in a directory called `fixture
26
26
  ├── cities.yml
27
27
  └── countries.yml
28
28
 
29
- You must put all your fixtures into a subdirectory of the `fixtures` directory. The name of the directory should be a good logical name for the database that the fixtures. If you have only one database, `default` is a reasonable name, but if you have an app with customers in one database and orders in another, you would name them `customers` and `orders`.
29
+ You must put all your fixtures into a subdirectory of the `fixtures` directory. The name of the directory should be a good logical name for the database that the fixtures. If you have only one database, you should use `default` as the name, but if you have an app with customers in one database and orders in another, you would name them `customers` and `orders`.
30
30
 
31
31
  Fixie uses Sequel to load the data into the database. Fixie will work even if you aren't using Sequel in your application. You must configure the Fixie databases and then call `load_fixtures` to get the fixtures to actually be loaded. Your test helper might look like this:
32
32
 
@@ -36,7 +36,23 @@ Fixie.dbs[:default] = Sequel.sqlite
36
36
  Fixie.load_fixtures
37
37
  ```
38
38
 
39
- Now all the fixtures will be loaded into the test database. In order to access them from a test, you need to mix the `Fixie::Model` module into the base class of your models. For example, say you have models defined like this:
39
+ Now all the fixtures will be loaded into the default database. In order to access them from a test, you can the fixture as a Hash like this:
40
+
41
+ ``` ruby
42
+ Fixie::Fixtures.countries(:us)
43
+ ```
44
+
45
+ You can also include the `Fixie::Fixtures` model in your tests and then just call the method directly:
46
+
47
+ ``` ruby
48
+ include Fixie::Fixtures
49
+
50
+ def test_something
51
+ assert_equal "US", countries(:us)
52
+ end
53
+ ```
54
+
55
+ If you have models in your application and you want to get instances of the model back instead of Hashes, you need to mix the `Fixie::Model` module into the base class of your models. For example, say you have models defined like this:
40
56
 
41
57
  ``` ruby
42
58
  class Model
@@ -63,12 +79,6 @@ def test_something
63
79
  end
64
80
  ```
65
81
 
66
- You can also access the fixtures in any context once they have been loaded like this:
67
-
68
- ``` ruby
69
- Fixie.fixture(:default, :countries, :us)
70
- ```
71
-
72
82
  Fixtures are defined in YAML files like this:
73
83
 
74
84
  ``` yaml
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "fixie"
5
- gem.version = "0.2.0"
5
+ gem.version = "0.3.0"
6
6
  gem.authors = ["Paul Barry"]
7
7
  gem.email = ["mail@paulbarry.com"]
8
8
  gem.description = %q{A standalone library for managing test fixture data}
@@ -1,4 +1,5 @@
1
1
  require 'fixie/version'
2
+ require 'active_support'
2
3
  require 'active_support/core_ext'
3
4
  require 'erb'
4
5
  require 'sequel'
@@ -35,8 +36,8 @@ module Fixie
35
36
 
36
37
  def self.all_fixtures
37
38
  @all_fixtures ||= begin
38
- unless Dir.exists?(Fixie.dir)
39
- raise "There is no directory in the $LOAD_PATH with a 'fixtures' directory in it"
39
+ unless Fixie.dir.present? && Dir.exists?(Fixie.dir)
40
+ raise "There is no directory in the load path with a 'fixtures' directory in it"
40
41
  end
41
42
 
42
43
  all_fixtures = {}
@@ -53,15 +54,19 @@ module Fixie
53
54
  fixtures = YAML.load(ERB.new(IO.read(file)).result(binding)).symbolize_keys
54
55
 
55
56
  fixtures.each do |name, data|
56
- data["id"] ||= identify(name)
57
+ data[:id] ||= identify(name)
58
+ data.symbolize_keys!
57
59
  end
58
60
 
61
+ Fixie::Fixtures.define_fixture_accessor(db_name, table_name.to_sym)
62
+
59
63
  all_fixtures[db_name][table_name.to_sym] = fixtures
60
64
  end
61
65
 
62
66
  # Do a second pass to resolve associations and load data in DB
63
67
  all_fixtures[db_name].each do |table_name, fixtures|
64
68
  table = db[table_name]
69
+ table.delete
65
70
  table_has_created_at = table.columns.include?(:created_at)
66
71
  table_has_updated_at = table.columns.include?(:updated_at)
67
72
 
@@ -73,18 +78,18 @@ module Fixie
73
78
  if associated_fixtures && table.columns.include?("#{attr}_id".to_sym)
74
79
  associated_fixture = associated_fixtures[data[attr].to_sym]
75
80
  if associated_fixture
76
- data["#{attr}_id"] = associated_fixture['id']
81
+ data["#{attr}_id".to_sym] = associated_fixture[:id]
77
82
  data.delete(attr)
78
83
  end
79
84
  end
80
85
 
81
- data["created_at"] = now if table_has_created_at && !data.key?("created_at")
82
- data["updated_at"] = now if table_has_updated_at && !data.key?("updated_at")
86
+ data[:created_at] = now if table_has_created_at && !data.key?(:created_at)
87
+ data[:updated_at] = now if table_has_updated_at && !data.key?(:updated_at)
83
88
  end
84
89
 
85
90
  # Set created_at/updated_at if they exist
86
91
 
87
- # Finally, put the data in the DB
92
+ # Finally, replace the data in the DB
88
93
  table.insert(data)
89
94
  end
90
95
  end
@@ -117,6 +122,16 @@ module Fixie
117
122
  Fixie.all_fixtures
118
123
  end
119
124
 
125
+ module Fixtures
126
+ extend self
127
+
128
+ def define_fixture_accessor(db_name, table_name)
129
+ define_method(table_name) do |fixture_name|
130
+ Fixie.fixture(db_name, table_name, fixture_name)
131
+ end
132
+ end
133
+ end
134
+
120
135
  module Model
121
136
  # This will return an instance of this class loaded from
122
137
  # the fixtures matching the name
@@ -142,7 +157,7 @@ module Fixie
142
157
  new(fixture)
143
158
  end
144
159
 
145
- # This method determine which database is used to load the fixture.
160
+ # This method determines which database is used to load the fixture.
146
161
  # The default implementation is to check the class to see if it has a
147
162
  # namespace, like 'Foo::Bar', and if it does, return :foo.
148
163
  # If it does not have a namespace, it will return :default.
@@ -1,3 +1,3 @@
1
1
  module Fixie
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,7 +1,8 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'logger'
3
3
  require 'sequel'
4
4
  require 'sqlite3'
5
+ require 'fileutils'
5
6
 
6
7
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
7
8
  $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
@@ -26,6 +27,7 @@ class City < Model
26
27
  attr_accessor :name, :country, :country_id, :created_at
27
28
  end
28
29
 
30
+ FileUtils.mkdir_p 'log'
29
31
  db = Sequel.sqlite(logger: Logger.new("log/test.log"))
30
32
 
31
33
  db.create_table :countries do
@@ -54,7 +56,7 @@ Fixie.extend FakeGetText
54
56
  Fixie.load_fixtures
55
57
  Model.extend Fixie::Model
56
58
 
57
- class FixieTest < MiniTest::Unit::TestCase
59
+ class FixieTest < Minitest::Test
58
60
 
59
61
  def test_explicit_id
60
62
  assert_equal "United States", Country.fixture(:us).name
@@ -73,7 +75,7 @@ class FixieTest < MiniTest::Unit::TestCase
73
75
  end
74
76
 
75
77
  def test_get
76
- assert_equal "US", Fixie.fixture(:default, :countries, :us)["code"]
78
+ assert_equal "US", Fixie.fixture(:default, :countries, :us)[:code]
77
79
  end
78
80
 
79
81
  def test_loaded_in_db
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Paul Barry
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sequel
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: sqlite3
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: A standalone library for managing test fixture data
@@ -66,7 +59,7 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
62
+ - ".gitignore"
70
63
  - Gemfile
71
64
  - LICENSE.txt
72
65
  - README.md
@@ -79,30 +72,28 @@ files:
79
72
  - test/fixtures/default/countries.yml
80
73
  homepage: http://github.com/pjb3/fixie
81
74
  licenses: []
75
+ metadata: {}
82
76
  post_install_message:
83
77
  rdoc_options: []
84
78
  require_paths:
85
79
  - lib
86
80
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
81
  requirements:
89
- - - ! '>='
82
+ - - ">="
90
83
  - !ruby/object:Gem::Version
91
84
  version: '0'
92
85
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
86
  requirements:
95
- - - ! '>='
87
+ - - ">="
96
88
  - !ruby/object:Gem::Version
97
89
  version: '0'
98
90
  requirements: []
99
91
  rubyforge_project:
100
- rubygems_version: 1.8.24
92
+ rubygems_version: 2.4.5
101
93
  signing_key:
102
- specification_version: 3
94
+ specification_version: 4
103
95
  summary: A standalone library for managing test fixture data
104
96
  test_files:
105
97
  - test/fixie_test.rb
106
98
  - test/fixtures/default/cities.yml
107
99
  - test/fixtures/default/countries.yml
108
- has_rdoc: