derail_specs 0.2.1 → 0.3.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
  SHA256:
3
- metadata.gz: 19ad2edfa41b68ea23a7e62cffc7f9265a7f303ca4e3440f3c37f16ec3d57f6a
4
- data.tar.gz: a36a37269421c0ac564046c6e05c6897997dea27bbd1d5d2c49198a92f728fba
3
+ metadata.gz: b3cb7b4de2c0df3488fd8d13cea48a9a432eb4a93c9154348373d19ffb2f5faf
4
+ data.tar.gz: 6640217cd89418908ad6cf8bf23d4acaf85aa75baf8f2495bdf661ff157d7161
5
5
  SHA512:
6
- metadata.gz: 6b2120eec627732dce1e88bb601d37a40b531cd72c373081f7d911555ff092549dfe4630b70e7f67c49031d1f7399d87412b3905e3684175004ddbf97079e131
7
- data.tar.gz: '02726830b503acba20c9ab92c0e1b6207451ba1af925914cd56c915270b11d5280b06f4bbf65ed30f9a38576b62c1442b5728b4963ff4c6b0fd056365037591d'
6
+ metadata.gz: 3587e23efa379f03cdab789814e0ed81c026688d1013dc7e216625e69a320445631b3f5d6dec3a51ad58ac2f5a0d4fdc07e121ba93326ed2d4a9e32958752958
7
+ data.tar.gz: cfd6c514732a6b153115038a04aa979232d0d0306cbfb93d1915410b13b405d77a31382ec7b27f9989529c81cebec9edb1497f18d299cee26c43d8c166678601
data/.rubocop.yml CHANGED
@@ -1,10 +1,14 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ NewCops: enable
5
+ Exclude:
6
+ - 'example/db/schema.rb'
7
+ - 'example/bin/*'
8
+
3
9
  Style/StringLiterals:
4
10
  Enabled: false
5
11
 
6
- AllCops:
7
- NewCops: enable
8
12
 
9
13
  Style/Documentation:
10
14
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-09-15 06:26:41 UTC using RuboCop version 1.21.0.
3
+ # on 2021-09-16 08:00:52 UTC using RuboCop version 1.21.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -18,30 +18,14 @@ Gemspec/RequiredRubyVersion:
18
18
  Metrics/AbcSize:
19
19
  Max: 34
20
20
 
21
- # Offense count: 1
22
- # Configuration parameters: IgnoredMethods.
23
- Metrics/CyclomaticComplexity:
24
- Max: 9
25
-
26
- # Offense count: 6
21
+ # Offense count: 4
27
22
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
28
23
  Metrics/MethodLength:
29
24
  Max: 20
30
25
 
31
- # Offense count: 1
32
- # Configuration parameters: IgnoredMethods.
33
- Metrics/PerceivedComplexity:
34
- Max: 9
35
-
36
- # Offense count: 1
37
- # Cop supports --auto-correct.
38
- Style/IfUnlessModifier:
39
- Exclude:
40
- - 'example/bin/bundle'
41
-
42
- # Offense count: 4
26
+ # Offense count: 3
43
27
  # Cop supports --auto-correct.
44
28
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
45
29
  # URISchemes: http, https
46
30
  Layout/LineLength:
47
- Max: 198
31
+ Max: 127
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+
4
+ ## [0.3.0] - 2021-09-16
5
+
6
+ - Add `/factory-bot/create` route to map to FactoryBot.create
7
+ - Run `rake derail_specs:run` in Rails test environment
8
+
3
9
  ## [0.2.1] - 2021-09-15
4
10
 
5
- - Fix Rails 5.2 missing method ActiveRecord::TestFixtures.setup_shared_connection_pool
11
+ - Fix Rails 5.2 missing method `ActiveRecord::TestFixtures.setup_shared_connection_pool`
6
12
 
7
13
  ## [0.2.0] - 2021-09-15
8
14
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- derail_specs (0.2.1)
4
+ derail_specs (0.3.0)
5
5
  puma (>= 3.8.0)
6
6
  railties (>= 5.2.0)
7
7
 
data/README.md CHANGED
@@ -63,6 +63,29 @@ beforeEach(async () => {
63
63
  });
64
64
  ```
65
65
 
66
+ ### FactoryBot.create
67
+
68
+ Post with a JSON array to `/factory-bot/create` with the following structure:
69
+
70
+ ```JSON
71
+ ["test", { "name": "Test Name", "created_at": "2011-11-11 11:11:11" }]
72
+ ````
73
+
74
+ which will run:
75
+
76
+ ```ruby
77
+ FactoryBot.create(:test, name: "Test Name", created_at: "2011-11-11 11:11:11")
78
+ ```
79
+
80
+ Example curl:
81
+
82
+ ```bash
83
+ curl -X POST \
84
+ -d '["test", { "name": "Test Name from Curl", "created_at": "2011-11-11 11:11:11" }]' \
85
+ -H 'Content-Type: application/json' \
86
+ 127.0.0.1:3001/factory-bot/create
87
+ ```
88
+
66
89
  ## Development
67
90
 
68
91
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/example/Gemfile CHANGED
@@ -11,5 +11,6 @@ gem 'sqlite3', '~> 1.4'
11
11
 
12
12
  group :development, :test do
13
13
  gem "derail_specs", path: '..'
14
+ gem 'factory_bot_rails'
14
15
  gem 'pry-rails'
15
16
  end
data/example/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- derail_specs (0.2.1)
4
+ derail_specs (0.3.0)
5
5
  puma (>= 3.8.0)
6
6
  railties (>= 5.2.0)
7
7
 
@@ -72,6 +72,11 @@ GEM
72
72
  concurrent-ruby (1.1.9)
73
73
  crass (1.0.6)
74
74
  erubi (1.10.0)
75
+ factory_bot (6.2.0)
76
+ activesupport (>= 5.0.0)
77
+ factory_bot_rails (6.2.0)
78
+ factory_bot (~> 6.2.0)
79
+ railties (>= 5.0.0)
75
80
  globalid (0.5.2)
76
81
  activesupport (>= 5.0)
77
82
  i18n (1.8.10)
@@ -147,6 +152,7 @@ PLATFORMS
147
152
 
148
153
  DEPENDENCIES
149
154
  derail_specs!
155
+ factory_bot_rails
150
156
  pry-rails
151
157
  puma (~> 5.0)
152
158
  rails (~> 6.1.4, >= 6.1.4.1)
@@ -0,0 +1,2 @@
1
+ class Test < ApplicationRecord
2
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTests < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :tests do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2021_09_16_070010) do
14
+
15
+ create_table "tests", force: :cascade do |t|
16
+ t.string "name"
17
+ t.datetime "created_at", precision: 6, null: false
18
+ t.datetime "updated_at", precision: 6, null: false
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :test do
3
+ sequence(:name) { |n| "Test #{n}" }
4
+ end
5
+ end
data/example/tests.sh CHANGED
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- curl 127.0.0.1:3001
3
+ curl -s 127.0.0.1:3001 > /dev/null
4
4
  curl 127.0.0.1:3001/reset-transaction
5
+ curl -X POST \
6
+ -d '["test", { "name": "Test Name from Curl", "created_at": "2011-11-11 11:11:11" }]' \
7
+ -H 'Content-Type: application/json' \
8
+ 127.0.0.1:3001/factory-bot/create
@@ -0,0 +1,14 @@
1
+ begin
2
+ gem 'factory_bot_rails'
3
+ require 'factory_bot_rails'
4
+
5
+ module DerailSpecs
6
+ class FactoryBot
7
+ def self.create(factory, options = nil)
8
+ ::FactoryBot.create(factory, options)
9
+ end
10
+ end
11
+ end
12
+ rescue Gem::LoadError
13
+ require_relative 'factory_bot_stub'
14
+ end
@@ -0,0 +1,8 @@
1
+ module DerailSpecs
2
+ class FactoryBot
3
+ def self.create(*_)
4
+ puts "factory_bot_rails is not installed in group :test"
5
+ puts "Please add factory_bot_rails to your Gemfile to use this feature"
6
+ end
7
+ end
8
+ end
@@ -7,6 +7,14 @@ module DerailSpecs
7
7
  [202, { "Content-Type" => "text/plain" }, ["Accepted"]]
8
8
  }
9
9
  end
10
+ map "/factory-bot/create" do
11
+ run lambda { |env|
12
+ body = Rack::Request.new(env).body.gets
13
+ object = FactoryBot.create(*JSON.parse(body))
14
+
15
+ [202, { "Content-Type" => "application/json" }, [object.to_json]]
16
+ }
17
+ end
10
18
  map "/" do
11
19
  run Rails.application
12
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DerailSpecs
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/derail_specs.rb CHANGED
@@ -22,3 +22,4 @@ end
22
22
  require 'derail_specs/boot'
23
23
  require 'derail_specs/transaction'
24
24
  require 'derail_specs/railtie'
25
+ require 'derail_specs/factory_bot'
@@ -1,5 +1,6 @@
1
1
  namespace :derail_specs do
2
2
  task run: :environment do
3
+ Rails.env = "test"
3
4
  DerailSpecs::Boot.new.run
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: derail_specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Piechowski
@@ -67,6 +67,7 @@ files:
67
67
  - example/Rakefile
68
68
  - example/app/controllers/application_controller.rb
69
69
  - example/app/models/application_record.rb
70
+ - example/app/models/test.rb
70
71
  - example/app/views/layouts/application.html.erb
71
72
  - example/bin/bundle
72
73
  - example/bin/rails
@@ -94,6 +95,9 @@ files:
94
95
  - example/config/locales/en.yml
95
96
  - example/config/puma.rb
96
97
  - example/config/routes.rb
98
+ - example/db/migrate/20210916070010_create_tests.rb
99
+ - example/db/schema.rb
100
+ - example/factories.rb
97
101
  - example/public/404.html
98
102
  - example/public/422.html
99
103
  - example/public/500.html
@@ -104,6 +108,8 @@ files:
104
108
  - example/tests.sh
105
109
  - lib/derail_specs.rb
106
110
  - lib/derail_specs/boot.rb
111
+ - lib/derail_specs/factory_bot.rb
112
+ - lib/derail_specs/factory_bot_stub.rb
107
113
  - lib/derail_specs/railtie.rb
108
114
  - lib/derail_specs/server.rb
109
115
  - lib/derail_specs/server/app.rb