engine_cart 1.2.0 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8180b96510ff7c10e9a21625cca64768f90b52ee
4
- data.tar.gz: 5872062cf96944e5ee713caf54dd49e8afe846e5
3
+ metadata.gz: 40c9b046588c71b4993de3134cdf47890d88fa84
4
+ data.tar.gz: 69cc69b06b1419055b1c8e28221f23785b8db7e7
5
5
  SHA512:
6
- metadata.gz: 64e60694001844c9c0f171dc72364740beae0395a331f65609c73911f508eb5c265ddc785882318799fef9831e8d07b92e58460529ea58c567148b37b1b3fecd
7
- data.tar.gz: 71e3fdbff0b743638aa212a4cc9b2ec313dd00b6c6ad1f711bf649f304128ecf0821f2b18d9f5dfbd56f7db629322208ef0c58985e8e0c7c2c9680b177df8e7e
6
+ metadata.gz: 6633db11d1f53e58552a84f399d1829db1a303d529ac2b1a0d0437c6f6358cf7080fbfd9af242a02f9c41c9c97b2a72b950ff31d8b473302af59bdc85e8561d2
7
+ data.tar.gz: abb7179ce65f9050b113ec94a7e4139a1ad7e1a0953fe179b24512243b358c01201cf0d40a12905a137ad8727183daef61060ea8a3824f85a8efb1d2cf1d954f
data/.travis.yml CHANGED
@@ -1,16 +1,7 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.4.1
5
-
6
- matrix:
7
- include:
8
- - rvm: jruby-9.1.13.0
9
- - rvm: 2.3.4
10
- env: "RAILS_VERSION=5.0.6"
11
- allow_failures:
12
- - rvm: jruby-9.1.13.0
13
- fast_finish: true
4
+ - 2.4.4
14
5
 
15
6
  env:
16
- - "RAILS_VERSION=5.1.4"
7
+ - "RAILS_VERSION=5.2.0"
data/README.md CHANGED
@@ -109,25 +109,7 @@ The EngineCart test application is meant to be disposable and easily rebuildable
109
109
 
110
110
  ### Automatic detection of when to rebuild test application
111
111
 
112
- In some cases, EngineCart can automatically detect and rebuild the test application when key files change. By default, the application will be rebuilt when your `Gemfile` or `Gemfile.lock` changes.
113
-
114
- It can also track changes to your engine's db migrations and generators with a fingerprint mechanism. To use this, add the line below to your rake testing task:
115
-
116
- ```ruby
117
- EngineCart.fingerprint_proc = EngineCart.rails_fingerprint_proc
118
- ```
119
-
120
- For example, in your engine's Rakefile:
121
-
122
- ```ruby
123
- require 'engine_cart/rake_task'
124
-
125
- task :ci do
126
- EngineCart.fingerprint_proc = EngineCart.rails_fingerprint_proc
127
- Rake::Task['engine_cart:generate'].invoke
128
- # run the tests
129
- end
130
- ```
112
+ In some cases, EngineCart can automatically detect and rebuild the test application when key files change. By default, the application will be rebuilt when your `Gemfile`, `Gemfile.lock`, database migrations or generators change.
131
113
 
132
114
  ### Rake tasks for rebuilding test application
133
115
 
@@ -54,6 +54,10 @@ module EngineCart
54
54
  Array(options[:rails_options])
55
55
  end
56
56
 
57
+ def extra_fingerprinted_files
58
+ options[:extra_fingerprinted_files]
59
+ end
60
+
57
61
  def default_destination
58
62
  '.internal_test_app'
59
63
  end
@@ -74,7 +78,8 @@ module EngineCart
74
78
  destination: ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || default_destination,
75
79
  template: ENV['ENGINE_CART_TEMPLATE'],
76
80
  templates_path: ENV['ENGINE_CART_TEMPLATES_PATH'] || './spec/test_app_templates',
77
- rails_options: parse_options(ENV['ENGINE_CART_RAILS_OPTIONS'])
81
+ rails_options: parse_options(ENV['ENGINE_CART_RAILS_OPTIONS']),
82
+ extra_fingerprinted_files: []
78
83
  }
79
84
  end
80
85
 
@@ -77,12 +77,8 @@ namespace :engine_cart do
77
77
  end
78
78
 
79
79
  desc "Create the test rails app"
80
- task :generate, [:fingerprint] => [:setup] do |t, args|
81
- original_fingerprint = args[:fingerprint]
82
- args.with_defaults(:fingerprint => EngineCart.fingerprint) unless original_fingerprint
83
-
84
- f = File.expand_path('.generated_engine_cart', EngineCart.destination)
85
- unless File.exist?(f) && File.read(f) == args[:fingerprint]
80
+ task :generate => [:setup] do
81
+ if EngineCart.fingerprint_expired?
86
82
 
87
83
  # Create a new test rails app
88
84
  Rake::Task['engine_cart:create_test_rails_app'].invoke
@@ -106,7 +102,7 @@ namespace :engine_cart do
106
102
 
107
103
  Bundler.clean_system "bundle install --quiet"
108
104
 
109
- File.open(File.expand_path('.generated_engine_cart', EngineCart.destination), 'w') { |f| f.write(original_fingerprint || EngineCart.fingerprint) }
105
+ EngineCart.write_fingerprint
110
106
 
111
107
  puts "Done generating test app"
112
108
  end
@@ -1,3 +1,3 @@
1
1
  module EngineCart
2
- VERSION = '1.2.0'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/engine_cart.rb CHANGED
@@ -2,6 +2,7 @@ require 'engine_cart/configuration'
2
2
  require "engine_cart/version"
3
3
  require 'engine_cart/gemfile_stanza'
4
4
  require 'bundler'
5
+ require 'json'
5
6
 
6
7
  module EngineCart
7
8
  require "engine_cart/engine" if defined? Rails
@@ -18,26 +19,52 @@ module EngineCart
18
19
  end
19
20
  end
20
21
 
21
- def self.fingerprint
22
- @fingerprint || (@fingerprint_proc || method(:default_fingerprint)).call
22
+ def self.fingerprint_expired?
23
+ !fingerprint_current?
23
24
  end
24
25
 
25
- def self.fingerprint= fingerprint
26
- @fingerprint = fingerprint
26
+ def self.fingerprint_current?
27
+ return false unless File.exist? stored_fingerprint_file
28
+ content = File.read(stored_fingerprint_file)
29
+ data = JSON.parse(content, symbolize_names: true)
30
+ data == fingerprint
31
+ rescue
32
+ false
27
33
  end
28
34
 
29
- def self.fingerprint_proc= fingerprint_proc
30
- @fingerprint_proc = fingerprint_proc
35
+ def self.write_fingerprint
36
+ File.open(stored_fingerprint_file, 'w') do |f|
37
+ f.write(EngineCart.fingerprint.to_json)
38
+ end
31
39
  end
32
40
 
33
- def self.rails_fingerprint_proc extra_files = []
34
- lambda do
35
- EngineCart.default_fingerprint + (Dir.glob("./db/migrate/*") + Dir.glob("./lib/generators/**/**") + Dir.glob("./spec/test_app_templates/**/**") + extra_files).map {|f| File.mtime(f) }.max.to_s
36
- end
41
+ def self.stored_fingerprint_file
42
+ File.expand_path('.generated_engine_cart', EngineCart.destination)
43
+ end
44
+
45
+ def self.fingerprint
46
+ { env: env_fingerprint }.merge(files:
47
+ fingerprinted_files.map do |file|
48
+ { file: file, fingerprint: Digest::MD5.file(file).to_s }
49
+ end
50
+ )
51
+ end
52
+
53
+ def self.fingerprinted_files
54
+ Dir.glob("./*.gemspec").select { |f| File.file? f } +
55
+ [Bundler.default_gemfile.to_s, Bundler.default_lockfile.to_s] +
56
+ Dir.glob("./db/migrate/*").select { |f| File.file? f } +
57
+ Dir.glob("./lib/generators/**/**").select { |f| File.file? f } +
58
+ Dir.glob("./spec/test_app_templates/**/**").select { |f| File.file? f } +
59
+ configuration.extra_fingerprinted_files
60
+ end
61
+
62
+ def self.extra_fingerprinted_files=(extra_fingerprinted_files)
63
+ @extra_fingerprinted_files = extra_fingerprinted_files
37
64
  end
38
65
 
39
- def self.default_fingerprint
40
- EngineCart.env_fingerprint + (Dir.glob("./*.gemspec") + [Bundler.default_gemfile.to_s, Bundler.default_lockfile.to_s]).map {|f| File.mtime(f) }.max.to_s
66
+ def self.extra_fingerprinted_files
67
+ @extra_fingerprinted_files || []
41
68
  end
42
69
 
43
70
  def self.env_fingerprint
@@ -12,45 +12,48 @@ describe "EngineCart powered application" do
12
12
 
13
13
  it "should have a engine_cart:generate rake task available" do
14
14
  EngineCart.within_test_app do
15
- `rake -T | grep "engine_cart:generate"`
15
+ `bundle exec rake -T | grep "engine_cart:generate"`
16
16
  expect($?).to eq 0
17
17
  end
18
18
  end
19
19
 
20
20
  it "should have a engine_cart:regenerate rake task available" do
21
21
  EngineCart.within_test_app do
22
- `rake -T | grep "engine_cart:regenerate"`
22
+ `bundle exec rake -T | grep "engine_cart:regenerate"`
23
23
  expect($?).to eq 0
24
24
  end
25
25
  end
26
26
 
27
27
  it "should create a rails app when the engine_cart:generate task is invoked" do
28
28
  EngineCart.within_test_app do
29
- `rake engine_cart:generate`
29
+ `bundle exec rake engine_cart:generate`
30
30
  expect(File).to exist(File.expand_path('.internal_test_app'))
31
31
  end
32
32
  end
33
33
 
34
34
  it "should not recreate an existing rails app when the engine_cart:generate task is reinvoked" do
35
35
  EngineCart.within_test_app do
36
- `rake engine_cart:generate`
36
+ `bundle exec rake engine_cart:generate`
37
37
  expect(File).to exist(File.expand_path('.internal_test_app'))
38
38
  FileUtils.touch File.join('.internal_test_app', ".this_should_still_exist")
39
- `rake engine_cart:generate`
39
+ `bundle exec rake engine_cart:generate`
40
40
  expect(File).to exist(File.expand_path(File.join('.internal_test_app', ".this_should_still_exist")))
41
41
  end
42
42
  end
43
-
43
+
44
44
  it "should create a rails app when the fingerprint argument is changed" do
45
45
  EngineCart.within_test_app do
46
- `rake engine_cart:generate[this-fingerprint]`
46
+ `bundle exec rake engine_cart:generate`
47
47
  expect(File).to exist(File.expand_path('.internal_test_app'))
48
48
  FileUtils.touch File.join('.internal_test_app', ".this_should_not_exist")
49
- `rake engine_cart:generate[that-fingerprint]`
49
+ File.open('Gemfile', 'a') do |f|
50
+ f.puts "# some new content"
51
+ end
52
+ `bundle exec rake engine_cart:generate`
50
53
  expect(File).to_not exist(File.expand_path(File.join('.internal_test_app', ".this_should_not_exist")))
51
54
  end
52
55
  end
53
-
56
+
54
57
  it "should be able to test the application controller from the internal app" do
55
58
  EngineCart.within_test_app do
56
59
  File.open('spec/some_spec.rb', 'w') do |f|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engine_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-08 00:00:00.000000000 Z
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.6.13
114
+ rubygems_version: 2.6.11
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Helper for testing Rails Engines sanely