large_text_field 0.3.1 → 1.0.2.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +6 -2
  3. data/Rakefile +5 -3
  4. data/db/migrate/20110217210640_add_large_text_fields.rb +3 -2
  5. data/lib/large_text_field/engine.rb +2 -0
  6. data/lib/large_text_field/named_text_value.rb +1 -3
  7. data/lib/large_text_field/owner.rb +10 -6
  8. data/lib/large_text_field/version.rb +3 -1
  9. data/lib/large_text_field.rb +1 -2
  10. data/test/dummy/Rakefile +3 -1
  11. data/test/dummy/app/assets/config/manifest.js +1 -0
  12. data/test/dummy/app/models/library.rb +2 -1
  13. data/test/dummy/config/application.rb +3 -1
  14. data/test/dummy/config/boot.rb +4 -2
  15. data/test/dummy/config/database.yml +13 -1
  16. data/test/dummy/config/environment.rb +3 -1
  17. data/test/dummy/config/environments/development.rb +2 -3
  18. data/test/dummy/config/environments/production.rb +2 -0
  19. data/test/dummy/config/environments/test.rb +2 -3
  20. data/test/dummy/config.ru +2 -0
  21. data/test/dummy/db/development.sqlite3 +0 -0
  22. data/test/dummy/db/migrate/20160217033529_create_libraries.rb +2 -0
  23. data/test/dummy/db/schema.rb +5 -5
  24. data/test/dummy/db/test.sqlite3 +0 -0
  25. data/test/dummy/log/development.log +39 -0
  26. data/test/dummy/log/test.log +827 -3763
  27. data/test/dummy/script/rails +4 -2
  28. data/test/large_text_field_test.rb +2 -0
  29. data/test/reports/TEST-LargeTextField-LibraryTest.xml +9 -0
  30. data/test/reports/TEST-LargeTextField-NamedTextValueTest.xml +15 -0
  31. data/test/reports/TEST-LargeTextField-OwnerTest.xml +53 -0
  32. data/test/reports/TEST-LargeTextFieldTest.xml +7 -0
  33. data/test/test_helper.rb +11 -2
  34. data/test/unit/dummy/library_test.rb +2 -0
  35. data/test/unit/large_text_field/name_text_value_test.rb +2 -0
  36. data/test/unit/large_text_field/owner_test.rb +18 -16
  37. metadata +35 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 40f3feb2ddeb7499788d2f89e5e5f6d65944c69f
4
- data.tar.gz: 97fd1b431fc477370eb2822f979ab6409186c821
2
+ SHA256:
3
+ metadata.gz: 02daae5b81c9b3ebef6f0e373e74a773df8bbdaa62df75c09b24b5743dc0fe55
4
+ data.tar.gz: c87ac6a50da96644a853cb70dc976644bc21dd44a8c0d1b8e70fe90a8b459ac8
5
5
  SHA512:
6
- metadata.gz: 92550cce241931423df48769f67fb3caf6750c3af8b85445883be0513f346e93b4cae87006fa3054fd589cce4f8036caad17c3373d69850cae196dd02734937a
7
- data.tar.gz: 24dec0903a9b9100fc3242519f746151d1e57edf7bf4e3c7ab1382ccad0c914c66e179f84968b296bcfbf5896cc5016fd67a2ab8771c9b788e23534b018a0a05
6
+ metadata.gz: 413ecb6c2949f64ffb298c9ce35cabd57e4791ad5994cd67b6d26f1092baf90430279910d7b0ac00412753628e4973059ac62df66dfb9f60184c247e81745639
7
+ data.tar.gz: c809eabe4ee4995de694d5fa41fbaac7e6df37cd36812136389837dc41e58a7310b40b224c1638f682b3be1835fd56a14395199be47d2f3c308a9da964b67322
data/README.md CHANGED
@@ -6,7 +6,11 @@ This gem allows any model to be associated with multiple named text fields. Eac
6
6
  characters. Defining new fields on models does not require a database migrations. All text fields are stored in a
7
7
  central table that is polymorphically associated with the model, but they act like a column on on the same model.
8
8
 
9
- # How do I use it?
9
+ ## Dependencies
10
+ * Ruby >= 2.6
11
+ * Rails >= 4.2, < 7
12
+
13
+ ## How do I use it?
10
14
  In you Gemfile add:
11
15
 
12
16
  ```
@@ -32,7 +36,7 @@ The large_text_field macro takes the following options...
32
36
  * **maximum:** - The maximum length of a large text field. By default this is 5,000,000 characters, but it can be set to less using this option.
33
37
  * **singularize_errors:** - should validation messages be singularized.
34
38
 
35
- Large text fields default to an empty string. You cannot store nil in a large text field.
39
+ Large text fields default to an empty string. You cannot store nil in a large text field.
36
40
 
37
41
  **Please note:** Large text field uses the *before_save* callback on the class that is the owner for book-keeping. Callbacks are great, but if there are multiple handlers for the same callback the order in which they are called is not predictable. If you want to make changes to large_text_field values in the before_save callback, use the **large_text_field_save** callback instead. This will be called before the large text field book-keeping so your changes will be saved. For example, this will call the save_preprocess method on your class before the large text fields are saved...
38
42
 
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  begin
3
5
  require 'bundler/setup'
4
6
  rescue LoadError
@@ -23,14 +25,14 @@ RDoc::Task.new(:rdoc) do |rdoc|
23
25
  rdoc.rdoc_files.include('lib/**/*.rb')
24
26
  end
25
27
 
26
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
28
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
27
29
  load 'rails/tasks/engine.rake'
28
30
 
29
31
  require 'rake/testtask'
30
32
  require 'rubocop/rake_task'
31
33
 
32
34
  namespace :db do
33
- task :migrate => [:environment] do |t|
35
+ task migrate: [:environment] do |_t|
34
36
  system("bundle exec rake db:setup RAILS_ENV='test'")
35
37
  end
36
38
  end
@@ -42,7 +44,7 @@ Rake::TestTask.new(:test) do |t|
42
44
  t.verbose = false
43
45
  end
44
46
 
45
- task default: [:test, :rubocop]
47
+ task default: %i[test rubocop]
46
48
 
47
49
  desc 'Run rubocop'
48
50
  task :rubocop do
@@ -1,5 +1,6 @@
1
- class AddLargeTextFields < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
2
 
3
+ class AddLargeTextFields < (Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
3
4
  def self.up
4
5
  create_table :large_text_fields do |t|
5
6
  t.string :field_name, null: false
@@ -7,7 +8,7 @@ class AddLargeTextFields < ActiveRecord::Migration
7
8
  t.integer :owner_id, null: false
8
9
  t.string :owner_type, null: false
9
10
  end
10
- add_index :large_text_fields, [:owner_type, :owner_id, :field_name], unique: true, name: 'large_text_field_by_owner_field'
11
+ add_index :large_text_fields, %i[owner_type owner_id field_name], unique: true, name: 'large_text_field_by_owner_field'
11
12
  end
12
13
 
13
14
  def self.down
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/engine'
2
4
 
3
5
  module LargeTextField
@@ -1,4 +1,4 @@
1
- require "protected_attributes"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module LargeTextField
4
4
  class NamedTextValue < ActiveRecord::Base
@@ -8,8 +8,6 @@ module LargeTextField
8
8
  #
9
9
  # index [ :owner_type, :owner_id, :field_name ], :name => 'large_text_field_by_owner_field', :unique=>true
10
10
 
11
- attr_accessible :field_name, :value, :owner_type, :owner_id, :owner
12
-
13
11
  belongs_to :owner, polymorphic: true, inverse_of: :large_text_fields
14
12
 
15
13
  self.table_name = "large_text_fields"
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "invoca/utils"
4
+
1
5
  module LargeTextField
2
6
  module Owner
3
7
  extend ActiveSupport::Concern
@@ -23,8 +27,8 @@ module LargeTextField
23
27
  result
24
28
  end
25
29
 
26
- def reload
27
- super
30
+ def reload(options = nil)
31
+ super(options)
28
32
  @text_field_hash = nil
29
33
  self
30
34
  end
@@ -38,7 +42,7 @@ module LargeTextField
38
42
  end
39
43
 
40
44
  def get_text_field(field_name)
41
- text_field_hash[field_name.to_s]._?.value || ''
45
+ text_field_hash[field_name.to_s]&.value || ''
42
46
  end
43
47
 
44
48
  def set_text_field(original_field_name, original_value)
@@ -54,13 +58,13 @@ module LargeTextField
54
58
  end
55
59
 
56
60
  def text_field_changed(field_name)
57
- text_field_hash_loaded? && @text_field_hash[field_name]._?.changes._?.any?
61
+ text_field_hash_loaded? && @text_field_hash[field_name]&.changes&.any?
58
62
  end
59
63
 
60
64
  def validate_large_text_fields
61
65
  if text_field_hash_loaded?
62
66
  large_text_field_options.each do |k, options|
63
- value = text_field_hash[k]._?.value
67
+ value = text_field_hash[k]&.value
64
68
  conjugation = options[:singularize_errors] ? "is" : "are"
65
69
  maximum = options[:maximum] || MAX_LENGTH
66
70
  errors.add k, "#{conjugation} too long (maximum is #{self.class.formatted_integer_value(maximum)} characters)" if value.present? && value.size > maximum
@@ -92,7 +96,7 @@ module LargeTextField
92
96
  raise ArgumentError, "maximum must be a number"
93
97
  elsif maximum > MAX_LENGTH
94
98
  raise ArgumentError, "maximum can't be greater than #{formatted_integer_value(MAX_LENGTH)}"
95
- elsif maximum < 0
99
+ elsif maximum.negative?
96
100
  raise ArgumentError, "maximum can't be less than 0"
97
101
  end
98
102
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LargeTextField
2
- VERSION = "0.3.1"
4
+ VERSION = "1.0.2.pre.1"
3
5
  end
@@ -1,5 +1,4 @@
1
- require "hobo_support"
2
- require "protected_attributes"
1
+ # frozen_string_literal: true
3
2
 
4
3
  require "rails"
5
4
 
data/test/dummy/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  # Add your own tasks in files placed in lib/tasks ending in .rake,
3
5
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
6
 
5
- require File.expand_path('../config/application', __FILE__)
7
+ require File.expand_path('config/application', __dir__)
6
8
 
7
9
  Dummy::Application.load_tasks
@@ -0,0 +1 @@
1
+ {}
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Library < ActiveRecord::Base
2
4
  include LargeTextField::Owner
3
5
 
4
6
  # Schema
5
7
  # name :string, :limit => 255
6
- attr_accessible :name, :description, :catalog, :notes
7
8
 
8
9
  large_text_field :description, singularize_errors: true
9
10
  large_text_field :catalog, maximum: 500, singularize_errors: true
@@ -1,4 +1,6 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('boot', __dir__)
2
4
 
3
5
  require 'rails/all'
4
6
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
4
+ gemfile = File.expand_path('../../../Gemfile', __dir__)
3
5
 
4
6
  if File.exist?(gemfile)
5
7
  ENV['BUNDLE_GEMFILE'] = gemfile
@@ -7,4 +9,4 @@ if File.exist?(gemfile)
7
9
  Bundler.setup
8
10
  end
9
11
 
10
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
12
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -12,11 +12,23 @@ development:
12
12
  # Warning: The database defined as "test" will be erased and
13
13
  # re-generated from your development database when you run "rake".
14
14
  # Do not set this db to the same as development or production.
15
+ <% if ENV["USE_MYSQL_DB"] %>
16
+ test:
17
+ adapter: mysql2
18
+ encoding: utf8
19
+ reconnect: false
20
+ database: large_text_field_test
21
+ pool: 5
22
+ username: <%= ENV['DATABASE_MYSQL_USERNAME'] || 'root' %>
23
+ password: <%= ENV['DATABASE_MYSQL_PASSWORD'] || '' %>
24
+ host: <%= ENV['DATABASE_MYSQL_HOST'] || 'localhost' %>
25
+ <% else %>
15
26
  test:
16
27
  adapter: sqlite3
17
- database: db/test.sqlite3
28
+ database: <%= ENV['TEST_DB'].presence || 'db/test.sqlite3' %>
18
29
  pool: 5
19
30
  timeout: 5000
31
+ <% end %>
20
32
 
21
33
  production:
22
34
  adapter: sqlite3
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
4
+ require File.expand_path('application', __dir__)
3
5
 
4
6
  # Initialize the rails application
5
7
  Dummy::Application.initialize!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -22,9 +24,6 @@ Dummy::Application.configure do
22
24
  # Only use best-standards-support built into browsers
23
25
  config.action_dispatch.best_standards_support = :builtin
24
26
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
27
-
28
27
  # Log the query plan for queries taking more than this (works
29
28
  # with SQLite, MySQL, and PostgreSQL)
30
29
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -29,9 +31,6 @@ Dummy::Application.configure do
29
31
  # ActionMailer::Base.deliveries array.
30
32
  config.action_mailer.delivery_method = :test
31
33
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
-
35
34
  # Print deprecation notices to the stderr
36
35
  config.active_support.deprecation = :stderr
37
36
 
data/test/dummy/config.ru CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is used by Rack-based servers to start the application.
2
4
 
3
5
  require ::File.expand_path('../config/environment', __FILE__)
File without changes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateLibraries < ActiveRecord::Migration
2
4
  def self.up
3
5
  create_table :libraries do |t|
@@ -14,16 +14,16 @@
14
14
  ActiveRecord::Schema.define(version: 20160217033529) do
15
15
 
16
16
  create_table "large_text_fields", force: :cascade do |t|
17
- t.string "field_name", null: false
17
+ t.string "field_name", limit: 255, null: false
18
18
  t.text "value", limit: 16777215
19
- t.integer "owner_id", null: false
20
- t.string "owner_type", null: false
19
+ t.integer "owner_id", limit: 4, null: false
20
+ t.string "owner_type", limit: 255, null: false
21
21
  end
22
22
 
23
- add_index "large_text_fields", ["owner_type", "owner_id", "field_name"], name: "large_text_field_by_owner_field", unique: true
23
+ add_index "large_text_fields", ["owner_type", "owner_id", "field_name"], name: "large_text_field_by_owner_field", unique: true, using: :btree
24
24
 
25
25
  create_table "libraries", force: :cascade do |t|
26
- t.string "name", null: false
26
+ t.string "name", limit: 255, null: false
27
27
  end
28
28
 
29
29
  end
Binary file
@@ -0,0 +1,39 @@
1
+  (2.3ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
2
+  (0.1ms) select sqlite_version(*)
3
+  (1.7ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
4
+  (1.7ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
5
+  (1.5ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
6
+  (1.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
7
+  (0.1ms) SELECT version FROM "schema_migrations"
8
+  (1.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20160217033529')
9
+  (1.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20110217210640')
10
+  (1.8ms) DROP TABLE "large_text_fields"
11
+  (1.4ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
12
+  (0.1ms) select sqlite_version(*)
13
+  (6.1ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
14
+  (1.3ms) DROP TABLE "libraries"
15
+  (1.6ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) 
16
+  (0.1ms) SELECT version FROM "schema_migrations"
17
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
18
+  (1.6ms) DROP TABLE "large_text_fields"
19
+  (1.1ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL)
20
+  (0.0ms) select sqlite_version(*)
21
+  (1.2ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
22
+  (1.2ms) DROP TABLE "libraries"
23
+  (1.0ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
24
+  (0.3ms) SELECT version FROM "schema_migrations"
25
+  (1.2ms) DROP TABLE "large_text_fields"
26
+  (1.2ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
27
+  (0.0ms) select sqlite_version(*)
28
+  (1.1ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
29
+  (1.1ms) DROP TABLE "libraries"
30
+  (1.2ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) 
31
+  (0.1ms) SELECT version FROM "schema_migrations"
32
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
33
+  (1.4ms) DROP TABLE "large_text_fields"
34
+  (1.2ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL)
35
+  (0.0ms) select sqlite_version(*)
36
+  (1.1ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
37
+  (1.1ms) DROP TABLE "libraries"
38
+  (0.9ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
39
+  (0.1ms) SELECT version FROM "schema_migrations"