nilify_blanks 1.4.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
  SHA256:
3
- metadata.gz: 117e4a499e7f6e4ca67ca960c463175898f34f06c017549b0d4838ab5d6c2be9
4
- data.tar.gz: 3d0dfb25b9c1868a3f14ebb2a04e3ba53d0242fe33c3621fc5233d51e264611b
3
+ metadata.gz: 3182bde0ba670c955ffe32072da1d25ab4ac555ee6407ba0cb382176f180c3e5
4
+ data.tar.gz: 651f7c83d16b982e06fd10e942794c3e2692e3aa308ff3e601d785e3402b2b31
5
5
  SHA512:
6
- metadata.gz: f0a0e775623407760b8db4d7d1fbedaad402621e0b57cef64ed3f5a6479948170128493e9c47e9217d1a8d72a1c96eb0a37b4cdbe81a4c3b10b3ce0c09ff8add
7
- data.tar.gz: 51f6507d4af29105bc808a2e7a91275538bb26334acabdcaf7bd0682034e4e754d1211cfc51257d8eaca9e2bbbfcaf7cb4617ec58904974f5e61b17f05246884
6
+ metadata.gz: d5402f67309e91fc294883f5c652d640de783eb034f2a37fcbb5f2cc85f1b820c0123ed0dac3c95ffcdb940129391497c36dfcb5e1ffa6ba69ad7e199a3e6514
7
+ data.tar.gz: 79d4faa8cfe40b20c01b6d41f35c1241bd3c9bccd57da6273933c31cb014dc527446a013d2e3d96e076e5284c83f0dc40623cf4fe005656fb9278dc992e0c6f5
@@ -1,50 +1,66 @@
1
- == [2020-04-18] 1.4.0
1
+ # Changelog
2
+
3
+ ## 2.0.0 (unreleased)
4
+
5
+ * Require Rails 6.1+ and Ruby 2.7+ (tested on Rails 6.1 through 8.1)
6
+ * RSpec matchers no longer define helper methods on every object, and drop RSpec 1/2 compatibility
7
+ * Remove legacy Rails 2 plugin files (`init.rb`, `rails/init.rb`)
8
+ * Replace Travis CI and Appraisal with GitHub Actions
9
+ * Only package library files in the gem, and add RubyGems metadata
10
+ * Convert README and CHANGELOG to Markdown, and document when Rails' built-in `normalizes` is a better fit
11
+
12
+ ## 1.4.0 (2020-04-18)
2
13
 
3
14
  * Internally restructure NilifyBlanks, use modern tooling like ActiveSupport::Concern
4
15
  * Drop support for Rails 3, expand Appraisals to include Rails 6
5
16
  * Change default before callback to :validation (from :save)
6
17
 
7
- == [2017-12-23] 1.3.0
18
+ ## 1.3.0 (2017-12-23)
8
19
 
9
20
  * Use all columns (not just content_columns)
10
21
  * Allow nullables_only: false option for including columns that don't allow NULLs
11
22
  * Support citext columns
12
23
 
13
- == [2015-04-12] 1.2.1
24
+ ## 1.2.1 (2015-04-12)
14
25
 
15
26
  * Fix inconsistency in nilify_blanks RSpec matcher: should filter by type
16
27
 
17
- == [2014-07-04] 1.2.0
28
+ ## 1.2.0 (2014-07-04)
18
29
 
19
30
  * Drop support for ruby 1.8.7 and 1.9.2 - too many issues with backwards-compatibility
20
31
  * Explicit support for Rails 4.1 and 4.2
21
32
  * Up-to-date Appraisals and dependencies
22
33
 
23
- == [2014-07-04] 1.1.0
34
+ ## 1.1.0 (2014-07-04)
24
35
 
25
36
  * Implement new mechanism to allow for global usage at ActiveRecord::Base level (or namespaced base model)
26
37
  * Make define_nilify_blanks thread safe
27
38
  * New rspec matchers with: require "nilify_blanks/matchers"
28
39
  * Only consider string and text columns, and allow types option to configure
29
40
 
30
- == [2013-11-09] 1.0.4
41
+ ## 1.0.4 (2013-11-09)
31
42
 
32
43
  * Fix issues with wrapping define_attribute_methods in jruby on Rails 4 (Thanks, tank157)
33
44
 
34
- == [2013-11-09] 1.0.3
45
+ ## 1.0.3 (2013-11-09)
35
46
 
36
47
  * Add rbx and JRuby compatibility (Thanks, petergoldstein)
37
48
 
38
- == [2013-08-25] 1.0.2
49
+ ## 1.0.2 (2013-08-25)
39
50
 
40
51
  * Hook on AR::Base.define_attribute_methods in order to prevent eager load of models [byroot]
41
52
 
42
- == [2010-10-15] 1.0.0 Major Updates
53
+ ## 1.0.0 (2010-10-15) - Major Updates
43
54
 
44
55
  * Finally updated to be a Gem
45
56
  * Internal refactoring
46
57
  * Converted tests to RSpec
47
58
  * Added support for Rails 3.0
48
59
 
49
- == 0.1.2 Fixed issue with table not existing.
50
- == 0.1.0 Initial Version
60
+ ## 0.1.2
61
+
62
+ * Fixed issue with table not existing.
63
+
64
+ ## 0.1.0
65
+
66
+ * Initial Version
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # Nilify Blanks
2
+
3
+ [![CI](https://github.com/rubiety/nilify_blanks/actions/workflows/ci.yml/badge.svg)](https://github.com/rubiety/nilify_blanks/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/nilify_blanks.svg)](https://rubygems.org/gems/nilify_blanks)
5
+
6
+ In Rails when saving a model from a form and values are not provided by the user, an empty string is recorded to the database instead of a NULL as many would prefer (mixing blanks and NULLs can become confusing). This gem converts blank attributes to nil before a model is saved, either for every applicable column or for a list you choose.
7
+
8
+ By default, columns set as NOT NULL will not be nilified, since that value cannot be persisted, and it might be better to catch that with a validation. If you want to nilify those columns anyway, you can use `only:` (see below) to explicitly mention them.
9
+
10
+ Only attributes responding to `blank?` with a value of true will be converted to nil. Therefore, this does not work with integer fields with the value of 0, for example.
11
+
12
+ ## Do you need this gem?
13
+
14
+ Rails 7.1 added [`normalizes`](https://api.rubyonrails.org/classes/ActiveRecord/Normalization/ClassMethods.html), which handles the per-attribute case well:
15
+
16
+ ```ruby
17
+ class Post < ApplicationRecord
18
+ normalizes :title, :author, with: ->(value) { value.presence }
19
+ end
20
+ ```
21
+
22
+ `normalizes` applies on assignment (not just before save) and to finder queries like `where(title: "")`, so prefer it when you only care about a few attributes.
23
+
24
+ Use nilify_blanks when you want this behavior for **every** nullable string/text column without listing them, including columns added later, or across all models at once via `ApplicationRecord` or `ActiveRecord::Base`.
25
+
26
+ ## Requirements
27
+
28
+ * Rails (Active Record) 6.1 or newer
29
+ * Ruby 2.7 or newer
30
+
31
+ Version 1.4.0 remains available for older Rails versions.
32
+
33
+ ## Install
34
+
35
+ Add the gem to your Gemfile:
36
+
37
+ ```ruby
38
+ gem "nilify_blanks"
39
+ ```
40
+
41
+ ## Basic Usage
42
+
43
+ ```ruby
44
+ # Checks and converts all nullable string, text and citext columns
45
+ class Post < ApplicationRecord
46
+ nilify_blanks
47
+ end
48
+
49
+ # Checks and converts only text columns
50
+ class Post < ApplicationRecord
51
+ nilify_blanks types: [:text]
52
+ end
53
+
54
+ # Checks and converts only the title and author fields
55
+ class Post < ApplicationRecord
56
+ nilify_blanks only: [:author, :title]
57
+ end
58
+
59
+ # Checks and converts all fields except for title and author
60
+ class Post < ApplicationRecord
61
+ nilify_blanks except: [:author, :title]
62
+ end
63
+
64
+ # Checks and converts any fields, regardless of their null constraint
65
+ class Post < ApplicationRecord
66
+ nilify_blanks nullables_only: false
67
+ end
68
+ ```
69
+
70
+ ## Global Usage
71
+
72
+ You can apply nilify_blanks to every model in your application:
73
+
74
+ ```ruby
75
+ class ApplicationRecord < ActiveRecord::Base
76
+ self.abstract_class = true
77
+ nilify_blanks
78
+ end
79
+ ```
80
+
81
+ Or to all models inheriting from `ActiveRecord::Base`:
82
+
83
+ ```ruby
84
+ ActiveRecord::Base.nilify_blanks
85
+ ```
86
+
87
+ Or perhaps just a model namespace base class:
88
+
89
+ ```ruby
90
+ Inventory::Base.nilify_blanks
91
+ ```
92
+
93
+ Individual models can still call `nilify_blanks` with their own options to override the inherited configuration.
94
+
95
+ ## Specifying a Callback
96
+
97
+ Checking uses an Active Record `before_validation` callback by default, but you can specify a different callback with the `:before` option. Any `before_*` callback will work; just remove the `before_` prefix from the name.
98
+
99
+ ```ruby
100
+ class Post < ApplicationRecord
101
+ nilify_blanks before: :save
102
+ end
103
+
104
+ class Post < ApplicationRecord
105
+ nilify_blanks before: :create
106
+ end
107
+ ```
108
+
109
+ ## RSpec Matchers
110
+
111
+ First, include the matchers:
112
+
113
+ ```ruby
114
+ require "nilify_blanks/matchers"
115
+ ```
116
+
117
+ To ensure for a given column:
118
+
119
+ ```ruby
120
+ RSpec.describe City do
121
+ it { is_expected.to nilify_blanks_for(:name) }
122
+ end
123
+ ```
124
+
125
+ To ensure for all applicable content columns:
126
+
127
+ ```ruby
128
+ RSpec.describe City do
129
+ it { is_expected.to nilify_blanks }
130
+ end
131
+ ```
132
+
133
+ You can optionally match on options also:
134
+
135
+ ```ruby
136
+ RSpec.describe City do
137
+ it { is_expected.to nilify_blanks_for(:name, before: :create) }
138
+ it { is_expected.to nilify_blanks(before: :create) }
139
+ end
140
+ ```
141
+
142
+ ## Running Tests
143
+
144
+ ```
145
+ bundle install
146
+ bundle exec rake
147
+ ```
148
+
149
+ CI runs the suite against each supported Rails version using the gemfiles in `gemfiles/`. To run against one locally:
150
+
151
+ ```
152
+ BUNDLE_GEMFILE=gemfiles/rails_7.2.gemfile bundle install
153
+ BUNDLE_GEMFILE=gemfiles/rails_7.2.gemfile bundle exec rake
154
+ ```
@@ -1,57 +1,39 @@
1
- rspec_module = defined?(RSpec::Core) ? 'RSpec' : 'Spec' # for RSpec 1 compatability
1
+ require "rspec/expectations"
2
2
 
3
- def failure_message_method
4
- rspec_major_version >= 3 ? :failure_message : :failure_message_for_should
5
- rescue
6
- :failure_message_for_should
7
- end
8
-
9
- def negated_failure_message_method
10
- rspec_major_version >= 3 ? :failure_message_when_negated : :failure_message_for_should_not
11
- rescue
12
- :failure_message_for_should_not
13
- end
14
-
15
- def rspec_major_version
16
- RSpec::Core::Version::STRING.split('.').first.to_i
17
- end
18
-
19
- Kernel.const_get(rspec_module)::Matchers.define :nilify_blanks_for do |column_name, options = {}|
3
+ RSpec::Matchers.define :nilify_blanks_for do |column_name, options = {}|
20
4
  match do |model_instance|
21
5
  model_class = model_instance.class
22
6
  model_class.define_attribute_methods
23
- model_class.included_modules.include?(NilifyBlanks) &&
24
- model_class.respond_to?(:nilify_blanks_columns) &&
7
+ model_class.include?(NilifyBlanks) &&
25
8
  model_class.nilify_blanks_columns.include?(column_name.to_s) &&
26
- (options || {}).all? {|k, v| model_class.nilify_blanks_options[k] == v }
9
+ options.all? {|k, v| (model_class.nilify_blanks_options || {})[k] == v }
27
10
  end
28
11
 
29
- send(failure_message_method) do |_|
30
- "expected to nilify blanks for #{column_name} #{options.inspect unless options.empty?}"
12
+ failure_message do
13
+ "expected to nilify blanks for #{column_name}#{" #{options.inspect}" unless options.empty?}"
31
14
  end
32
15
 
33
- send(negated_failure_message_method) do |_|
34
- "expected to not nilify blanks for #{column_name} #{options.inspect unless options.empty?}"
16
+ failure_message_when_negated do
17
+ "expected to not nilify blanks for #{column_name}#{" #{options.inspect}" unless options.empty?}"
35
18
  end
36
19
  end
37
20
 
38
- Kernel.const_get(rspec_module)::Matchers.define :nilify_blanks do |options = {}|
21
+ RSpec::Matchers.define :nilify_blanks do |options = {}|
39
22
  match do |model_instance|
40
23
  expected_types = options[:types] ? Array.wrap(options[:types]).map(&:to_sym) : NilifyBlanks::ClassMethods::DEFAULT_TYPES
41
24
 
42
25
  model_class = model_instance.class
43
26
  model_class.define_attribute_methods
44
- model_class.included_modules.include?(NilifyBlanks) &&
45
- model_class.respond_to?(:nilify_blanks_columns) &&
27
+ model_class.include?(NilifyBlanks) &&
46
28
  model_class.nilify_blanks_columns == model_class.columns.select(&:null).select {|c| expected_types.include?(c.type) }.map(&:name).map(&:to_s) &&
47
- (options || {}).all? {|k, v| model_class.nilify_blanks_options[k] == v }
29
+ options.all? {|k, v| (model_class.nilify_blanks_options || {})[k] == v }
48
30
  end
49
31
 
50
- send(failure_message_method) do |_|
51
- "expected to nilify blanks #{options.inspect unless options.empty?}"
32
+ failure_message do
33
+ "expected to nilify blanks#{" #{options.inspect}" unless options.empty?}"
52
34
  end
53
35
 
54
- send(negated_failure_message_method) do |_|
55
- "expected to not nilify blanks #{options.inspect unless options.empty?}"
36
+ failure_message_when_negated do
37
+ "expected to not nilify blanks#{" #{options.inspect}" unless options.empty?}"
56
38
  end
57
39
  end
@@ -1,3 +1,3 @@
1
1
  module NilifyBlanks
2
- VERSION = "1.4.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/nilify_blanks.rb CHANGED
@@ -67,7 +67,6 @@ module NilifyBlanks
67
67
  (nilify_blanks_columns || []).each do |column|
68
68
  value = read_attribute(column)
69
69
  next unless value.is_a?(String)
70
- next unless value.respond_to?(:blank?)
71
70
 
72
71
  write_attribute(column, nil) if value.blank?
73
72
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nilify_blanks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hughes
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2020-04-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -16,115 +15,51 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 4.0.0
18
+ version: '6.1'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 4.0.0
25
+ version: '6.1'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: activerecord
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: 4.0.0
32
+ version: '6.1'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: 4.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 13.0.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 13.0.1
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 3.8.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 3.8.0
69
- - !ruby/object:Gem::Dependency
70
- name: appraisal
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 1.0.2
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 1.0.2
83
- - !ruby/object:Gem::Dependency
84
- name: sqlite3
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 1.3.6
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 1.3.6
39
+ version: '6.1'
97
40
  description: Often times you'll end up with empty strings where you really want nil
98
41
  at the database level. This plugin automatically converts blanks to nil and is
99
42
  configurable.
100
- email: ben@railsgarden.com
43
+ email: me@benhughes.name
101
44
  executables: []
102
45
  extensions: []
103
46
  extra_rdoc_files: []
104
47
  files:
105
- - Appraisals
106
- - CHANGELOG.rdoc
107
- - Gemfile
108
- - Gemfile.lock
48
+ - CHANGELOG.md
109
49
  - LICENSE
110
- - README.rdoc
111
- - Rakefile
112
- - init.rb
50
+ - README.md
113
51
  - lib/nilify_blanks.rb
114
52
  - lib/nilify_blanks/matchers.rb
115
53
  - lib/nilify_blanks/railtie.rb
116
54
  - lib/nilify_blanks/version.rb
117
- - spec/db/database.yml
118
- - spec/db/schema.rb
119
- - spec/db/test.sqlite3
120
- - spec/examples.txt
121
- - spec/nilify_blanks_spec.rb
122
- - spec/spec_helper.rb
123
- homepage: http://github.com/rubiety/nilify_blanks
55
+ homepage: https://github.com/rubiety/nilify_blanks
124
56
  licenses:
125
57
  - MIT
126
- metadata: {}
127
- post_install_message:
58
+ metadata:
59
+ source_code_uri: https://github.com/rubiety/nilify_blanks
60
+ changelog_uri: https://github.com/rubiety/nilify_blanks/blob/master/CHANGELOG.md
61
+ bug_tracker_uri: https://github.com/rubiety/nilify_blanks/issues
62
+ rubygems_mfa_required: 'true'
128
63
  rdoc_options: []
129
64
  require_paths:
130
65
  - lib
@@ -132,16 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
67
  requirements:
133
68
  - - ">="
134
69
  - !ruby/object:Gem::Version
135
- version: '0'
70
+ version: '2.7'
136
71
  required_rubygems_version: !ruby/object:Gem::Requirement
137
72
  requirements:
138
73
  - - ">="
139
74
  - !ruby/object:Gem::Version
140
- version: 1.3.4
75
+ version: '0'
141
76
  requirements: []
142
- rubyforge_project: nilify_blanks
143
- rubygems_version: 2.7.6
144
- signing_key:
77
+ rubygems_version: 3.6.7
145
78
  specification_version: 4
146
79
  summary: Auto-convert blank fields to nil.
147
80
  test_files: []
data/Appraisals DELETED
@@ -1,19 +0,0 @@
1
- appraise "4.0" do
2
- gem "rails", "~> 4.0.12"
3
- end
4
-
5
- appraise "4.1" do
6
- gem "rails", "~> 4.1.8"
7
- end
8
-
9
- appraise "4.2" do
10
- gem "rails", "~> 4.2.0"
11
- end
12
-
13
- appraise "5.2" do
14
- gem "rails", "~> 5.2.0"
15
- end
16
-
17
- appraise "6.0" do
18
- gem "rails", "~> 6.0.2"
19
- end
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rubysl', '~> 2.0', :platforms => [:rbx]
4
-
5
- gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
6
- gem 'sqlite3', '~> 1.3.6', :platforms => [:ruby]
7
-
8
- gemspec
data/Gemfile.lock DELETED
@@ -1,268 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- nilify_blanks (1.3.0)
5
- activerecord (>= 4.0.0)
6
- activesupport (>= 4.0.0)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- activemodel (6.0.2.1)
12
- activesupport (= 6.0.2.1)
13
- activerecord (6.0.2.1)
14
- activemodel (= 6.0.2.1)
15
- activesupport (= 6.0.2.1)
16
- activesupport (6.0.2.1)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- zeitwerk (~> 2.2)
22
- appraisal (2.2.0)
23
- bundler
24
- rake
25
- thor (>= 0.14.0)
26
- concurrent-ruby (1.1.5)
27
- diff-lcs (1.3)
28
- ffi2-generators (0.1.1)
29
- i18n (1.8.2)
30
- concurrent-ruby (~> 1.0)
31
- minitest (5.14.0)
32
- rake (13.0.1)
33
- rspec (3.9.0)
34
- rspec-core (~> 3.9.0)
35
- rspec-expectations (~> 3.9.0)
36
- rspec-mocks (~> 3.9.0)
37
- rspec-core (3.9.1)
38
- rspec-support (~> 3.9.1)
39
- rspec-expectations (3.9.1)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.9.0)
42
- rspec-mocks (3.9.1)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.9.0)
45
- rspec-support (3.9.2)
46
- rubysl (2.2.0)
47
- rubysl-abbrev (~> 2.0)
48
- rubysl-base64 (~> 2.0)
49
- rubysl-benchmark (~> 2.0)
50
- rubysl-bigdecimal (~> 2.0)
51
- rubysl-cgi (~> 2.0)
52
- rubysl-cgi-session (~> 2.0)
53
- rubysl-cmath (~> 2.0)
54
- rubysl-complex (~> 2.0)
55
- rubysl-continuation (~> 2.0)
56
- rubysl-coverage (~> 2.0)
57
- rubysl-csv (~> 2.0)
58
- rubysl-curses (~> 2.0)
59
- rubysl-date (~> 2.0)
60
- rubysl-delegate (~> 2.0)
61
- rubysl-digest (~> 2.0)
62
- rubysl-drb (~> 2.0)
63
- rubysl-e2mmap (~> 2.0)
64
- rubysl-english (~> 2.0)
65
- rubysl-enumerator (~> 2.0)
66
- rubysl-erb (~> 2.0)
67
- rubysl-etc (~> 2.0)
68
- rubysl-expect (~> 2.0)
69
- rubysl-fcntl (~> 2.0)
70
- rubysl-fiber (~> 2.0)
71
- rubysl-fileutils (~> 2.0)
72
- rubysl-find (~> 2.0)
73
- rubysl-forwardable (~> 2.0)
74
- rubysl-getoptlong (~> 2.0)
75
- rubysl-gserver (~> 2.0)
76
- rubysl-io-console (~> 2.0)
77
- rubysl-io-nonblock (~> 2.0)
78
- rubysl-io-wait (~> 2.0)
79
- rubysl-ipaddr (~> 2.0)
80
- rubysl-irb (~> 2.1)
81
- rubysl-logger (~> 2.0)
82
- rubysl-mathn (~> 2.0)
83
- rubysl-matrix (~> 2.0)
84
- rubysl-mkmf (~> 2.0)
85
- rubysl-monitor (~> 2.0)
86
- rubysl-mutex_m (~> 2.0)
87
- rubysl-net-ftp (~> 2.0)
88
- rubysl-net-http (~> 2.0)
89
- rubysl-net-imap (~> 2.0)
90
- rubysl-net-pop (~> 2.0)
91
- rubysl-net-protocol (~> 2.0)
92
- rubysl-net-smtp (~> 2.0)
93
- rubysl-net-telnet (~> 2.0)
94
- rubysl-nkf (~> 2.0)
95
- rubysl-observer (~> 2.0)
96
- rubysl-open-uri (~> 2.0)
97
- rubysl-open3 (~> 2.0)
98
- rubysl-openssl (~> 2.0)
99
- rubysl-optparse (~> 2.0)
100
- rubysl-ostruct (~> 2.0)
101
- rubysl-pathname (~> 2.0)
102
- rubysl-prettyprint (~> 2.0)
103
- rubysl-prime (~> 2.0)
104
- rubysl-profile (~> 2.0)
105
- rubysl-profiler (~> 2.0)
106
- rubysl-pstore (~> 2.0)
107
- rubysl-pty (~> 2.0)
108
- rubysl-rational (~> 2.0)
109
- rubysl-resolv (~> 2.0)
110
- rubysl-rexml (~> 2.0)
111
- rubysl-rinda (~> 2.0)
112
- rubysl-rss (~> 2.0)
113
- rubysl-scanf (~> 2.0)
114
- rubysl-securerandom (~> 2.0)
115
- rubysl-set (~> 2.0)
116
- rubysl-shellwords (~> 2.0)
117
- rubysl-singleton (~> 2.0)
118
- rubysl-socket (~> 2.0)
119
- rubysl-stringio (~> 2.0)
120
- rubysl-strscan (~> 2.0)
121
- rubysl-sync (~> 2.0)
122
- rubysl-syslog (~> 2.0)
123
- rubysl-tempfile (~> 2.0)
124
- rubysl-thread (~> 2.0)
125
- rubysl-thwait (~> 2.0)
126
- rubysl-time (~> 2.0)
127
- rubysl-timeout (~> 2.0)
128
- rubysl-tmpdir (~> 2.0)
129
- rubysl-tsort (~> 2.0)
130
- rubysl-un (~> 2.0)
131
- rubysl-unicode_normalize (~> 2.0)
132
- rubysl-uri (~> 2.0)
133
- rubysl-weakref (~> 2.0)
134
- rubysl-webrick (~> 2.0)
135
- rubysl-xmlrpc (~> 2.0)
136
- rubysl-yaml (~> 2.0)
137
- rubysl-zlib (~> 2.0)
138
- rubysl-abbrev (2.0.4)
139
- rubysl-base64 (2.0.0)
140
- rubysl-benchmark (2.0.1)
141
- rubysl-bigdecimal (2.0.2)
142
- rubysl-cgi (2.0.1)
143
- rubysl-cgi-session (2.1.0)
144
- rubysl-cmath (2.0.0)
145
- rubysl-complex (2.0.0)
146
- rubysl-continuation (2.0.0)
147
- rubysl-coverage (2.1)
148
- rubysl-csv (2.0.2)
149
- rubysl-english (~> 2.0)
150
- rubysl-curses (2.0.1)
151
- rubysl-date (2.0.9)
152
- rubysl-delegate (2.0.1)
153
- rubysl-digest (2.0.8)
154
- rubysl-drb (2.0.1)
155
- rubysl-e2mmap (2.0.0)
156
- rubysl-english (2.0.0)
157
- rubysl-enumerator (2.0.0)
158
- rubysl-erb (2.0.2)
159
- rubysl-etc (2.0.3)
160
- ffi2-generators (~> 0.1)
161
- rubysl-expect (2.0.0)
162
- rubysl-fcntl (2.0.4)
163
- ffi2-generators (~> 0.1)
164
- rubysl-fiber (2.0.0)
165
- rubysl-fileutils (2.0.3)
166
- rubysl-find (2.0.1)
167
- rubysl-forwardable (2.0.1)
168
- rubysl-getoptlong (2.0.0)
169
- rubysl-gserver (2.0.0)
170
- rubysl-socket (~> 2.0)
171
- rubysl-thread (~> 2.0)
172
- rubysl-io-console (2.0.0)
173
- rubysl-io-nonblock (2.0.0)
174
- rubysl-io-wait (2.0.0)
175
- rubysl-ipaddr (2.0.0)
176
- rubysl-irb (2.1.1)
177
- rubysl-e2mmap (~> 2.0)
178
- rubysl-mathn (~> 2.0)
179
- rubysl-thread (~> 2.0)
180
- rubysl-logger (2.1.0)
181
- rubysl-mathn (2.0.0)
182
- rubysl-matrix (2.1.0)
183
- rubysl-e2mmap (~> 2.0)
184
- rubysl-mkmf (2.1)
185
- rubysl-fileutils (~> 2.0)
186
- rubysl-shellwords (~> 2.0)
187
- rubysl-monitor (2.1)
188
- rubysl-mutex_m (2.0.0)
189
- rubysl-net-ftp (2.0.1)
190
- rubysl-net-http (2.0.4)
191
- rubysl-cgi (~> 2.0)
192
- rubysl-erb (~> 2.0)
193
- rubysl-singleton (~> 2.0)
194
- rubysl-net-imap (2.0.1)
195
- rubysl-net-pop (2.0.1)
196
- rubysl-net-protocol (2.0.1)
197
- rubysl-net-smtp (2.0.1)
198
- rubysl-net-telnet (2.0.0)
199
- rubysl-nkf (2.0.1)
200
- rubysl-observer (2.0.0)
201
- rubysl-open-uri (2.0.0)
202
- rubysl-open3 (2.0.0)
203
- rubysl-openssl (2.10)
204
- rubysl-optparse (2.0.1)
205
- rubysl-shellwords (~> 2.0)
206
- rubysl-ostruct (2.1.0)
207
- rubysl-pathname (2.3)
208
- rubysl-prettyprint (2.0.3)
209
- rubysl-prime (2.0.1)
210
- rubysl-profile (2.0.0)
211
- rubysl-profiler (2.1)
212
- rubysl-pstore (2.0.0)
213
- rubysl-pty (2.0.3)
214
- rubysl-rational (2.0.1)
215
- rubysl-resolv (2.1.2)
216
- rubysl-rexml (2.0.4)
217
- rubysl-rinda (2.0.1)
218
- rubysl-rss (2.0.0)
219
- rubysl-scanf (2.0.0)
220
- rubysl-securerandom (2.0.0)
221
- rubysl-set (2.0.1)
222
- rubysl-shellwords (2.0.0)
223
- rubysl-singleton (2.0.0)
224
- rubysl-socket (2.2.1)
225
- rubysl-fcntl (~> 2.0)
226
- rubysl-stringio (2.3)
227
- rubysl-strscan (2.0.0)
228
- rubysl-sync (2.0.0)
229
- rubysl-syslog (2.1.0)
230
- ffi2-generators (~> 0.1)
231
- rubysl-tempfile (2.0.1)
232
- rubysl-thread (2.1)
233
- rubysl-thwait (2.0.0)
234
- rubysl-time (2.0.3)
235
- rubysl-timeout (2.0.0)
236
- rubysl-tmpdir (2.0.1)
237
- rubysl-tsort (2.0.1)
238
- rubysl-un (2.0.0)
239
- rubysl-fileutils (~> 2.0)
240
- rubysl-optparse (~> 2.0)
241
- rubysl-unicode_normalize (2.0)
242
- rubysl-uri (2.0.0)
243
- rubysl-weakref (2.0.0)
244
- rubysl-webrick (2.0.0)
245
- rubysl-xmlrpc (2.0.0)
246
- rubysl-yaml (2.1.0)
247
- rubysl-zlib (2.0.1)
248
- sqlite3 (1.3.13)
249
- thor (0.20.3)
250
- thread_safe (0.3.6)
251
- tzinfo (1.2.6)
252
- thread_safe (~> 0.1)
253
- zeitwerk (2.2.2)
254
-
255
- PLATFORMS
256
- ruby
257
-
258
- DEPENDENCIES
259
- activerecord-jdbcsqlite3-adapter
260
- appraisal (>= 1.0.2)
261
- nilify_blanks!
262
- rake (~> 13.0.1)
263
- rspec (>= 3.8.0)
264
- rubysl (~> 2.0)
265
- sqlite3 (~> 1.3.6)
266
-
267
- BUNDLED WITH
268
- 1.17.3
data/README.rdoc DELETED
@@ -1,103 +0,0 @@
1
- {<img src="https://secure.travis-ci.org/rubiety/nilify_blanks.png?branch=master" alt="Build Status" />}[http://travis-ci.org/rubiety/nilify_blanks]
2
-
3
- == Nilify Blanks
4
-
5
- In Rails when saving a model from a form and values are not provided by the user, an empty string is recorded to the database instead of a NULL as many would prefer (mixing blanks and NULLs can become confusing). This plugin allows you to specify a list of attributes (or exceptions from all the attributes) that will be converted to nil if they are blank before a model is saved.
6
-
7
- By default, columns set as NOT NULL will not be nilified, since that value cannot be persisted, and it might be better to catch that with a validation. If you want to nilify those columns anyway, you can use `only:` (see below) to explicitly mention them.
8
-
9
- Only attributes responding to blank? with a value of true will be converted to nil. Therefore, this does not work with integer fields with the value of 0, for example. Usage is best shown through examples:
10
-
11
- == Requirements
12
-
13
- As of v1.4.0, this gem requires Rails 4 and Ruby 2.2 or higher.
14
-
15
- == Install
16
-
17
- Include the gem using bundler in your Gemfile:
18
-
19
- gem "nilify_blanks"
20
-
21
- == Basic Usage
22
-
23
- # Checks and converts all content fields in the model
24
- class Post < ActiveRecord::Base
25
- nilify_blanks
26
- end
27
-
28
- # Checks and converts only text fields in the model
29
- class Post < ActiveRecord::Base
30
- nilify_blanks types: [:text]
31
- end
32
-
33
- # Checks and converts only the title and author fields
34
- class Post < ActiveRecord::Base
35
- nilify_blanks only: [:author, :title]
36
- end
37
-
38
- # Checks and converts all fields except for title and author
39
- class Post < ActiveRecord::Base
40
- nilify_blanks except: [:author, :title]
41
- end
42
-
43
- # Checks and converts any fields, regardless of their null constraint
44
- class Post < ActiveRecord::Base
45
- nilify_blanks nullables_only: false
46
- end
47
-
48
- == Global Usage
49
-
50
- You can also apply nilify_blanks to all models inheriting from ActiveRecord::Base:
51
-
52
- ActiveRecord::Base.nilify_blanks
53
-
54
- Or perhaps just a model namespace base class:
55
-
56
- Inventory::Base.nilify_blanks
57
-
58
- == Specifying a Callback
59
-
60
- Checking uses an ActiveRecord before_validation callback by default, but you can specify a different callback with the :before option. Any callback will work - just first remove the "before_" prefix from the name.
61
-
62
- class Post < ActiveRecord::Base
63
- nilify_blanks before: :create
64
- end
65
-
66
- class Post < ActiveRecord::Base
67
- nilify_blanks before: :validation_on_update
68
- end
69
-
70
- == RSpec Matcher
71
-
72
- First, include the matchers:
73
-
74
- require "nilify_blanks/matchers"
75
-
76
- To ensure for a given column:
77
-
78
- describe City do
79
- it { should nilify_blanks_for(:name) }
80
- end
81
-
82
- To ensure for all applicable content columns:
83
-
84
- describe City do
85
- it { should nilify_blanks }
86
- end
87
-
88
- You can optionally match on options also:
89
-
90
- describe City do
91
- it { should nilify_blanks_for(:name, before: :create) }
92
- end
93
-
94
- describe City do
95
- it { should nilify_blanks(before: :create) }
96
- end
97
-
98
- == Running Tests
99
-
100
- This gem uses appraisal to test with different versions of the dependencies. See Appraisal first for which versions are tested, then run to test all appraisals:
101
-
102
- $ rake appraisal install
103
- $ rake appraisal test
data/Rakefile DELETED
@@ -1,41 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'appraisal'
3
- require 'rspec/core/rake_task'
4
-
5
- require 'bundler/setup'
6
-
7
- require 'rake'
8
- require 'rspec/core/rake_task'
9
-
10
- desc "Default: run unit tests."
11
- task default: [:clean, :all]
12
-
13
- task test: :spec
14
-
15
- desc "Test this plugin under all supported Rails versions."
16
- task :all do |t|
17
- if ENV['BUNDLE_GEMFILE']
18
- exec('rake spec && cucumber')
19
- else
20
- exec("rm -f gemfiles/*.lock")
21
- Rake::Task["appraisal:gemfiles"].execute
22
- Rake::Task["appraisal:install"].execute
23
- exec('rake appraisal')
24
- end
25
- end
26
-
27
- desc "Run Specs"
28
- RSpec::Core::RakeTask.new(:spec)
29
-
30
- desc "Start an IRB session within this plugin"
31
- task :shell do |t|
32
- chdir File.dirname(__FILE__)
33
- exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
34
- end
35
-
36
- desc "Clean up files."
37
- task :clean do |t|
38
- FileUtils.rm_rf "tmp"
39
- Dir.glob("nilify_blanks-*.gem").each {|f| FileUtils.rm f }
40
- Dir.glob("spec/db/*.sqlite3").each {|f| FileUtils.rm f }
41
- end
data/init.rb DELETED
@@ -1,3 +0,0 @@
1
- require "nilify_blanks"
2
-
3
- NilifyBlanks::Railtie.insert
data/spec/db/database.yml DELETED
@@ -1,21 +0,0 @@
1
- sqlite:
2
- adapter: sqlite
3
- database: spec/db/test.sqlite
4
-
5
- sqlite3:
6
- adapter: sqlite3
7
- database: spec/db/test.sqlite3
8
-
9
- postgresql:
10
- adapter: postgresql
11
- username: postgres
12
- password: postgres
13
- database: nilify_blanks_plugin_test
14
- min_messages: ERROR
15
-
16
- mysql:
17
- adapter: mysql
18
- host: localhost
19
- username: root
20
- password:
21
- database: nilify_blanks_plugin_test
data/spec/db/schema.rb DELETED
@@ -1,15 +0,0 @@
1
- ActiveRecord::Schema.define(:version => 0) do
2
-
3
- create_table :posts, :force => true do |t|
4
- t.string :first_name
5
- t.string :last_name, :null => false
6
- t.string :title
7
- t.text :summary
8
- t.text :body
9
- t.column :slug, :citext
10
- t.integer :views
11
- t.integer :category_id
12
- t.string :blog_id
13
- end
14
-
15
- end
data/spec/db/test.sqlite3 DELETED
Binary file
data/spec/examples.txt DELETED
@@ -1,30 +0,0 @@
1
- example_id | status | run_time |
2
- --------------------------------------- | ------ | --------------- |
3
- ./spec/nilify_blanks_spec.rb[1:1:1] | passed | 0.00172 seconds |
4
- ./spec/nilify_blanks_spec.rb[1:1:2] | passed | 0.00248 seconds |
5
- ./spec/nilify_blanks_spec.rb[1:1:3] | passed | 0.00081 seconds |
6
- ./spec/nilify_blanks_spec.rb[1:1:4] | passed | 0.00052 seconds |
7
- ./spec/nilify_blanks_spec.rb[1:1:5] | passed | 0.00158 seconds |
8
- ./spec/nilify_blanks_spec.rb[1:2:1] | passed | 0.00014 seconds |
9
- ./spec/nilify_blanks_spec.rb[1:3:1] | passed | 0.00037 seconds |
10
- ./spec/nilify_blanks_spec.rb[1:3:2] | passed | 0.00026 seconds |
11
- ./spec/nilify_blanks_spec.rb[1:3:3] | passed | 0.00033 seconds |
12
- ./spec/nilify_blanks_spec.rb[1:4:1] | passed | 0.00032 seconds |
13
- ./spec/nilify_blanks_spec.rb[1:4:2] | passed | 0.00016 seconds |
14
- ./spec/nilify_blanks_spec.rb[1:4:3] | passed | 0.00022 seconds |
15
- ./spec/nilify_blanks_spec.rb[1:5:1] | passed | 0.0002 seconds |
16
- ./spec/nilify_blanks_spec.rb[1:5:2] | passed | 0.00016 seconds |
17
- ./spec/nilify_blanks_spec.rb[1:5:3] | passed | 0.00028 seconds |
18
- ./spec/nilify_blanks_spec.rb[1:6:1:1] | passed | 0.00091 seconds |
19
- ./spec/nilify_blanks_spec.rb[1:6:2:1] | passed | 0.00023 seconds |
20
- ./spec/nilify_blanks_spec.rb[1:6:3:1] | passed | 0.00047 seconds |
21
- ./spec/nilify_blanks_spec.rb[1:6:4:1] | passed | 0.00041 seconds |
22
- ./spec/nilify_blanks_spec.rb[1:7:1:1] | passed | 0.00067 seconds |
23
- ./spec/nilify_blanks_spec.rb[1:7:1:2] | passed | 0.00072 seconds |
24
- ./spec/nilify_blanks_spec.rb[1:7:1:3] | passed | 0.00072 seconds |
25
- ./spec/nilify_blanks_spec.rb[1:7:1:4] | passed | 0.00087 seconds |
26
- ./spec/nilify_blanks_spec.rb[1:7:1:5] | passed | 0.00051 seconds |
27
- ./spec/nilify_blanks_spec.rb[1:7:1:6] | passed | 0.00036 seconds |
28
- ./spec/nilify_blanks_spec.rb[1:7:1:7] | passed | 0.00041 seconds |
29
- ./spec/nilify_blanks_spec.rb[1:7:1:8] | passed | 0.00171 seconds |
30
- ./spec/nilify_blanks_spec.rb[1:7:2:1:1] | passed | 0.00149 seconds |
@@ -1,264 +0,0 @@
1
- require "nilify_blanks/matchers"
2
-
3
- RSpec.describe NilifyBlanks do
4
- context "Model with nilify_blanks" do
5
- before(:all) do
6
- class Post < ActiveRecord::Base
7
- nilify_blanks
8
- end
9
-
10
- @post = Post.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0, :blog_id => '')
11
- @post.save
12
- end
13
-
14
- it "should recognize all non-null string, text, citext columns" do
15
- expect(Post.nilify_blanks_columns).to eq(['first_name', 'title', 'summary', 'body', 'slug', 'blog_id'])
16
- end
17
-
18
- it "should convert all blanks to nils" do
19
- expect(@post.first_name).to be_nil
20
- expect(@post.title).to be_nil
21
- expect(@post.summary).to be_nil
22
- expect(@post.body).to be_nil
23
- expect(@post.slug).to be_nil
24
- expect(@post.blog_id).to be_nil
25
- end
26
-
27
- it "should leave not-null last name field alone" do
28
- expect(@post.last_name).to eq("")
29
- end
30
-
31
- it "should leave integer views field alone" do
32
- expect(@post.views).to eq(0)
33
- end
34
-
35
- it "should not nilify non-null column" do
36
- expect(@post.class.nilify_blanks_columns).to_not include('last_name')
37
- end
38
- end
39
-
40
- context "Model with nilify_blanks :nullables_only => false" do
41
- before(:all) do
42
- class PostWithNullables < ActiveRecord::Base
43
- self.table_name = "posts"
44
- nilify_blanks :nullables_only => false
45
- end
46
-
47
- @post = PostWithNullables.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0, :blog_id => '')
48
- end
49
-
50
- it "should recognize all (even null) string, text, citext columns" do
51
- expect(PostWithNullables.nilify_blanks_columns).to eq(['first_name', 'last_name', 'title', 'summary', 'body', 'slug', 'blog_id'])
52
- end
53
- end
54
-
55
- context "Model with nilify_blanks :types => [:text]" do
56
- def citext_supported
57
- PostOnlyText.content_columns.detect {|c| c.type == :citext}
58
- end
59
-
60
- before(:all) do
61
- class PostOnlyText < ActiveRecord::Base
62
- self.table_name = "posts"
63
- nilify_blanks :types => [:text]
64
- end
65
-
66
- @post = PostOnlyText.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
67
- @post.save
68
- end
69
-
70
- it "should recognize all non-null text only columns" do
71
- expected_types = ['summary', 'body']
72
- expected_types << 'slug' unless citext_supported
73
- expect(PostOnlyText.nilify_blanks_columns).to eq(expected_types)
74
- end
75
-
76
- it "should convert all blanks to nils" do
77
- expect(@post.summary).to be_nil
78
- expect(@post.body).to be_nil
79
- expect(@post.slug).to be_nil unless citext_supported
80
- end
81
-
82
- it "should leave not-null string fields alone" do
83
- expect(@post.first_name).to eq("")
84
- expect(@post.last_name).to eq("")
85
- expect(@post.title).to eq("")
86
- expect(@post.slug).to eq("") if citext_supported
87
- end
88
- end
89
-
90
- context "Model with nilify_blanks :only => [:first_name, :title]" do
91
- before(:all) do
92
- class PostOnlyFirstNameAndTitle < ActiveRecord::Base
93
- self.table_name = "posts"
94
- nilify_blanks :only => [:first_name, :title]
95
- end
96
-
97
- @post = PostOnlyFirstNameAndTitle.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
98
- @post.save
99
- end
100
-
101
- it "should recognize only first_name and title" do
102
- expect(PostOnlyFirstNameAndTitle.nilify_blanks_columns).to eq(['first_name', 'title'])
103
- end
104
-
105
- it "should convert first_name and title blanks to nils" do
106
- expect(@post.first_name).to be_nil
107
- expect(@post.title).to be_nil
108
- end
109
-
110
- it "should leave other fields alone" do
111
- expect(@post.summary).to eq("")
112
- expect(@post.body).to eq("")
113
- expect(@post.slug).to eq("")
114
- end
115
- end
116
-
117
- context "Model with nilify_blanks :except => [:first_name, :title]" do
118
- before(:all) do
119
- class PostExceptFirstNameAndTitle < ActiveRecord::Base
120
- self.table_name = "posts"
121
- nilify_blanks :except => [:first_name, :title, :blog_id]
122
- end
123
-
124
- @post = PostExceptFirstNameAndTitle.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
125
- @post.save
126
- end
127
-
128
- it "should recognize only summary, body, and views" do
129
- expect(PostExceptFirstNameAndTitle.nilify_blanks_columns).to eq(['summary', 'body', 'slug'])
130
- end
131
-
132
- it "should convert summary and body blanks to nils" do
133
- expect(@post.summary).to be_nil
134
- expect(@post.body).to be_nil
135
- expect(@post.slug).to be_nil
136
- end
137
-
138
- it "should leave other fields alone" do
139
- expect(@post.first_name).to eq("")
140
- expect(@post.title).to eq("")
141
- end
142
- end
143
-
144
-
145
- context "Global Usage" do
146
- context "Namespaced Base Class with nilify_blanks inline" do
147
- before(:all) do
148
- module Admin1
149
- class Base < ActiveRecord::Base
150
- self.abstract_class = true
151
- nilify_blanks
152
- end
153
- end
154
-
155
- class Admin1::Post < Admin1::Base
156
- self.table_name = "posts"
157
- end
158
-
159
- @post = Admin1::Post.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
160
- @post.save
161
- end
162
-
163
- it "should convert all blanks to nils" do
164
- expect(@post.first_name).to be_nil
165
- end
166
- end
167
-
168
- context "Namespaced Base Class with nilify_blanks applied after definition" do
169
- before(:all) do
170
- module Admin2
171
- class Base < ActiveRecord::Base
172
- self.abstract_class = true
173
- end
174
- end
175
-
176
- class Admin2::Post < Admin2::Base
177
- self.table_name = "posts"
178
- end
179
-
180
- Admin2::Base.nilify_blanks
181
-
182
- @post = Admin2::Post.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
183
- @post.save
184
- end
185
-
186
- it "should convert all blanks to nils" do
187
- expect(@post.first_name).to be_nil
188
- end
189
- end
190
-
191
- context "Namespaced Base Class with nilify_blanks applied after definition" do
192
- before(:all) do
193
- ActiveRecord::Base.nilify_blanks
194
-
195
- class InheritedPost < ActiveRecord::Base
196
- self.table_name = "posts"
197
- end
198
-
199
- @post = InheritedPost.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
200
- @post.save
201
- end
202
-
203
- it "should convert all blanks to nils" do
204
- expect(@post.first_name).to be_nil
205
- end
206
- end
207
-
208
- context "Namespaced Base Class with nilify_blanks with overrides applied after definition" do
209
- before(:all) do
210
- ActiveRecord::Base.nilify_blanks
211
-
212
- class InheritedPost < ActiveRecord::Base
213
- self.table_name = "posts"
214
-
215
- nilify_blanks except: [:first_name]
216
- end
217
-
218
- @post = InheritedPost.new(:first_name => '', :last_name => '', :title => '', :summary => '', :body => '', :slug => '', :views => 0)
219
- @post.save
220
- end
221
-
222
- it "should convert all blanks to nils" do
223
- expect(@post.first_name).to_not be_nil
224
- expect(@post.title).to be_nil
225
- end
226
- end
227
- end
228
-
229
- describe "matchers" do
230
- describe "nilify_blanks_for" do
231
- subject { Post.new }
232
-
233
- before(:all) do
234
- class Post < ActiveRecord::Base
235
- nilify_blanks
236
- end
237
- end
238
-
239
- it { is_expected.to nilify_blanks_for(:first_name) }
240
- it { is_expected.to nilify_blanks_for(:title) }
241
- it { is_expected.to nilify_blanks_for(:summary) }
242
- it { is_expected.to nilify_blanks_for(:body) }
243
- it { is_expected.to nilify_blanks_for(:slug) }
244
- it { is_expected.to nilify_blanks_for(:blog_id) }
245
-
246
- it { is_expected.to_not nilify_blanks_for(:id) }
247
- it { is_expected.to_not nilify_blanks_for(:last_name) }
248
- end
249
-
250
- describe "nilify_blanks" do
251
- subject { Post.new }
252
-
253
- before(:all) do
254
- class Post < ActiveRecord::Base
255
- nilify_blanks
256
- end
257
- end
258
-
259
- context "foreign key column is nilified" do
260
- it { is_expected.to nilify_blanks }
261
- end
262
- end
263
- end
264
- end
data/spec/spec_helper.rb DELETED
@@ -1,40 +0,0 @@
1
- require "rubygems"
2
- require "rspec"
3
- require "active_support"
4
- require "active_record"
5
- require "yaml"
6
-
7
- # Establish DB Connection
8
- config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'db', 'database.yml')))
9
- ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
10
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
11
-
12
- # Load Test Schema into the Database
13
- load(File.dirname(__FILE__) + "/db/schema.rb")
14
-
15
- require File.dirname(__FILE__) + '/../init'
16
-
17
- RSpec.configure do |config|
18
- config.define_derived_metadata do |meta|
19
- meta[:aggregate_failures] = true unless meta.key?(:aggregate_failures)
20
- end
21
-
22
- config.disable_monkey_patching!
23
-
24
- config.expect_with :rspec do |expectations|
25
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
26
- end
27
-
28
- config.mock_with :rspec do |mocks|
29
- mocks.verify_partial_doubles = true
30
- end
31
-
32
- config.shared_context_metadata_behavior = :apply_to_host_groups
33
- config.filter_run_when_matching :focus
34
- config.example_status_persistence_file_path = "spec/examples.txt"
35
-
36
- # config.order = :random
37
- # Kernel.srand config.seed
38
-
39
- # config.warnings = true
40
- end