fixture_farm 0.1.0 → 0.1.3
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.
- checksums.yaml +4 -4
- data/bin/fixture_farm.rb +23 -0
- data/lib/fixture_farm/active_record_extension.rb +17 -3
- data/lib/fixture_farm/fixture_recorder.rb +6 -4
- data/lib/fixture_farm/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 473a2a53021fcb6a622b9585c95769a343c7a5bbeaba96e25a347f96211ae156
|
4
|
+
data.tar.gz: ec5cbfaa5d092b11c1ba9716b47440795866fee6ae377d968ce1a44bf9a2e93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d32f502880c8e88e111c640cbdfa8ebfdf7a1369d06eb4421d55e9bfe3b014a91df399605037e77cdc0cbe8720c6a40808551f40c9d918af991d3dfba2ced2c5
|
7
|
+
data.tar.gz: e39d80ac110da1f67b1f219fe277bd83a85eb6e6e6dbac0cc4657fd6a22f6103ab469082a641c5caff11ed0b6d33f4a01c9fdcb1718c959422ef83819c1d318b
|
data/bin/fixture_farm.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/fixture_farm/fixture_recorder'
|
5
|
+
|
6
|
+
def usage
|
7
|
+
puts 'Usage: bundle exec fixture_farm <record|status|stop> [fixture_name_prefix]'
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
case ARGV[0]
|
12
|
+
when 'record'
|
13
|
+
usage unless ARGV[1]
|
14
|
+
FixtureFarm::FixtureRecorder.start_recording_session!(ARGV[1])
|
15
|
+
puts "Recording fixtures with prefix #{ARGV[1]}"
|
16
|
+
when 'status'
|
17
|
+
puts "Recording is #{FixtureFarm::FixtureRecorder.recording_session_in_progress? ? 'on' : 'off'}"
|
18
|
+
when 'stop'
|
19
|
+
FixtureFarm::FixtureRecorder.stop_recording_session!
|
20
|
+
puts 'Stopped recording'
|
21
|
+
else
|
22
|
+
usage
|
23
|
+
end
|
@@ -5,15 +5,29 @@ module FixtureFarm
|
|
5
5
|
def fixture_name
|
6
6
|
require 'active_record/fixtures'
|
7
7
|
|
8
|
-
return nil unless
|
8
|
+
return nil unless File.exist?(fixtures_file_path)
|
9
9
|
|
10
|
-
fixtures = YAML.load_file(
|
10
|
+
fixtures = YAML.load_file(fixtures_file_path)
|
11
11
|
fixtures.keys.find do |key|
|
12
12
|
ActiveRecord::FixtureSet.identify(key) == id
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def fixtures_file_path
|
17
|
+
existing_fixtures_file_path || candidate_fixtures_file_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def candidate_fixtures_file_path
|
21
|
+
klass = self.class
|
22
|
+
loop do
|
23
|
+
path = Rails.root.join('test', 'fixtures', "#{klass.to_s.underscore.pluralize}.yml")
|
24
|
+
return path if klass >= ActiveRecord::Base || !klass.columns.map(&:name).include?(klass.inheritance_column)
|
25
|
+
|
26
|
+
klass = klass.superclass
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def existing_fixtures_file_path
|
17
31
|
klass = self.class
|
18
32
|
|
19
33
|
while klass < ActiveRecord::Base
|
@@ -43,7 +43,7 @@ module FixtureFarm
|
|
43
43
|
subscriber = ActiveSupport::Notifications.subscribe 'sql.active_record' do |event|
|
44
44
|
payload = event.payload
|
45
45
|
|
46
|
-
next unless payload[:name] =~ /(
|
46
|
+
next unless payload[:name] =~ /([:\w]+) Create/
|
47
47
|
|
48
48
|
new_fixture_class_name = Regexp.last_match(1)
|
49
49
|
|
@@ -125,12 +125,14 @@ module FixtureFarm
|
|
125
125
|
end
|
126
126
|
end.to_h
|
127
127
|
|
128
|
-
|
128
|
+
fixtures_file_path = model_instance.fixtures_file_path
|
129
129
|
|
130
|
-
fixtures = File.exist?(
|
130
|
+
fixtures = File.exist?(fixtures_file_path) ? YAML.load_file(fixtures_file_path) : {}
|
131
131
|
fixtures[new_fixture_name] = yaml_attributes
|
132
132
|
|
133
|
-
|
133
|
+
FileUtils.mkdir_p(fixtures_file_path.dirname)
|
134
|
+
|
135
|
+
File.open(fixtures_file_path, 'w') do |file|
|
134
136
|
yaml = YAML.dump(fixtures).gsub(/\n(?=[^\s])/, "\n\n").delete_prefix("---\n\n")
|
135
137
|
file.write(yaml)
|
136
138
|
end
|
data/lib/fixture_farm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixture_farm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- artemave
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -35,6 +35,7 @@ email:
|
|
35
35
|
- mr@artem.rocks
|
36
36
|
executables:
|
37
37
|
- fixture_farm
|
38
|
+
- fixture_farm.rb
|
38
39
|
extensions: []
|
39
40
|
extra_rdoc_files: []
|
40
41
|
files:
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- README.md
|
43
44
|
- Rakefile
|
44
45
|
- bin/fixture_farm
|
46
|
+
- bin/fixture_farm.rb
|
45
47
|
- lib/fixture_farm.rb
|
46
48
|
- lib/fixture_farm/active_record_extension.rb
|
47
49
|
- lib/fixture_farm/controller_hook.rb
|