fixturama 0.0.2 → 0.0.3

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
- SHA1:
3
- metadata.gz: bba5ba59d906e247aaa4e798664b7ec30802e960
4
- data.tar.gz: b2bfc9b12596884af5dc875a9caede9c343522bb
2
+ SHA256:
3
+ metadata.gz: 9f04b46184ce1d6f3dcb64b6d39b16f0d33b1fa4f5c0900328361a43c984f521
4
+ data.tar.gz: 52356f415a1ed49571c0448e563d7b60ad6d800728de9763fc66cd3f39b37b89
5
5
  SHA512:
6
- metadata.gz: c94ee6bb71480fc429ee9074d48eda1b8cb09914a5184ae676e6cbe07495754fbcaad3dccb6c74812c56866b7c60d6cf148b4c7cd2e0ae3003c0d0d745db7953
7
- data.tar.gz: e1ecad3d926147300425c474757ecd0d1e80d6427c37bc5ef1d29d122680104f8913cea4511dec84e64b779588c1247e0326508de0226e0bb5d521bb7c8f608f
6
+ metadata.gz: eebbc37fc482726aa1cffef2d9d2f26e309a1bc6ca63c11719ecb5d22629eafd93218803a7bb2575a59d508185f0a18722c766e41ab68be1f8f7f9c3d9706ffe
7
+ data.tar.gz: 6c81e6161a0a772a2a947407400ccf51888cb734f191ad7b60187423d550cb5894ef2a110f1bf808fdaf6e4e754f678400a41947e71a6e42c230b09664d56b62
data/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## [0.0.3] - [2018-05-04]
9
+
10
+ ### Added
11
+
12
+ - Helper method to configuge start ids (sclinede, nepalez)
13
+
14
+ ```ruby
15
+ RSpec.configure do |c|
16
+ c.before(:suite) { Fixturama.start_ids_from(1_000_000_000) }
17
+ end
18
+ ```
19
+
8
20
  ## [0.0.2] - [2018-04-27]
9
21
 
10
22
  ### Added
@@ -39,3 +51,4 @@ This is a first public release with features extracted from production app.
39
51
 
40
52
  [0.0.1]: https://github.com/nepalez/fixturama/releases/tag/v0.0.1
41
53
  [0.0.2]: https://github.com/nepalez/fixturama/compare/v0.0.1...v0.0.2
54
+ [0.0.3]: https://github.com/nepalez/fixturama/compare/v0.0.2...v0.0.3
data/README.md CHANGED
@@ -14,6 +14,19 @@ Collection of helpers for dealing with fixtures in [RSpec][rspec]
14
14
  gem "fixturama"
15
15
  ```
16
16
 
17
+ ## Configuration
18
+
19
+ On Rails add offsets to id sequences of database tables.
20
+
21
+ ```ruby
22
+ # spec/rails_helper.rb
23
+ RSpec.configure do |config|
24
+ config.before(:suite) { Fixturama.start_ids_from 1_000_000 }
25
+ end
26
+ ```
27
+
28
+ Now when you hardcode ids in fixtures (under 1_000_000), they won't conflict with authomatically created ones.
29
+
17
30
  ## Usage
18
31
 
19
32
  ```ruby
@@ -58,7 +71,7 @@ end
58
71
 
59
72
  The seed (`seed_fixture`) file should be a YAML/JSON with opinionated parameters, namely:
60
73
 
61
- - `type` for the name of the [FactoryBot][factory_bot] factory
74
+ - `type` for the name of the [FactoryBot][factory-bot] factory
62
75
  - `traits` for the factory traits
63
76
  - `params` for parameters of the factory
64
77
 
@@ -99,7 +112,7 @@ Every action either `return` some value, or `raise` some exception
99
112
  # allow(Notifier)
100
113
  # .to receive_message_chain(:create)
101
114
  # .with(:profileDeleted, 42)
102
- # .and_raise AlreadyRegisteredError
115
+ # .and_raise ActiveRecord::RecordNotFound
103
116
  #
104
117
  ---
105
118
  - class: Notifier
@@ -110,7 +123,7 @@ Every action either `return` some value, or `raise` some exception
110
123
  - <%= profile_id %>
111
124
  actions:
112
125
  - return: true
113
- - raise: AlreadyRegisteredError
126
+ - raise: ActiveRecord::RecordNotFound
114
127
  ```
115
128
 
116
129
  ```graphql
data/fixturama.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "fixturama"
3
- gem.version = "0.0.2"
3
+ gem.version = "0.0.3"
4
4
  gem.author = "Andrew Kozin (nepalez)"
5
5
  gem.email = "andrew.kozin@gmail.com"
6
6
  gem.homepage = "https://github.com/nepalez/fixturama"
@@ -0,0 +1,39 @@
1
+ module Fixturama::Config
2
+ module_function
3
+
4
+ #
5
+ # @param [#to_i] value
6
+ # @return [Boolean]
7
+ #
8
+ def start_ids_from(value)
9
+ require "active_record"
10
+
11
+ db_name = ActiveRecord::Base.connection_config[:database]
12
+ sql = format(SEQUENCE_BOOST_SCRIPT, db_name: db_name, min_id: value.to_i)
13
+ ActiveRecord::Base.connection.execute(sql)
14
+
15
+ true
16
+ rescue LoadError
17
+ false
18
+ end
19
+
20
+ # @private
21
+ SEQUENCE_BOOST_SCRIPT = <<~SQL.freeze
22
+ DO $$
23
+ DECLARE
24
+ seq_name TEXT;
25
+
26
+ BEGIN
27
+ FOR seq_name IN (select table_name from information_schema.tables where
28
+ table_catalog='%<db_name>s' and table_schema='public') LOOP
29
+ BEGIN
30
+ EXECUTE ' \
31
+ SELECT setval('''||seq_name||'_id_seq''::regclass, %<min_id>s); ';
32
+ EXCEPTION
33
+ WHEN undefined_table THEN
34
+ NULL;
35
+ END;
36
+ END LOOP;
37
+ END$$;
38
+ SQL
39
+ end
data/lib/fixturama.rb CHANGED
@@ -6,10 +6,15 @@ require "rspec"
6
6
  require "yaml"
7
7
 
8
8
  module Fixturama
9
+ require_relative "fixturama/config"
9
10
  require_relative "fixturama/utils"
10
11
  require_relative "fixturama/stubs"
11
12
  require_relative "fixturama/seed"
12
13
 
14
+ def self.start_ids_from(value)
15
+ Config.start_ids_from(value)
16
+ end
17
+
13
18
  def stub_fixture(path, **opts)
14
19
  items = load_fixture(path, **opts)
15
20
  raise "The fixture should contain an array" unless items.is_a?(Array)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixturama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin (nepalez)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-27 00:00:00.000000000 Z
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -113,6 +113,7 @@ files:
113
113
  - Rakefile
114
114
  - fixturama.gemspec
115
115
  - lib/fixturama.rb
116
+ - lib/fixturama/config.rb
116
117
  - lib/fixturama/rspec.rb
117
118
  - lib/fixturama/seed.rb
118
119
  - lib/fixturama/stubs.rb
@@ -150,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
152
153
  requirements: []
153
- rubyforge_project:
154
- rubygems_version: 2.6.14
154
+ rubygems_version: 3.0.3
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: A set of helpers to prettify specs with fixtures