fixie 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2af6e750ed73e3bb2d5a4e36b8a22bb45d4e06af
4
- data.tar.gz: 2f7ee65828e9b1995f8b8a124f26cce0b5f3add6
3
+ metadata.gz: cf8ccf1b8d2425c0d7c0f5ff010bc855b543660f
4
+ data.tar.gz: 79b5f737d75f04e4ded85b6edbf2e7b8f5f62d76
5
5
  SHA512:
6
- metadata.gz: 68114ab1a2a4a8734e41c6ff891107c04825acd8029aee7ef2b0019d0d3251062d0ff5677759b03a28c3b56afb098d0d0dc5022b8c0f48fe5e95db9059cb1c06
7
- data.tar.gz: d855fe7758e8d058f827ba8178a97481bf7c3cd07827b54b1b4856dd7fb68b2100dccf846ad45a2e4853f0d06de174f9fd629d31c231d629e15192eaf14f274b
6
+ metadata.gz: 152e1c87de693a844abb68a44a0bb261293c801caa42ee54d96b3f3cb56a3152b45cdc5cfc5f6743bd463e862b01dedcacc6cbcd0fd1a1a9edb0141371a554c8
7
+ data.tar.gz: fcc429a2648ea9bcd11d4df13a56607dc441ed747c14ae634af599ae18fefb94ad566af0d48b8ff028b76dc8bdade174dfec35b04c168f8ce5e7077f1c257bc5
data/fixie.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "fixie"
5
- gem.version = "0.4.0"
5
+ gem.version = "0.5.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}
data/lib/fixie.rb CHANGED
@@ -3,6 +3,7 @@ require 'active_support'
3
3
  require 'active_support/core_ext'
4
4
  require 'erb'
5
5
  require 'sequel'
6
+ require 'set'
6
7
  require 'yaml'
7
8
  require 'zlib'
8
9
 
@@ -64,33 +65,43 @@ module Fixie
64
65
  end
65
66
 
66
67
  # Do a second pass to resolve associations and load data in DB
67
- all_fixtures[db_name].each do |table_name, fixtures|
68
- table = db[table_name]
69
- table.truncate(cascade: true, restart: true)
70
- table_has_created_at = table.columns.include?(:created_at)
71
- table_has_updated_at = table.columns.include?(:updated_at)
68
+ db.transaction(deferrable: true) do
69
+ all_fixtures[db_name].each do |table_name, fixtures|
70
+ table = db[table_name]
71
+ table.truncate(cascade: true, restart: true)
72
+ table_has_created_at = table.columns.include?(:created_at)
73
+ table_has_updated_at = table.columns.include?(:updated_at)
74
+
75
+ json_columns = Set.new
76
+ db.schema(table_name).each do |column,metadata|
77
+ json_columns << column if metadata[:db_type] == 'json'
78
+ end
72
79
 
73
- fixtures.each do |name, data|
80
+ fixtures.each do |name, data|
81
+
82
+ # Change attributes like city: baltimore to city_id: baltimore.id
83
+ data.keys.each do |attr|
84
+ associated_fixtures = all_fixtures[db_name][attr.to_s.pluralize.to_sym]
85
+ if associated_fixtures && table.columns.include?("#{attr}_id".to_sym)
86
+ associated_fixture = associated_fixtures[data[attr].to_sym]
87
+ if associated_fixture
88
+ data["#{attr}_id".to_sym] = associated_fixture[:id]
89
+ data.delete(attr)
90
+ end
91
+ end
74
92
 
75
- # Change attributes like city: baltimore to city_id: baltimore.id
76
- data.keys.each do |attr|
77
- associated_fixtures = all_fixtures[db_name][attr.to_s.pluralize.to_sym]
78
- if associated_fixtures && table.columns.include?("#{attr}_id".to_sym)
79
- associated_fixture = associated_fixtures[data[attr].to_sym]
80
- if associated_fixture
81
- data["#{attr}_id".to_sym] = associated_fixture[:id]
82
- data.delete(attr)
93
+ if db.database_type == :postgres && json_columns.include?(attr)
94
+ data[attr] = Sequel.pg_json(data[attr])
83
95
  end
84
96
  end
85
97
 
98
+ # Set created_at/updated_at if they exist
86
99
  data[:created_at] = now if table_has_created_at && !data.key?(:created_at)
87
100
  data[:updated_at] = now if table_has_updated_at && !data.key?(:updated_at)
88
- end
89
-
90
- # Set created_at/updated_at if they exist
91
101
 
92
- # Finally, replace the data in the DB
93
- table.insert(data)
102
+ # Finally, replace the data in the DB
103
+ table.insert(data)
104
+ end
94
105
  end
95
106
  end
96
107
  end
data/lib/fixie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fixie
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport