paper_trail 4.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +28 -9
  3. data/.github/ISSUE_TEMPLATE.md +13 -0
  4. data/.gitignore +2 -1
  5. data/.rubocop.yml +100 -0
  6. data/.rubocop_todo.yml +14 -0
  7. data/.travis.yml +8 -9
  8. data/Appraisals +41 -0
  9. data/CHANGELOG.md +49 -9
  10. data/Gemfile +1 -1
  11. data/README.md +130 -109
  12. data/Rakefile +19 -19
  13. data/doc/bug_report_template.rb +20 -14
  14. data/gemfiles/ar3.gemfile +10 -53
  15. data/gemfiles/ar4.gemfile +7 -0
  16. data/gemfiles/ar5.gemfile +13 -0
  17. data/lib/generators/paper_trail/install_generator.rb +26 -18
  18. data/lib/generators/paper_trail/templates/add_object_changes_to_versions.rb +4 -2
  19. data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +2 -0
  20. data/lib/generators/paper_trail/templates/create_version_associations.rb +9 -4
  21. data/lib/generators/paper_trail/templates/create_versions.rb +39 -5
  22. data/lib/paper_trail.rb +169 -146
  23. data/lib/paper_trail/attributes_serialization.rb +89 -17
  24. data/lib/paper_trail/cleaner.rb +15 -9
  25. data/lib/paper_trail/config.rb +28 -11
  26. data/lib/paper_trail/frameworks/active_record.rb +4 -0
  27. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb +5 -1
  28. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +6 -2
  29. data/lib/paper_trail/frameworks/cucumber.rb +1 -0
  30. data/lib/paper_trail/frameworks/rails.rb +2 -7
  31. data/lib/paper_trail/frameworks/rails/controller.rb +29 -9
  32. data/lib/paper_trail/frameworks/rails/engine.rb +7 -1
  33. data/lib/paper_trail/frameworks/rspec.rb +5 -5
  34. data/lib/paper_trail/frameworks/rspec/helpers.rb +3 -1
  35. data/lib/paper_trail/frameworks/sinatra.rb +6 -4
  36. data/lib/paper_trail/has_paper_trail.rb +199 -106
  37. data/lib/paper_trail/record_history.rb +1 -3
  38. data/lib/paper_trail/reifier.rb +297 -118
  39. data/lib/paper_trail/serializers/json.rb +3 -3
  40. data/lib/paper_trail/serializers/yaml.rb +27 -8
  41. data/lib/paper_trail/version_association_concern.rb +3 -1
  42. data/lib/paper_trail/version_concern.rb +75 -35
  43. data/lib/paper_trail/version_number.rb +6 -9
  44. data/paper_trail.gemspec +44 -51
  45. data/spec/generators/install_generator_spec.rb +24 -25
  46. data/spec/generators/paper_trail/templates/create_versions_spec.rb +51 -0
  47. data/spec/models/animal_spec.rb +12 -12
  48. data/spec/models/boolit_spec.rb +8 -8
  49. data/spec/models/callback_modifier_spec.rb +47 -47
  50. data/spec/models/car_spec.rb +13 -0
  51. data/spec/models/fluxor_spec.rb +3 -3
  52. data/spec/models/gadget_spec.rb +19 -19
  53. data/spec/models/joined_version_spec.rb +3 -3
  54. data/spec/models/json_version_spec.rb +23 -24
  55. data/spec/models/kitchen/banana_spec.rb +3 -3
  56. data/spec/models/not_on_update_spec.rb +7 -4
  57. data/spec/models/post_with_status_spec.rb +13 -3
  58. data/spec/models/skipper_spec.rb +10 -10
  59. data/spec/models/thing_spec.rb +4 -4
  60. data/spec/models/truck_spec.rb +5 -0
  61. data/spec/models/vehicle_spec.rb +5 -0
  62. data/spec/models/version_spec.rb +103 -59
  63. data/spec/models/widget_spec.rb +82 -52
  64. data/spec/modules/paper_trail_spec.rb +2 -2
  65. data/spec/modules/version_concern_spec.rb +11 -12
  66. data/spec/modules/version_number_spec.rb +2 -4
  67. data/spec/paper_trail/config_spec.rb +10 -29
  68. data/spec/paper_trail_spec.rb +16 -14
  69. data/spec/rails_helper.rb +10 -9
  70. data/spec/requests/articles_spec.rb +11 -7
  71. data/spec/spec_helper.rb +41 -22
  72. data/spec/support/alt_db_init.rb +8 -13
  73. data/test/custom_json_serializer.rb +3 -3
  74. data/test/dummy/Rakefile +2 -2
  75. data/test/dummy/app/controllers/application_controller.rb +21 -8
  76. data/test/dummy/app/controllers/articles_controller.rb +11 -8
  77. data/test/dummy/app/controllers/widgets_controller.rb +13 -12
  78. data/test/dummy/app/models/animal.rb +1 -1
  79. data/test/dummy/app/models/article.rb +19 -11
  80. data/test/dummy/app/models/authorship.rb +1 -1
  81. data/test/dummy/app/models/bar_habtm.rb +4 -0
  82. data/test/dummy/app/models/book.rb +4 -4
  83. data/test/dummy/app/models/boolit.rb +1 -1
  84. data/test/dummy/app/models/callback_modifier.rb +6 -6
  85. data/test/dummy/app/models/car.rb +3 -0
  86. data/test/dummy/app/models/chapter.rb +4 -4
  87. data/test/dummy/app/models/customer.rb +1 -1
  88. data/test/dummy/app/models/document.rb +2 -2
  89. data/test/dummy/app/models/editor.rb +1 -1
  90. data/test/dummy/app/models/foo_habtm.rb +4 -0
  91. data/test/dummy/app/models/fruit.rb +2 -2
  92. data/test/dummy/app/models/gadget.rb +1 -1
  93. data/test/dummy/app/models/kitchen/banana.rb +1 -1
  94. data/test/dummy/app/models/legacy_widget.rb +2 -2
  95. data/test/dummy/app/models/line_item.rb +1 -1
  96. data/test/dummy/app/models/not_on_update.rb +1 -1
  97. data/test/dummy/app/models/person.rb +6 -6
  98. data/test/dummy/app/models/post.rb +1 -1
  99. data/test/dummy/app/models/post_with_status.rb +1 -1
  100. data/test/dummy/app/models/quotation.rb +1 -1
  101. data/test/dummy/app/models/section.rb +1 -1
  102. data/test/dummy/app/models/skipper.rb +2 -2
  103. data/test/dummy/app/models/song.rb +13 -4
  104. data/test/dummy/app/models/thing.rb +2 -2
  105. data/test/dummy/app/models/translation.rb +2 -2
  106. data/test/dummy/app/models/truck.rb +4 -0
  107. data/test/dummy/app/models/vehicle.rb +4 -0
  108. data/test/dummy/app/models/whatchamajigger.rb +1 -1
  109. data/test/dummy/app/models/widget.rb +7 -6
  110. data/test/dummy/app/versions/joined_version.rb +4 -3
  111. data/test/dummy/app/versions/json_version.rb +1 -1
  112. data/test/dummy/app/versions/kitchen/banana_version.rb +1 -1
  113. data/test/dummy/app/versions/post_version.rb +2 -2
  114. data/test/dummy/config.ru +1 -1
  115. data/test/dummy/config/application.rb +20 -9
  116. data/test/dummy/config/boot.rb +5 -5
  117. data/test/dummy/config/environment.rb +1 -1
  118. data/test/dummy/config/environments/development.rb +4 -3
  119. data/test/dummy/config/environments/production.rb +3 -2
  120. data/test/dummy/config/environments/test.rb +15 -5
  121. data/test/dummy/config/initializers/backtrace_silencers.rb +4 -2
  122. data/test/dummy/config/initializers/paper_trail.rb +1 -2
  123. data/test/dummy/config/initializers/secret_token.rb +3 -1
  124. data/test/dummy/config/initializers/session_store.rb +1 -1
  125. data/test/dummy/config/routes.rb +2 -2
  126. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +120 -74
  127. data/test/dummy/db/schema.rb +29 -6
  128. data/test/dummy/script/rails +6 -4
  129. data/test/functional/controller_test.rb +34 -35
  130. data/test/functional/enabled_for_controller_test.rb +6 -7
  131. data/test/functional/modular_sinatra_test.rb +43 -38
  132. data/test/functional/sinatra_test.rb +49 -40
  133. data/test/functional/thread_safety_test.rb +4 -6
  134. data/test/paper_trail_test.rb +15 -14
  135. data/test/test_helper.rb +68 -44
  136. data/test/time_travel_helper.rb +1 -15
  137. data/test/unit/associations_test.rb +517 -251
  138. data/test/unit/cleaner_test.rb +66 -60
  139. data/test/unit/inheritance_column_test.rb +17 -17
  140. data/test/unit/model_test.rb +611 -504
  141. data/test/unit/protected_attrs_test.rb +16 -12
  142. data/test/unit/serializer_test.rb +44 -43
  143. data/test/unit/serializers/json_test.rb +17 -18
  144. data/test/unit/serializers/mixin_json_test.rb +15 -14
  145. data/test/unit/serializers/mixin_yaml_test.rb +20 -16
  146. data/test/unit/serializers/yaml_test.rb +12 -13
  147. data/test/unit/timestamp_test.rb +10 -12
  148. data/test/unit/version_test.rb +7 -7
  149. metadata +92 -40
@@ -1,47 +1,51 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class ProtectedAttrsTest < ActiveSupport::TestCase
4
4
  subject { ProtectedWidget.new }
5
5
 
6
- if ActiveRecord::VERSION::MAJOR < 4 # these ActiveModel matchers (provided by shoulda-matchers) only work for Rails 3
6
+ # These ActiveModel matchers (provided by shoulda-matchers) only work for
7
+ # Rails 3.
8
+ if ActiveRecord::VERSION::MAJOR < 4
7
9
  accessible_attrs = ProtectedWidget.accessible_attributes.to_a
8
10
  accessible_attrs.each do |attr_name|
9
11
  should allow_mass_assignment_of(attr_name.to_sym)
10
12
  end
11
- ProtectedWidget.column_names.reject { |column_name| accessible_attrs.include?(column_name) }.each do |attr_name|
13
+ inaccessible = ProtectedWidget.
14
+ column_names.
15
+ reject { |column_name| accessible_attrs.include?(column_name) }
16
+ inaccessible.each do |attr_name|
12
17
  should_not allow_mass_assignment_of(attr_name.to_sym)
13
18
  end
14
19
  end
15
20
 
16
- context 'A model with `attr_accessible` created' do
21
+ context "A model with `attr_accessible` created" do
17
22
  setup do
18
- @widget = ProtectedWidget.create! :name => 'Henry'
23
+ @widget = ProtectedWidget.create! name: "Henry"
19
24
  @initial_attributes = @widget.attributes
20
25
  end
21
26
 
22
- should 'be `nil` in its previous version' do
27
+ should "be `nil` in its previous version" do
23
28
  assert_nil @widget.previous_version
24
29
  end
25
30
 
26
- context 'which is then updated' do
31
+ context "which is then updated" do
27
32
  setup do
28
- @widget.assign_attributes(:name => 'Jeff', :a_text => 'Short statement')
33
+ @widget.assign_attributes(name: "Jeff", a_text: "Short statement")
29
34
  @widget.an_integer = 42
30
35
  @widget.save!
31
36
  end
32
37
 
33
- should 'not be `nil` in its previous version' do
38
+ should "not be `nil` in its previous version" do
34
39
  assert_not_nil @widget.previous_version
35
40
  end
36
41
 
37
- should 'the previous version should contain right attributes' do
42
+ should "the previous version should contain right attributes" do
38
43
  # For some reason this test seems to be broken in JRuby 1.9 mode in the
39
44
  # test env even though it works in the console. WTF?
40
- unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION) && RUBY_VERSION >= '1.9'
45
+ unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION)
41
46
  assert_attributes_equal @widget.previous_version.attributes, @initial_attributes
42
47
  end
43
48
  end
44
49
  end
45
-
46
50
  end
47
51
  end
@@ -1,36 +1,34 @@
1
- require 'test_helper'
2
- require 'custom_json_serializer'
1
+ require "test_helper"
2
+ require "custom_json_serializer"
3
3
 
4
4
  class SerializerTest < ActiveSupport::TestCase
5
-
6
- context 'YAML Serializer' do
5
+ context "YAML Serializer" do
7
6
  setup do
8
7
  Fluxor.instance_eval <<-END
9
8
  has_paper_trail
10
9
  END
11
10
 
12
- @fluxor = Fluxor.create :name => 'Some text.'
13
- @original_fluxor_attributes = @fluxor.send(:attributes_before_change) # this is exactly what PaperTrail serializes
14
- @fluxor.update_attributes :name => 'Some more text.'
11
+ @fluxor = Fluxor.create name: "Some text."
12
+
13
+ # this is exactly what PaperTrail serializes
14
+ @original_fluxor_attributes = @fluxor.send(:attributes_before_change)
15
+
16
+ @fluxor.update_attributes name: "Some more text."
15
17
  end
16
18
 
17
- should 'work with the default `YAML` serializer' do
19
+ should "work with the default `YAML` serializer" do
18
20
  # Normal behaviour
19
21
  assert_equal 2, @fluxor.versions.length
20
22
  assert_nil @fluxor.versions[0].reify
21
- assert_equal 'Some text.', @fluxor.versions[1].reify.name
23
+ assert_equal "Some text.", @fluxor.versions[1].reify.name
22
24
 
23
25
  # Check values are stored as `YAML`.
24
26
  assert_equal @original_fluxor_attributes, YAML.load(@fluxor.versions[1].object)
25
- # This test can't consistently pass in Ruby1.8 because hashes do no preserve order, which means the order of the
26
- # attributes in the `YAML` can't be ensured.
27
- if RUBY_VERSION >= '1.9'
28
- assert_equal YAML.dump(@original_fluxor_attributes), @fluxor.versions[1].object
29
- end
27
+ assert_equal YAML.dump(@original_fluxor_attributes), @fluxor.versions[1].object
30
28
  end
31
29
  end
32
30
 
33
- context 'JSON Serializer' do
31
+ context "JSON Serializer" do
34
32
  setup do
35
33
  PaperTrail.configure do |config|
36
34
  config.serializer = PaperTrail::Serializers::JSON
@@ -40,39 +38,40 @@ class SerializerTest < ActiveSupport::TestCase
40
38
  has_paper_trail
41
39
  END
42
40
 
43
- @fluxor = Fluxor.create :name => 'Some text.'
44
- @original_fluxor_attributes = @fluxor.send(:attributes_before_change) # this is exactly what PaperTrail serializes
45
- @fluxor.update_attributes :name => 'Some more text.'
41
+ @fluxor = Fluxor.create name: "Some text."
42
+
43
+ # this is exactly what PaperTrail serializes
44
+ @original_fluxor_attributes = @fluxor.send(:attributes_before_change)
45
+
46
+ @fluxor.update_attributes name: "Some more text."
46
47
  end
47
48
 
48
49
  teardown do
49
50
  PaperTrail.config.serializer = PaperTrail::Serializers::YAML
50
51
  end
51
52
 
52
- should 'reify with JSON serializer' do
53
+ should "reify with JSON serializer" do
53
54
  # Normal behaviour
54
55
  assert_equal 2, @fluxor.versions.length
55
56
  assert_nil @fluxor.versions[0].reify
56
- assert_equal 'Some text.', @fluxor.versions[1].reify.name
57
+ assert_equal "Some text.", @fluxor.versions[1].reify.name
57
58
 
58
59
  # Check values are stored as JSON.
59
- assert_equal @original_fluxor_attributes, ActiveSupport::JSON.decode(@fluxor.versions[1].object)
60
- # This test can't consistently pass in Ruby1.8 because hashes do no preserve order, which means the order of the
61
- # attributes in the JSON can't be ensured.
62
- if RUBY_VERSION >= '1.9'
63
- assert_equal ActiveSupport::JSON.encode(@original_fluxor_attributes), @fluxor.versions[1].object
64
- end
60
+ assert_equal @original_fluxor_attributes,
61
+ ActiveSupport::JSON.decode(@fluxor.versions[1].object)
62
+ assert_equal ActiveSupport::JSON.encode(@original_fluxor_attributes),
63
+ @fluxor.versions[1].object
65
64
  end
66
65
 
67
- should 'store object_changes' do
68
- initial_changeset = {"name" => [nil, "Some text."], "id" => [nil, @fluxor.id]}
69
- second_changeset = {"name"=>["Some text.", "Some more text."]}
66
+ should "store object_changes" do
67
+ initial_changeset = { "name" => [nil, "Some text."], "id" => [nil, @fluxor.id] }
68
+ second_changeset = { "name" => ["Some text.", "Some more text."] }
70
69
  assert_equal initial_changeset, @fluxor.versions[0].changeset
71
70
  assert_equal second_changeset, @fluxor.versions[1].changeset
72
71
  end
73
72
  end
74
73
 
75
- context 'Custom Serializer' do
74
+ context "Custom Serializer" do
76
75
  setup do
77
76
  PaperTrail.configure do |config|
78
77
  config.serializer = CustomJsonSerializer
@@ -83,35 +82,37 @@ class SerializerTest < ActiveSupport::TestCase
83
82
  END
84
83
 
85
84
  @fluxor = Fluxor.create
86
- @original_fluxor_attributes = @fluxor.send(:attributes_before_change).reject { |k,v| v.nil? } # this is exactly what PaperTrail serializes
87
- @fluxor.update_attributes :name => 'Some more text.'
85
+
86
+ # this is exactly what PaperTrail serializes
87
+ @original_fluxor_attributes = @fluxor.
88
+ send(:attributes_before_change).
89
+ reject { |_k, v| v.nil? }
90
+
91
+ @fluxor.update_attributes name: "Some more text."
88
92
  end
89
93
 
90
94
  teardown do
91
95
  PaperTrail.config.serializer = PaperTrail::Serializers::YAML
92
96
  end
93
97
 
94
- should 'reify with custom serializer' do
98
+ should "reify with custom serializer" do
95
99
  # Normal behaviour
96
100
  assert_equal 2, @fluxor.versions.length
97
101
  assert_nil @fluxor.versions[0].reify
98
102
  assert_nil @fluxor.versions[1].reify.name
99
103
 
100
104
  # Check values are stored as JSON.
101
- assert_equal @original_fluxor_attributes, ActiveSupport::JSON.decode(@fluxor.versions[1].object)
102
- # This test can't consistently pass in Ruby1.8 because hashes do no preserve order, which means the order of the
103
- # attributes in the JSON can't be ensured.
104
- if RUBY_VERSION >= '1.9'
105
- assert_equal ActiveSupport::JSON.encode(@original_fluxor_attributes), @fluxor.versions[1].object
106
- end
105
+ assert_equal @original_fluxor_attributes,
106
+ ActiveSupport::JSON.decode(@fluxor.versions[1].object)
107
+ assert_equal ActiveSupport::JSON.encode(@original_fluxor_attributes),
108
+ @fluxor.versions[1].object
107
109
  end
108
110
 
109
- should 'store object_changes' do
110
- initial_changeset = {"id" => [nil, @fluxor.id]}
111
- second_changeset = {"name"=>[nil, "Some more text."]}
111
+ should "store object_changes" do
112
+ initial_changeset = { "id" => [nil, @fluxor.id] }
113
+ second_changeset = { "name" => [nil, "Some more text."] }
112
114
  assert_equal initial_changeset, @fluxor.versions[0].changeset
113
115
  assert_equal second_changeset, @fluxor.versions[1].changeset
114
116
  end
115
117
  end
116
-
117
118
  end
@@ -1,50 +1,49 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class JSONTest < ActiveSupport::TestCase
4
-
5
4
  setup do
6
5
  # Setup a hash with random values
7
6
  @hash = {}
8
7
  (1..4).each do |i|
9
- @hash["key#{i}"] = Faker::Lorem.word
8
+ @hash["key#{i}"] = FFaker::Lorem.word
10
9
  end
11
10
  @hash_as_json = @hash.to_json
12
11
  # Setup an array of random words
13
12
  @array = []
14
- (rand(5) + 4).times { @array << Faker::Lorem.word }
13
+ (rand(5) + 4).times { @array << FFaker::Lorem.word }
15
14
  @array_as_json = @array.to_json
16
15
  end
17
16
 
18
- context '`load` class method' do
19
- should 'exist' do
17
+ context "`load` class method" do
18
+ should "exist" do
20
19
  assert PaperTrail::Serializers::JSON.respond_to?(:load)
21
20
  end
22
21
 
23
- should '`deserialize` JSON to Ruby' do
22
+ should "`deserialize` JSON to Ruby" do
24
23
  assert_equal @hash, PaperTrail::Serializers::JSON.load(@hash_as_json)
25
24
  assert_equal @array, PaperTrail::Serializers::JSON.load(@array_as_json)
26
25
  end
27
26
  end
28
27
 
29
- context '`dump` class method' do
30
- should 'exist' do
28
+ context "`dump` class method" do
29
+ should "exist" do
31
30
  assert PaperTrail::Serializers::JSON.respond_to?(:dump)
32
31
  end
33
32
 
34
- should '`serialize` Ruby to JSON' do
33
+ should "`serialize` Ruby to JSON" do
35
34
  assert_equal @hash_as_json, PaperTrail::Serializers::JSON.dump(@hash)
36
35
  assert_equal @array_as_json, PaperTrail::Serializers::JSON.dump(@array)
37
36
  end
38
37
  end
39
38
 
40
- context '`where_object` class method' do
39
+ context "`where_object` class method" do
41
40
  context "when value is a string" do
42
- should 'construct correct WHERE query' do
41
+ should "construct correct WHERE query" do
43
42
  matches = PaperTrail::Serializers::JSON.where_object_condition(
44
43
  PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
45
44
 
46
45
  assert matches.instance_of?(Arel::Nodes::Matches)
47
- if Arel::VERSION >= '6'
46
+ if Arel::VERSION >= "6"
48
47
  assert_equal matches.right.val, "%\"arg1\":\"Val 1\"%"
49
48
  else
50
49
  assert_equal matches.right, "%\"arg1\":\"Val 1\"%"
@@ -53,12 +52,12 @@ class JSONTest < ActiveSupport::TestCase
53
52
  end
54
53
 
55
54
  context "when value is `null`" do
56
- should 'construct correct WHERE query' do
55
+ should "construct correct WHERE query" do
57
56
  matches = PaperTrail::Serializers::JSON.where_object_condition(
58
57
  PaperTrail::Version.arel_table[:object], :arg1, nil)
59
58
 
60
59
  assert matches.instance_of?(Arel::Nodes::Matches)
61
- if Arel::VERSION >= '6'
60
+ if Arel::VERSION >= "6"
62
61
  assert_equal matches.right.val, "%\"arg1\":null%"
63
62
  else
64
63
  assert_equal matches.right, "%\"arg1\":null%"
@@ -67,15 +66,15 @@ class JSONTest < ActiveSupport::TestCase
67
66
  end
68
67
 
69
68
  context "when value is a number" do
70
- should 'construct correct WHERE query' do
69
+ should "construct correct WHERE query" do
71
70
  grouping = PaperTrail::Serializers::JSON.where_object_condition(
72
71
  PaperTrail::Version.arel_table[:object], :arg1, -3.5)
73
72
 
74
73
  assert grouping.instance_of?(Arel::Nodes::Grouping)
75
74
  matches = grouping.select { |v| v.instance_of?(Arel::Nodes::Matches) }
76
- # Numeric arguments need to ensure that they match for only the number, not the beginning
75
+ # Numeric arguments need to ensure that they match for only the number, not the beginning
77
76
  # of a #, so it uses an Grouping matcher (See notes on `PaperTrail::Serializers::JSON`)
78
- if Arel::VERSION >= '6'
77
+ if Arel::VERSION >= "6"
79
78
  assert_equal matches.first.right.val, "%\"arg1\":-3.5,%"
80
79
  assert_equal matches.last.right.val, "%\"arg1\":-3.5}%"
81
80
  else
@@ -1,36 +1,37 @@
1
- require 'test_helper'
2
- require 'custom_json_serializer'
1
+ require "test_helper"
2
+ require "custom_json_serializer"
3
3
 
4
4
  class MixinJsonTest < ActiveSupport::TestCase
5
-
6
5
  setup do
7
6
  # Setup a hash with random values, ensuring some values are nil
8
7
  @hash = {}
9
8
  (1..4).each do |i|
10
- @hash["key#{i}"] = [Faker::Lorem.word, nil].sample
9
+ @hash["key#{i}"] = [FFaker::Lorem.word, nil].sample
11
10
  end
12
- @hash['tkey'] = nil
13
- @hash[''] = 'foo'
11
+ @hash["tkey"] = nil
12
+ @hash[""] = "foo"
14
13
  @hash_as_json = @hash.to_json
15
14
  end
16
15
 
17
- context '`load` class method' do
18
- should 'exist' do
16
+ context "`load` class method" do
17
+ should "exist" do
19
18
  assert CustomJsonSerializer.respond_to?(:load)
20
19
  end
21
20
 
22
- should '`deserialize` JSON to Ruby, removing pairs with `blank` keys or values' do
23
- assert_equal @hash.reject { |k,v| k.blank? || v.blank? }, CustomJsonSerializer.load(@hash_as_json)
21
+ should "`deserialize` JSON to Ruby, removing pairs with `blank` keys or values" do
22
+ assert_equal @hash.reject { |k, v| k.blank? || v.blank? },
23
+ CustomJsonSerializer.load(@hash_as_json)
24
24
  end
25
25
  end
26
26
 
27
- context '`dump` class method' do
28
- should 'exist' do
27
+ context "`dump` class method" do
28
+ should "exist" do
29
29
  assert CustomJsonSerializer.respond_to?(:dump)
30
30
  end
31
31
 
32
- should '`serialize` Ruby to JSON, removing pairs with `nil` values' do
33
- assert_equal @hash.reject { |k,v| v.nil? }.to_json, CustomJsonSerializer.dump(@hash)
32
+ should "`serialize` Ruby to JSON, removing pairs with `nil` values" do
33
+ assert_equal @hash.reject { |_k, v| v.nil? }.to_json,
34
+ CustomJsonSerializer.dump(@hash)
34
35
  end
35
36
  end
36
37
  end
@@ -1,49 +1,53 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  module CustomYamlSerializer
4
4
  extend PaperTrail::Serializers::YAML
5
5
 
6
6
  def self.load(string)
7
7
  parsed_value = super(string)
8
- parsed_value.is_a?(Hash) ? parsed_value.reject { |k,v| k.blank? || v.blank? } : parsed_value
8
+ if parsed_value.is_a?(Hash)
9
+ parsed_value.reject { |k, v| k.blank? || v.blank? }
10
+ else
11
+ parsed_value
12
+ end
9
13
  end
10
14
 
11
15
  def self.dump(object)
12
- object.is_a?(Hash) ? super(object.reject { |k,v| v.nil? }) : super
16
+ object.is_a?(Hash) ? super(object.reject { |_k, v| v.nil? }) : super
13
17
  end
14
18
  end
15
19
 
16
20
  class MixinYamlTest < ActiveSupport::TestCase
17
-
18
21
  setup do
19
22
  # Setup a hash with random values, ensuring some values are nil
20
23
  @hash = {}
21
24
  (1..4).each do |i|
22
- @hash["key#{i}"] = [Faker::Lorem.word, nil].sample
25
+ @hash["key#{i}"] = [FFaker::Lorem.word, nil].sample
23
26
  end
24
- @hash['tkey'] = nil
25
- @hash[''] = 'foo'
27
+ @hash["tkey"] = nil
28
+ @hash[""] = "foo"
26
29
  @hash_as_yaml = @hash.to_yaml
27
30
  end
28
31
 
29
- context '`load` class method' do
30
- should 'exist' do
32
+ context "`load` class method" do
33
+ should "exist" do
31
34
  assert CustomYamlSerializer.respond_to?(:load)
32
35
  end
33
36
 
34
- should '`deserialize` YAML to Ruby, removing pairs with `blank` keys or values' do
35
- assert_equal @hash.reject { |k,v| k.blank? || v.blank? }, CustomYamlSerializer.load(@hash_as_yaml)
37
+ should "`deserialize` YAML to Ruby, removing pairs with `blank` keys or values" do
38
+ assert_equal @hash.reject { |k, v| k.blank? || v.blank? },
39
+ CustomYamlSerializer.load(@hash_as_yaml)
36
40
  end
37
41
  end
38
42
 
39
- context '`dump` class method' do
40
- should 'exist' do
43
+ context "`dump` class method" do
44
+ should "exist" do
41
45
  assert CustomYamlSerializer.respond_to?(:dump)
42
46
  end
43
47
 
44
- should '`serialize` Ruby to YAML, removing pairs with `nil` values' do
45
- assert_equal @hash.reject { |k,v| v.nil? }.to_yaml, CustomYamlSerializer.dump(@hash)
48
+ should "`serialize` Ruby to YAML, removing pairs with `nil` values" do
49
+ assert_equal @hash.reject { |_k, v| v.nil? }.to_yaml,
50
+ CustomYamlSerializer.dump(@hash)
46
51
  end
47
52
  end
48
-
49
53
  end
@@ -1,48 +1,47 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  class YamlTest < ActiveSupport::TestCase
4
-
5
4
  setup do
6
5
  # Setup a hash with random values
7
6
  @hash = {}
8
7
  (1..4).each do |i|
9
- @hash["key#{i}".to_sym] = Faker::Lorem.word
8
+ @hash["key#{i}".to_sym] = FFaker::Lorem.word
10
9
  end
11
10
  @hash_as_yaml = @hash.to_yaml
12
11
  # Setup an array of random words
13
12
  @array = []
14
- (rand(5) + 4).times { @array << Faker::Lorem.word }
13
+ (rand(5) + 4).times { @array << FFaker::Lorem.word }
15
14
  @array_as_yaml = @array.to_yaml
16
15
  end
17
16
 
18
- context '`load` class method' do
19
- should 'exist' do
17
+ context "`load` class method" do
18
+ should "exist" do
20
19
  assert PaperTrail::Serializers::YAML.respond_to?(:load)
21
20
  end
22
21
 
23
- should 'deserialize `YAML` to Ruby' do
22
+ should "deserialize `YAML` to Ruby" do
24
23
  assert_equal @hash, PaperTrail::Serializers::YAML.load(@hash_as_yaml)
25
24
  assert_equal @array, PaperTrail::Serializers::YAML.load(@array_as_yaml)
26
25
  end
27
26
  end
28
27
 
29
- context '`dump` class method' do
30
- should 'exist' do
28
+ context "`dump` class method" do
29
+ should "exist" do
31
30
  assert PaperTrail::Serializers::YAML.respond_to?(:dump)
32
31
  end
33
32
 
34
- should 'serialize Ruby to `YAML`' do
33
+ should "serialize Ruby to `YAML`" do
35
34
  assert_equal @hash_as_yaml, PaperTrail::Serializers::YAML.dump(@hash)
36
35
  assert_equal @array_as_yaml, PaperTrail::Serializers::YAML.dump(@array)
37
36
  end
38
37
  end
39
38
 
40
- context '`where_object` class method' do
41
- should 'construct correct WHERE query' do
39
+ context "`where_object` class method" do
40
+ should "construct correct WHERE query" do
42
41
  matches = PaperTrail::Serializers::YAML.where_object_condition(
43
42
  PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
44
43
  assert matches.instance_of?(Arel::Nodes::Matches)
45
- if Arel::VERSION >= '6'
44
+ if Arel::VERSION >= "6"
46
45
  assert_equal matches.right.val, "%\narg1: Val 1\n%"
47
46
  else
48
47
  assert_equal matches.right, "%\narg1: Val 1\n%"