large_text_field 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +25 -17
  4. data/Rakefile +2 -1
  5. data/config/brakeman.ignore +12 -0
  6. data/db/migrate/20110217210640_add_large_text_fields.rb +2 -0
  7. data/lib/large_text_field/application_record.rb +7 -0
  8. data/lib/large_text_field/named_text_value.rb +3 -1
  9. data/lib/large_text_field/owner.rb +22 -6
  10. data/lib/large_text_field/version.rb +1 -1
  11. data/lib/large_text_field.rb +5 -4
  12. metadata +24 -81
  13. data/test/dummy/README.rdoc +0 -261
  14. data/test/dummy/Rakefile +0 -9
  15. data/test/dummy/app/assets/config/manifest.js +0 -1
  16. data/test/dummy/app/models/library.rb +0 -23
  17. data/test/dummy/config/application.rb +0 -54
  18. data/test/dummy/config/boot.rb +0 -12
  19. data/test/dummy/config/database.yml +0 -37
  20. data/test/dummy/config/environment.rb +0 -7
  21. data/test/dummy/config/environments/development.rb +0 -38
  22. data/test/dummy/config/environments/production.rb +0 -71
  23. data/test/dummy/config/environments/test.rb +0 -41
  24. data/test/dummy/config.ru +0 -6
  25. data/test/dummy/db/development.sqlite3 +0 -0
  26. data/test/dummy/db/migrate/20160217033529_create_libraries.rb +0 -13
  27. data/test/dummy/db/schema.rb +0 -29
  28. data/test/dummy/db/test.sqlite3 +0 -0
  29. data/test/dummy/log/development.log +0 -39
  30. data/test/dummy/log/test.log +0 -2893
  31. data/test/dummy/script/rails +0 -8
  32. data/test/dummy/test/fixtures/text_field_owners.yml +0 -11
  33. data/test/fixtures/large_text_field/named_text_values.yml +0 -11
  34. data/test/large_text_field_test.rb +0 -9
  35. data/test/reports/TEST-LargeTextField-LibraryTest.xml +0 -9
  36. data/test/reports/TEST-LargeTextField-NamedTextValueTest.xml +0 -15
  37. data/test/reports/TEST-LargeTextField-OwnerTest.xml +0 -53
  38. data/test/reports/TEST-LargeTextFieldTest.xml +0 -7
  39. data/test/test_helper.rb +0 -46
  40. data/test/unit/dummy/library_test.rb +0 -25
  41. data/test/unit/large_text_field/name_text_value_test.rb +0 -49
  42. data/test/unit/large_text_field/owner_test.rb +0 -317
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
5
-
6
- APP_PATH = File.expand_path('../config/application', __dir__)
7
- require File.expand_path('../config/boot', __dir__)
8
- require 'rails/commands'
@@ -1,11 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
-
3
- # This model initially had no columns defined. If you add columns to the
4
- # model remove the '{}' from the fixture names and add the columns immediately
5
- # below each fixture, per the syntax in the comments below
6
- #
7
- one: {}
8
- # column: value
9
- #
10
- two: {}
11
- # column: value
@@ -1,11 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
-
3
- # This model initially had no columns defined. If you add columns to the
4
- # model remove the '{}' from the fixture names and add the columns immediately
5
- # below each fixture, per the syntax in the comments below
6
- #
7
- one: {}
8
- # column: value
9
- #
10
- two: {}
11
- # column: value
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class LargeTextFieldTest < ActiveSupport::TestCase
6
- test "truth" do
7
- assert_kind_of Module, LargeTextField
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuites>
3
- <testsuite name="LargeTextField::LibraryTest" filepath="/Users/tstarck/invoca/large_text_field/test/unit/dummy/library_test.rb" skipped="0" failures="0" errors="0" tests="2" assertions="2" time="0.00797699997201562">
4
- <testcase name="test_: LargeTextField::Library should be able to construct a library. " lineno="7" classname="LargeTextField::LibraryTest" assertions="2" time="0.005172000033780932">
5
- </testcase>
6
- <testcase name="test_: LargeTextField::Library should be able to dup a class that has no current large text field. " lineno="20" classname="LargeTextField::LibraryTest" assertions="0" time="0.002804999938234687">
7
- </testcase>
8
- </testsuite>
9
- </testsuites>
@@ -1,15 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuites>
3
- <testsuite name="LargeTextField::NamedTextValueTest" filepath="/Users/tstarck/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/shoulda-context-1.2.2/lib/shoulda/context/context.rb" skipped="0" failures="0" errors="0" tests="5" assertions="9" time="0.06121000007260591">
4
- <testcase name="test_: LargeTextField::NamedTextValue should belong to owner. " lineno="346" classname="LargeTextField::NamedTextValueTest" assertions="1" time="0.003751999931409955">
5
- </testcase>
6
- <testcase name="test_: LargeTextField::NamedTextValue should have field name and value attributes. " lineno="11" classname="LargeTextField::NamedTextValueTest" assertions="6" time="0.0427560000680387">
7
- </testcase>
8
- <testcase name="test_: LargeTextField::NamedTextValue should use large_text_fields as the table name. " lineno="7" classname="LargeTextField::NamedTextValueTest" assertions="1" time="0.0005510000046342611">
9
- </testcase>
10
- <testcase name="test_: unique index should allow different owners and field names. " lineno="36" classname="LargeTextField::NamedTextValueTest" assertions="0" time="0.009568999987095594">
11
- </testcase>
12
- <testcase name="test_: unique index should raise a unique constraint failure on the same owner, and field name. " lineno="27" classname="LargeTextField::NamedTextValueTest" assertions="1" time="0.004582000081427395">
13
- </testcase>
14
- </testsuite>
15
- </testsuites>
@@ -1,53 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuites>
3
- <testsuite name="LargeTextField::OwnerTest" filepath="/Users/tstarck/invoca/large_text_field/test/unit/large_text_field/owner_test.rb" skipped="0" failures="0" errors="0" tests="24" assertions="99" time="0.18328300002031028">
4
- <testcase name="test_: a large text field should allow a custom maximum length to be provided. " lineno="135" classname="LargeTextField::OwnerTest" assertions="3" time="0.013416999951004982">
5
- </testcase>
6
- <testcase name="test_: a large text field should allow a single argument to be passed into reload. " lineno="301" classname="LargeTextField::OwnerTest" assertions="1" time="0.004912999924272299">
7
- </testcase>
8
- <testcase name="test_: a large text field should allow for concurrent sets and deletes. " lineno="84" classname="LargeTextField::OwnerTest" assertions="9" time="0.007678000023588538">
9
- </testcase>
10
- <testcase name="test_: a large text field should allow get and set with saves and deletes. " lineno="61" classname="LargeTextField::OwnerTest" assertions="7" time="0.014948999974876642">
11
- </testcase>
12
- <testcase name="test_: a large text field should be able to be eager loaded. " lineno="244" classname="LargeTextField::OwnerTest" assertions="3" time="0.01591099996585399">
13
- </testcase>
14
- <testcase name="test_: a large text field should be able to update deleted fields. " lineno="194" classname="LargeTextField::OwnerTest" assertions="7" time="0.008474000031128526">
15
- </testcase>
16
- <testcase name="test_: a large text field should be cloned with the rest of the record. " lineno="218" classname="LargeTextField::OwnerTest" assertions="9" time="0.023695999989286065">
17
- </testcase>
18
- <testcase name="test_: a large text field should declare the association when it is first described and other meta data when it is first defined. " lineno="35" classname="LargeTextField::OwnerTest" assertions="3" time="0.0033099999418482184">
19
- </testcase>
20
- <testcase name="test_: a large text field should delete fields when they are set to blank. " lineno="173" classname="LargeTextField::OwnerTest" assertions="6" time="0.009033999987877905">
21
- </testcase>
22
- <testcase name="test_: a large text field should delete large text fields when the owner is destroyed. " lineno="305" classname="LargeTextField::OwnerTest" assertions="4" time="0.006717000040225685">
23
- </testcase>
24
- <testcase name="test_: a large text field should detect changes when @text_field_hash hash is/not empty. " lineno="268" classname="LargeTextField::OwnerTest" assertions="7" time="0.005818000063300133">
25
- </testcase>
26
- <testcase name="test_: a large text field should forget about changes if they are not saved. " lineno="109" classname="LargeTextField::OwnerTest" assertions="3" time="0.006125000072643161">
27
- </testcase>
28
- <testcase name="test_: a large text field should not save fields that are set to blank. " lineno="157" classname="LargeTextField::OwnerTest" assertions="5" time="0.007122000097297132">
29
- </testcase>
30
- <testcase name="test_: a large text field should only validate_large_text_fields if loaded. " lineno="285" classname="LargeTextField::OwnerTest" assertions="4" time="0.00335600005928427">
31
- </testcase>
32
- <testcase name="test_: a large text field should prevent a custom maximum length to be provided that is not in the allowable range. " lineno="147" classname="LargeTextField::OwnerTest" assertions="3" time="0.0030239999759942293">
33
- </testcase>
34
- <testcase name="test_: a large text field should prevent a non-Integer to be provided for a custom maximum. " lineno="141" classname="LargeTextField::OwnerTest" assertions="2" time="0.00317799998447299">
35
- </testcase>
36
- <testcase name="test_: a large text field should read from a file. " lineno="41" classname="LargeTextField::OwnerTest" assertions="3" time="0.01081999996677041">
37
- </testcase>
38
- <testcase name="test_: a large text field should reload changes when they come from a different model. " lineno="292" classname="LargeTextField::OwnerTest" assertions="2" time="0.007147000054828823">
39
- </testcase>
40
- <testcase name="test_: a large text field should singularize the errors if requested. " lineno="129" classname="LargeTextField::OwnerTest" assertions="3" time="0.00828499998897314">
41
- </testcase>
42
- <testcase name="test_: a large text field should support strings or symbols for get/set methods. " lineno="256" classname="LargeTextField::OwnerTest" assertions="7" time="0.002863000030629337">
43
- </testcase>
44
- <testcase name="test_: a large text field should validate the maximum length. " lineno="123" classname="LargeTextField::OwnerTest" assertions="3" time="0.007084999931976199">
45
- </testcase>
46
- <testcase name="test_: updating in large_text_field_save hook should be able to assign empty string. " lineno="9" classname="LargeTextField::OwnerTest" assertions="2" time="0.004567999974824488">
47
- </testcase>
48
- <testcase name="test_: updating in large_text_field_save hook should be able to assign non empty string. " lineno="9" classname="LargeTextField::OwnerTest" assertions="2" time="0.004910999909043312">
49
- </testcase>
50
- <testcase name="test_: updating in large_text_field_save hook should raise error on saving nil value. " lineno="19" classname="LargeTextField::OwnerTest" assertions="1" time="0.0008820000803098083">
51
- </testcase>
52
- </testsuite>
53
- </testsuites>
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuites>
3
- <testsuite name="LargeTextFieldTest" filepath="/Users/tstarck/invoca/large_text_field/test/large_text_field_test.rb" skipped="0" failures="0" errors="0" tests="1" assertions="1" time="0.00063699996098876">
4
- <testcase name="test_truth" lineno="6" classname="LargeTextFieldTest" assertions="1" time="0.00063699996098876">
5
- </testcase>
6
- </testsuite>
7
- </testsuites>
data/test/test_helper.rb DELETED
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ENV["RAILS_ENV"] = "test"
4
-
5
- require File.expand_path('dummy/config/environment.rb', __dir__)
6
- require "rails/test_help"
7
- require "rr"
8
- require "shoulda"
9
- require "minitest/unit"
10
- require 'minitest/reporters'
11
-
12
- junit_output_dir = ENV['JUNIT_OUTPUT'].presence || "test/reports"
13
- Minitest::Reporters.use! [
14
- Minitest::Reporters::DefaultReporter.new,
15
- Minitest::Reporters::JUnitReporter.new(junit_output_dir)
16
- ]
17
-
18
- require "pry"
19
-
20
- def large_description
21
- <<-EOF
22
- The Royal Library of Alexandria or Ancient Library of Alexandria in Alexandria, Egypt, was one of the
23
- largest and most significant libraries of the ancient world. It was dedicated to the Muses, the nine
24
- goddesses of the arts.[1] It flourished under the patronage of the Ptolemaic dynasty and functioned
25
- as a major center of scholarship from its construction in the 3rd century BCE until the Roman conquest
26
- of Egypt in 30 BCE, with collections of works, lecture halls, meeting rooms, and gardens. The library
27
- was part of a larger research institution called the Musaeum of Alexandria, where many of the most
28
- famous thinkers of the ancient world studied.
29
-
30
- The library was created by Ptolemy I Soter, who was a Macedonian general and the successor of Alexander
31
- the Great.[2] Most of the books were kept as papyrus scrolls. It is unknown how many such scrolls were
32
- housed at any given time.
33
-
34
- The library is famous for having been burned down, resulting in the loss of many scrolls and books; its
35
- destruction has become a symbol for the loss of cultural knowledge. A few sources differ on who is
36
- responsible for the destruction and when it occurred. There is mythology regarding this main burning
37
- but the library may in truth have suffered several fires or other acts of destruction over many years.
38
- Possible occasions for the partial or complete destruction of the Library of Alexandria include a fire
39
- set by Julius Caesar in 48 BCE and an attack by Aurelian in the CE 270s.
40
-
41
- After the main library was fully destroyed, ancient scholars used a "daughter library" in a temple known
42
- as the Serapeum, located in another part of the city. According to Socrates of Constantinople, Coptic Pope
43
- Theophilus destroyed the Serapeum in AD 391, although it's not certain that it still contained an offshoot
44
- of the library then.
45
- EOF
46
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module LargeTextField
6
- class LibraryTest < ActiveSupport::TestCase
7
- should "be able to construct a library" do
8
- l = Library.new(name: "Alexandria Public Library")
9
- l.save!
10
-
11
- l.description = large_description
12
- l.save!
13
-
14
- assert_equal large_description, l.description
15
-
16
- l = Library.find(l.id)
17
- assert_equal large_description, l.description
18
- end
19
-
20
- should "be able to dup a class that has no current large text field" do
21
- l = Library.new(name: "Alexandria Public Library")
22
- l.dup
23
- end
24
- end
25
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LargeTextField
4
- class NamedTextValueTest < ActiveSupport::TestCase
5
- should belong_to(:owner)
6
-
7
- should "use large_text_fields as the table name" do
8
- assert_equal "large_text_fields", LargeTextField::NamedTextValue.table_name
9
- end
10
-
11
- should "have field name and value attributes" do
12
- library = Library.create!(name: "Smithsonian")
13
- ntv = LargeTextField::NamedTextValue.new(field_name: "puppy", value: "Millie", owner: library)
14
- assert_equal "puppy", ntv.field_name
15
- assert_equal "Millie", ntv.value
16
- assert_equal "Smithsonian", ntv.owner.name
17
- ntv.save!
18
-
19
- # Attributes survive persistance
20
- ntv = LargeTextField::NamedTextValue.find(ntv.id)
21
- assert_equal "puppy", ntv.field_name
22
- assert_equal "Millie", ntv.value
23
- assert_equal "Smithsonian", ntv.owner.name
24
- end
25
-
26
- context "unique index" do
27
- should "raise a unique constraint failure on the same owner, and field name" do
28
- library = Library.create!(name: "Smithsonian")
29
- LargeTextField::NamedTextValue.create!(field_name: "puppy", value: "Millie", owner: library)
30
-
31
- assert_raise(ActiveRecord::RecordNotUnique) do
32
- LargeTextField::NamedTextValue.create!(field_name: "puppy", value: "Wiki", owner: library)
33
- end
34
- end
35
-
36
- should "allow different owners and field names" do
37
- library = Library.create!(name: "Smithsonian")
38
- library2 = Library.create!(name: "Alexandria")
39
- LargeTextField::NamedTextValue.create!(field_name: "puppy", value: "Millie", owner: library)
40
-
41
- # Different field name
42
- LargeTextField::NamedTextValue.create!(field_name: "dog", value: "Wiki", owner: library)
43
-
44
- # Different owner instance
45
- LargeTextField::NamedTextValue.create!(field_name: "puppy", value: "Millie", owner: library2)
46
- end
47
- end
48
- end
49
- end
@@ -1,317 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module LargeTextField
6
- class OwnerTest < ActiveSupport::TestCase
7
- context "updating in large_text_field_save hook" do
8
- { 'empty string' => '', 'non empty string' => 'this is some text' }.each do |name, value|
9
- should "be able to assign #{name}" do
10
- Library.default_notes = value
11
- @library = Library.create!(name: "Smithsonian")
12
- assert_equal value, @library.notes
13
- assert_equal value, @library.reload.notes
14
- ensure
15
- Library.default_notes = "none_set"
16
- end
17
- end
18
-
19
- should "raise error on saving nil value" do
20
- Library.default_notes = :nil
21
- assert_raises RuntimeError do
22
- @library = Library.create!(name: "Smithsonian")
23
- end
24
- ensure
25
- Library.default_notes = "none_set"
26
- end
27
- end
28
-
29
- context "a large text field" do
30
- setup do
31
- @library = Library.create!(name: "Smithsonian")
32
- assert_equal "", @library.description
33
- end
34
-
35
- should "declare the association when it is first described and other meta data when it is first defined" do
36
- assert_equal :has_many, Library.reflections['large_text_fields'].macro
37
-
38
- assert_equal({ maximum: nil, singularize_errors: true }, Library.large_text_field_options['description'])
39
- end
40
-
41
- should "read from a file" do
42
- @library = Library.create!(name: "Smithsonian")
43
- tmp_file = nil
44
- begin
45
- tmp_file = Tempfile.new('large_text_field_test')
46
- tmp_file.write("this is a string from the file")
47
- tmp_file.close
48
-
49
- test_file = File.open(tmp_file.path)
50
-
51
- @library.description = test_file
52
- assert_equal 'this is a string from the file', @library.description
53
-
54
- @library.save!
55
- assert_equal 'this is a string from the file', @library.reload.description
56
- ensure
57
- tmp_file.unlink
58
- end
59
- end
60
-
61
- should "allow get and set with saves and deletes" do
62
- @library.description = "badger " * 200
63
- assert_equal "badger " * 200, @library.description
64
-
65
- @library.save!
66
- @library.reload
67
- assert_equal "badger " * 200, @library.description
68
-
69
- @library.description = "mushroom " * 200
70
- assert_equal "mushroom " * 200, @library.description
71
-
72
- @library.save!
73
- @library.reload
74
- assert_equal "mushroom " * 200, @library.description
75
-
76
- @library.description = ''
77
- assert_equal '', @library.description
78
-
79
- @library.save!
80
- @library.reload
81
- assert_equal '', @library.description
82
- end
83
-
84
- should "allow for concurrent sets and deletes" do
85
- @library.description = "first"
86
- @library.catalog = "second"
87
-
88
- assert_equal "first", @library.description
89
- assert_equal "second", @library.catalog
90
-
91
- @library.save!
92
- @library.reload
93
-
94
- assert_equal "first", @library.description
95
- assert_equal "second", @library.catalog
96
-
97
- @library.description = "third"
98
- @library.catalog = ''
99
-
100
- assert_equal "third", @library.description
101
- assert_equal '', @library.catalog
102
-
103
- @library.save!
104
-
105
- assert_equal "third", @library.description
106
- assert_equal '', @library.catalog
107
- end
108
-
109
- should "forget about changes if they are not saved" do
110
- @library.description = "first"
111
- @library.reload
112
- assert_equal '', @library.description
113
-
114
- @library.description = "first"
115
- @library.save!
116
- @library.reload
117
-
118
- @library.description = ''
119
- @library.reload
120
- assert_equal "first", @library.description
121
- end
122
-
123
- should "validate the maximum length" do
124
- @library.notes = "a" * (LargeTextField::MAX_LENGTH + 1)
125
- assert !@library.valid?
126
- assert_equal(["Notes are too long (maximum is 5,000,000 characters)"], @library.errors.full_messages)
127
- end
128
-
129
- should "singularize the errors if requested" do
130
- @library.description = "a" * (LargeTextField::MAX_LENGTH + 1)
131
- assert !@library.valid?
132
- assert_equal(["Description is too long (maximum is 5,000,000 characters)"], @library.errors.full_messages)
133
- end
134
-
135
- should "allow a custom maximum length to be provided" do
136
- @library.catalog = "1" * 501
137
- assert_equal false, @library.valid?
138
- assert_equal ["Catalog is too long (maximum is 500 characters)"], @library.errors.full_messages
139
- end
140
-
141
- should "prevent a non-Integer to be provided for a custom maximum" do
142
- assert_raise(ArgumentError) do
143
- Library.large_text_field :not_number_maximum, maximum: "i am not a number"
144
- end
145
- end
146
-
147
- should "prevent a custom maximum length to be provided that is not in the allowable range" do
148
- assert_raise ArgumentError do
149
- Library.large_text_field :bigger_than_allowed, maximum: LargeTextField::MAX_LENGTH + 1
150
- end
151
-
152
- assert_raise ArgumentError do
153
- Library.large_text_field :smaller_than_allowed, maximum: -1
154
- end
155
- end
156
-
157
- should "not save fields that are set to blank" do
158
- @library = Library.new(name: 'Millie')
159
- assert_equal 0, @library.large_text_fields.count
160
-
161
- @library.description = "first"
162
- @library.notes = ""
163
-
164
- @library.save!
165
- @library.reload
166
-
167
- assert_equal "first", @library.description
168
- assert_equal "", @library.notes
169
-
170
- assert_equal 1, @library.large_text_fields.count
171
- end
172
-
173
- should "delete fields when they are set to blank" do
174
- assert_equal 0, @library.large_text_fields.count
175
-
176
- @library.description = "first"
177
-
178
- @library.save!
179
- @library.reload
180
-
181
- assert_equal "first", @library.description
182
-
183
- assert_equal 1, @library.large_text_fields.count
184
-
185
- @library.description = ""
186
- @library.save!
187
- @library.reload
188
-
189
- assert_equal "", @library.description
190
-
191
- assert_equal 0, @library.large_text_fields.count
192
- end
193
-
194
- should "be able to update deleted fields" do
195
- assert_equal 0, @library.large_text_fields.count
196
-
197
- @library.description = "first"
198
-
199
- @library.save!
200
-
201
- assert_equal "first", @library.description
202
-
203
- assert_equal 1, @library.large_text_fields.count
204
-
205
- @library.description = ""
206
- @library.save!
207
-
208
- assert_equal "", @library.description
209
-
210
- assert_equal 0, @library.large_text_fields.count
211
- @library.description = "first"
212
-
213
- @library.save!
214
-
215
- assert_equal "first", @library.description
216
- end
217
-
218
- should "be cloned with the rest of the record" do
219
- @library.description = "first"
220
- @library.catalog = "second"
221
- @library.save!
222
-
223
- @clone = @library.dup
224
- assert_equal "first", @clone.description
225
- assert_equal "second", @clone.catalog
226
- @clone.save!
227
-
228
- assert_equal "first", @clone.description
229
- assert_equal "second", @clone.catalog
230
-
231
- # Should not have stolen from the owner...
232
- @library.save!
233
- @library.reload
234
-
235
- assert_equal "first", @library.description
236
- assert_equal "second", @library.catalog
237
-
238
- # should be destroyed when destroyed
239
- text_field_ids = @clone.large_text_fields.*.id
240
- @clone.destroy
241
- text_field_ids.each { |id| assert !LargeTextField::NamedTextValue.find_by_id(id) }
242
- end
243
-
244
- should "be able to be eager loaded" do
245
- @library.description = "first"
246
- @library.catalog = "second"
247
- @library.save!
248
-
249
- new_value = Library.includes(:large_text_fields).find(@library.id)
250
-
251
- dont_allow(Library.connection).select
252
- assert_equal "first", new_value.description
253
- assert_equal "second", new_value.catalog
254
- end
255
-
256
- should "support strings or symbols for get/set methods" do
257
- @library.set_text_field(:description, "first")
258
- assert_equal "first", @library.description
259
- assert_equal "first", @library.get_text_field(:description)
260
- assert_equal "first", @library.get_text_field('description')
261
-
262
- @library.set_text_field('description', "second")
263
- assert_equal "second", @library.description
264
- assert_equal "second", @library.get_text_field(:description)
265
- assert_equal "second", @library.get_text_field('description')
266
- end
267
-
268
- should "detect changes when @text_field_hash hash is/not empty" do
269
- @library = Library.new(name: "Smithsonian")
270
-
271
- assert !@library.instance_variable_defined?("@text_field_hash")
272
- assert !@library.description_changed?
273
- @library.description = "a new note"
274
- assert @library.description_changed?
275
- @library.save!
276
- @library.reload
277
-
278
- assert !@library.description_changed?
279
- @library.description = "a new note"
280
- assert !@library.description_changed?
281
- @library.description = "now with more chicken taste"
282
- assert @library.description_changed?
283
- end
284
-
285
- should "only validate_large_text_fields if loaded" do
286
- @library = Library.new
287
- assert !@library.instance_variable_defined?("@text_field_hash")
288
- assert @library.valid?
289
- assert !@library.instance_variable_defined?("@text_field_hash")
290
- end
291
-
292
- should "reload changes when they come from a different model" do
293
- @library = Library.create!(name: "Cambridge University Library", description: "in england")
294
- @second_version = Library.find(@library.id)
295
-
296
- @second_version.update_attributes!(description: "The main research library of the University of Cambridge in England")
297
-
298
- assert_equal "The main research library of the University of Cambridge in England", @library.reload.description
299
- end
300
-
301
- should "allow a single argument to be passed into reload" do
302
- Library.create!(name: "Cambridge University Library", description: "in england").reload(lock: true)
303
- end
304
-
305
- should "delete large text fields when the owner is destroyed" do
306
- assert_equal 0, LargeTextField::NamedTextValue.count
307
-
308
- @library = Library.create!(name: "Cambridge University Library", description: "in england")
309
- assert_equal 1, LargeTextField::NamedTextValue.count
310
-
311
- @library.destroy
312
- assert_equal 0, LargeTextField::NamedTextValue.count
313
- end
314
- end
315
-
316
- end
317
- end