large_text_field 0.3.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/db/migrate/20110217210640_add_large_text_fields.rb +1 -2
- data/lib/large_text_field/named_text_value.rb +0 -4
- data/lib/large_text_field/owner.rb +2 -2
- data/lib/large_text_field/version.rb +1 -1
- data/lib/large_text_field.rb +0 -2
- data/test/dummy/app/models/library.rb +0 -1
- data/test/dummy/config/database.yml +13 -1
- data/test/dummy/config/environments/development.rb +0 -3
- data/test/dummy/config/environments/test.rb +0 -3
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +10 -9
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +32 -12
- data/test/dummy/log/test.log +1261 -439
- data/test/reports/TEST-LargeTextField-LibraryTest.xml +3 -3
- data/test/reports/TEST-LargeTextField-NamedTextValueTest.xml +6 -6
- data/test/reports/TEST-LargeTextField-OwnerTest.xml +26 -24
- data/test/reports/TEST-LargeTextFieldTest.xml +2 -2
- data/test/test_helper.rb +3 -1
- data/test/unit/large_text_field/owner_test.rb +4 -0
- metadata +13 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f32662941052c47f238878093fa9ca751cc85b87cd2247b8bd7de2e88762dc1
|
4
|
+
data.tar.gz: d8b1867ae5d565b5203c0e8c0c352d5a8c02256fe14b4c83d84ba41a40cf3885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd2868895b7a9fb3b0112e88cf6988d079e1685d68ae25aa3ef0c362b0559ffe9695671d6fc1211e64eab7127be81ebcb72fe151acaadc7cbcfb51126eb5ddf
|
7
|
+
data.tar.gz: f98433084f56f6c2d8a5f2342eace05c8363b579269fd45de9f07d6b9ff591bf8c78edad8fea314c59ee2fc8afbd7b61fa879057cfe264263aa75e733614f92f
|
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
|
-
|
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
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class AddLargeTextFields < ActiveRecord::Migration
|
4
|
-
|
3
|
+
class AddLargeTextFields < (Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
|
5
4
|
def self.up
|
6
5
|
create_table :large_text_fields do |t|
|
7
6
|
t.string :field_name, null: false
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "protected_attributes"
|
4
|
-
|
5
3
|
module LargeTextField
|
6
4
|
class NamedTextValue < ActiveRecord::Base
|
7
5
|
# Schema
|
@@ -10,8 +8,6 @@ module LargeTextField
|
|
10
8
|
#
|
11
9
|
# index [ :owner_type, :owner_id, :field_name ], :name => 'large_text_field_by_owner_field', :unique=>true
|
12
10
|
|
13
|
-
attr_accessible :field_name, :value, :owner_type, :owner_id, :owner
|
14
|
-
|
15
11
|
belongs_to :owner, polymorphic: true, inverse_of: :large_text_fields
|
16
12
|
|
17
13
|
self.table_name = "large_text_fields"
|
data/lib/large_text_field.rb
CHANGED
@@ -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
|
@@ -24,9 +24,6 @@ Dummy::Application.configure do
|
|
24
24
|
# Only use best-standards-support built into browsers
|
25
25
|
config.action_dispatch.best_standards_support = :builtin
|
26
26
|
|
27
|
-
# Raise exception on mass assignment protection for Active Record models
|
28
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
29
|
-
|
30
27
|
# Log the query plan for queries taking more than this (works
|
31
28
|
# with SQLite, MySQL, and PostgreSQL)
|
32
29
|
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
@@ -31,9 +31,6 @@ Dummy::Application.configure do
|
|
31
31
|
# ActionMailer::Base.deliveries array.
|
32
32
|
config.action_mailer.delivery_method = :test
|
33
33
|
|
34
|
-
# Raise exception on mass assignment protection for Active Record models
|
35
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
36
|
-
|
37
34
|
# Print deprecation notices to the stderr
|
38
35
|
config.active_support.deprecation = :stderr
|
39
36
|
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: UTF-8
|
3
2
|
# This file is auto-generated from the current state of the database. Instead
|
4
3
|
# of editing this file, please use the migrations feature of Active Record to
|
5
4
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -12,17 +11,19 @@
|
|
12
11
|
#
|
13
12
|
# It's strongly recommended that you check this file into your version control system.
|
14
13
|
|
15
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160217033529) do
|
15
|
+
|
16
16
|
create_table "large_text_fields", force: :cascade do |t|
|
17
|
-
t.string "field_name", null: false
|
18
|
-
t.text "value",
|
19
|
-
t.integer "owner_id",
|
20
|
-
t.string "owner_type",
|
17
|
+
t.string "field_name", limit: 255, null: false
|
18
|
+
t.text "value", limit: 16777215
|
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",
|
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
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -1,19 +1,39 @@
|
|
1
|
-
[1m[36m (
|
1
|
+
[1m[36m (2.3ms)[0m [1mCREATE 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) [0m
|
2
2
|
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
3
|
-
[1m[36m (1.
|
4
|
-
[1m[35m (1.
|
5
|
-
[1m[36m (1.
|
3
|
+
[1m[36m (1.7ms)[0m [1mCREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")[0m
|
4
|
+
[1m[35m (1.7ms)[0m CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
|
5
|
+
[1m[36m (1.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
6
6
|
[1m[35m (1.4ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
7
7
|
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
8
|
-
[1m[35m (1.
|
9
|
-
[1m[36m (1.
|
10
|
-
[1m[35m (1.
|
8
|
+
[1m[35m (1.8ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20160217033529')
|
9
|
+
[1m[36m (1.7ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20110217210640')[0m
|
10
|
+
[1m[35m (1.8ms)[0m DROP TABLE "large_text_fields"
|
11
|
+
[1m[36m (1.4ms)[0m [1mCREATE 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) [0m
|
12
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
13
|
+
[1m[36m (6.1ms)[0m [1mCREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")[0m
|
14
|
+
[1m[35m (1.3ms)[0m DROP TABLE "libraries"
|
15
|
+
[1m[36m (1.6ms)[0m [1mCREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) [0m
|
16
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
17
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
18
|
+
[1m[36m (1.6ms)[0m [1mDROP TABLE "large_text_fields"[0m
|
19
|
+
[1m[35m (1.1ms)[0m 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)
|
11
20
|
[1m[36m (0.0ms)[0m [1mselect sqlite_version(*)[0m
|
12
21
|
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
|
13
|
-
[1m[36m (1.
|
14
|
-
[1m[35m (1.
|
15
|
-
[1m[36m (
|
22
|
+
[1m[36m (1.2ms)[0m [1mDROP TABLE "libraries"[0m
|
23
|
+
[1m[35m (1.0ms)[0m CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
|
24
|
+
[1m[36m (0.3ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
25
|
+
[1m[35m (1.2ms)[0m DROP TABLE "large_text_fields"
|
26
|
+
[1m[36m (1.2ms)[0m [1mCREATE 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) [0m
|
27
|
+
[1m[35m (0.0ms)[0m select sqlite_version(*)
|
28
|
+
[1m[36m (1.1ms)[0m [1mCREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")[0m
|
29
|
+
[1m[35m (1.1ms)[0m DROP TABLE "libraries"
|
30
|
+
[1m[36m (1.2ms)[0m [1mCREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) [0m
|
16
31
|
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
17
|
-
[1m[36m (1.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20160217033529')[0m
|
18
|
-
[1m[35m (1.2ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20110217210640')
|
19
32
|
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
33
|
+
[1m[36m (1.4ms)[0m [1mDROP TABLE "large_text_fields"[0m
|
34
|
+
[1m[35m (1.2ms)[0m 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
|
+
[1m[36m (0.0ms)[0m [1mselect sqlite_version(*)[0m
|
36
|
+
[1m[35m (1.1ms)[0m CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
|
37
|
+
[1m[36m (1.1ms)[0m [1mDROP TABLE "libraries"[0m
|
38
|
+
[1m[35m (0.9ms)[0m CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
|
39
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|