granite-form 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -2
  3. data/.github/workflows/{ci.yml → ruby.yml} +22 -4
  4. data/.rubocop.yml +1 -1
  5. data/.rubocop_todo.yml +3 -3
  6. data/Appraisals +1 -2
  7. data/CHANGELOG.md +15 -0
  8. data/README.md +6 -15
  9. data/docker-compose.yml +14 -0
  10. data/gemfiles/rails.5.0.gemfile +0 -1
  11. data/gemfiles/rails.5.1.gemfile +0 -1
  12. data/gemfiles/rails.5.2.gemfile +0 -1
  13. data/granite-form.gemspec +15 -15
  14. data/lib/granite/form/active_record/associations.rb +1 -1
  15. data/lib/granite/form/base.rb +1 -2
  16. data/lib/granite/form/errors.rb +0 -15
  17. data/lib/granite/form/model/associations/base.rb +0 -4
  18. data/lib/granite/form/model/associations/collection/embedded.rb +2 -1
  19. data/lib/granite/form/model/associations/collection/proxy.rb +1 -1
  20. data/lib/granite/form/model/associations/embeds_any.rb +7 -0
  21. data/lib/granite/form/model/associations/embeds_many.rb +9 -58
  22. data/lib/granite/form/model/associations/embeds_one.rb +7 -36
  23. data/lib/granite/form/model/associations/nested_attributes.rb +7 -7
  24. data/lib/granite/form/model/associations/persistence_adapters/active_record.rb +0 -4
  25. data/lib/granite/form/model/associations/persistence_adapters/base.rb +0 -4
  26. data/lib/granite/form/model/associations/references_many.rb +0 -32
  27. data/lib/granite/form/model/associations/references_one.rb +0 -28
  28. data/lib/granite/form/model/associations/reflections/embeds_any.rb +1 -1
  29. data/lib/granite/form/model/associations/reflections/embeds_many.rb +1 -1
  30. data/lib/granite/form/model/associations/reflections/embeds_one.rb +11 -1
  31. data/lib/granite/form/model/associations/reflections/references_any.rb +0 -4
  32. data/lib/granite/form/model/associations/reflections/singular.rb +0 -22
  33. data/lib/granite/form/model/associations.rb +0 -6
  34. data/lib/granite/form/model/attributes/attribute.rb +3 -21
  35. data/lib/granite/form/model/attributes/base.rb +5 -23
  36. data/lib/granite/form/model/attributes/reference_many.rb +1 -1
  37. data/lib/granite/form/model/attributes/reference_one.rb +1 -1
  38. data/lib/granite/form/model/attributes/reflections/attribute.rb +2 -8
  39. data/lib/granite/form/model/attributes/reflections/base/build_type_definition.rb +38 -0
  40. data/lib/granite/form/model/attributes/reflections/base.rb +20 -17
  41. data/lib/granite/form/model/attributes/reflections/collection/build_type_definition.rb +19 -0
  42. data/lib/granite/form/model/attributes/reflections/dictionary/build_type_definition.rb +19 -0
  43. data/lib/granite/form/model/attributes/reflections/dictionary.rb +0 -3
  44. data/lib/granite/form/model/attributes/reflections/reference_one.rb +0 -6
  45. data/lib/granite/form/model/attributes/reflections/represents/build_type_definition.rb +73 -0
  46. data/lib/granite/form/model/attributes/reflections/represents.rb +10 -2
  47. data/lib/granite/form/model/attributes/represents.rb +22 -37
  48. data/lib/granite/form/model/attributes.rb +10 -2
  49. data/lib/granite/form/model/persistence.rb +1 -19
  50. data/lib/granite/form/model/representation.rb +1 -0
  51. data/lib/granite/form/model/validations.rb +6 -0
  52. data/lib/granite/form/model.rb +1 -3
  53. data/lib/granite/form/types/active_support/time_zone.rb +2 -0
  54. data/lib/granite/form/types/array.rb +2 -0
  55. data/lib/granite/form/types/big_decimal.rb +2 -0
  56. data/lib/granite/form/types/boolean.rb +2 -0
  57. data/lib/granite/form/types/collection.rb +11 -0
  58. data/lib/granite/form/types/date.rb +2 -0
  59. data/lib/granite/form/types/date_time.rb +2 -0
  60. data/lib/granite/form/types/dictionary.rb +23 -0
  61. data/lib/granite/form/types/float.rb +2 -0
  62. data/lib/granite/form/types/has_subtype.rb +18 -0
  63. data/lib/granite/form/types/hash_with_action_controller_parameters.rb +2 -0
  64. data/lib/granite/form/types/integer.rb +2 -0
  65. data/lib/granite/form/types/object.rb +28 -0
  66. data/lib/granite/form/types/string.rb +2 -0
  67. data/lib/granite/form/types/time.rb +2 -0
  68. data/lib/granite/form/types/uuid.rb +2 -0
  69. data/lib/granite/form/types.rb +3 -0
  70. data/lib/granite/form/util.rb +55 -0
  71. data/lib/granite/form/version.rb +1 -1
  72. data/lib/granite/form.rb +1 -0
  73. data/spec/granite/form/active_record/associations_spec.rb +16 -18
  74. data/spec/granite/form/model/associations/embeds_many_spec.rb +29 -305
  75. data/spec/granite/form/model/associations/embeds_one_spec.rb +27 -212
  76. data/spec/granite/form/model/associations/nested_attributes_spec.rb +0 -95
  77. data/spec/granite/form/model/associations/references_many_spec.rb +5 -326
  78. data/spec/granite/form/model/associations/references_one_spec.rb +7 -279
  79. data/spec/granite/form/model/associations/reflections/embeds_any_spec.rb +1 -2
  80. data/spec/granite/form/model/associations/reflections/embeds_many_spec.rb +18 -26
  81. data/spec/granite/form/model/associations/reflections/embeds_one_spec.rb +16 -23
  82. data/spec/granite/form/model/associations/reflections/references_many_spec.rb +1 -1
  83. data/spec/granite/form/model/associations/reflections/references_one_spec.rb +1 -22
  84. data/spec/granite/form/model/associations/validations_spec.rb +0 -3
  85. data/spec/granite/form/model/associations_spec.rb +3 -24
  86. data/spec/granite/form/model/attributes/attribute_spec.rb +0 -29
  87. data/spec/granite/form/model/attributes/reflections/attribute_spec.rb +0 -9
  88. data/spec/granite/form/model/attributes/reflections/base/build_type_definition_spec.rb +27 -0
  89. data/spec/granite/form/model/attributes/reflections/base_spec.rb +16 -10
  90. data/spec/granite/form/model/attributes/reflections/collection/build_type_definition_spec.rb +24 -0
  91. data/spec/granite/form/model/attributes/reflections/dictionary/build_type_definition_spec.rb +24 -0
  92. data/spec/granite/form/model/attributes/reflections/dictionary_spec.rb +0 -6
  93. data/spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb +129 -0
  94. data/spec/granite/form/model/attributes/reflections/represents_spec.rb +43 -20
  95. data/spec/granite/form/model/attributes/represents_spec.rb +78 -55
  96. data/spec/granite/form/model/attributes_spec.rb +84 -23
  97. data/spec/granite/form/model/dirty_spec.rb +1 -7
  98. data/spec/granite/form/model/persistence_spec.rb +0 -2
  99. data/spec/granite/form/model/representation_spec.rb +4 -7
  100. data/spec/granite/form/model/validations/associated_spec.rb +2 -4
  101. data/spec/granite/form/model/validations/nested_spec.rb +2 -4
  102. data/spec/granite/form/model/validations_spec.rb +28 -1
  103. data/spec/granite/form/types/collection_spec.rb +22 -0
  104. data/spec/granite/form/types/dictionary_spec.rb +32 -0
  105. data/spec/granite/form/types/has_subtype_spec.rb +20 -0
  106. data/spec/granite/form/types/object_spec.rb +50 -4
  107. data/spec/granite/form/util_spec.rb +108 -0
  108. data/spec/spec_helper.rb +0 -15
  109. data/spec/support/active_record.rb +23 -0
  110. data/spec/support/shared/nested_attribute_examples.rb +3 -21
  111. metadata +56 -51
  112. data/.github/workflows/main.yml +0 -29
  113. data/gemfiles/rails.4.2.gemfile +0 -15
  114. data/lib/granite/form/model/attributes/collection.rb +0 -19
  115. data/lib/granite/form/model/attributes/dictionary.rb +0 -28
  116. data/lib/granite/form/model/attributes/localized.rb +0 -44
  117. data/lib/granite/form/model/attributes/reflections/localized.rb +0 -45
  118. data/lib/granite/form/model/callbacks.rb +0 -72
  119. data/lib/granite/form/model/lifecycle.rb +0 -309
  120. data/lib/granite/form/model/localization.rb +0 -26
  121. data/spec/granite/form/model/attributes/collection_spec.rb +0 -72
  122. data/spec/granite/form/model/attributes/dictionary_spec.rb +0 -100
  123. data/spec/granite/form/model/attributes/localized_spec.rb +0 -103
  124. data/spec/granite/form/model/attributes/reflections/localized_spec.rb +0 -37
  125. data/spec/granite/form/model/callbacks_spec.rb +0 -337
  126. data/spec/granite/form/model/lifecycle_spec.rb +0 -356
@@ -26,32 +26,14 @@ module Granite
26
26
  !!@persisted
27
27
  end
28
28
 
29
- def destroyed?
30
- !!@destroyed
31
- end
32
-
33
29
  def marked_for_destruction?
34
- @marked_for_destruction
35
- end
36
-
37
- def mark_for_destruction
38
- @marked_for_destruction = true
39
- end
40
-
41
- def _destroy
42
- marked_for_destruction?
30
+ false
43
31
  end
44
32
 
45
33
  private
46
34
 
47
35
  def mark_persisted!
48
36
  @persisted = true
49
- @destroyed = false
50
- end
51
-
52
- def mark_destroyed!
53
- @persisted = false
54
- @destroyed = true
55
37
  end
56
38
  end
57
39
  end
@@ -1,5 +1,6 @@
1
1
  require 'active_model/version'
2
2
  require 'granite/form/model/attributes/reflections/represents'
3
+ require 'granite/form/model/attributes/reflections/represents/build_type_definition'
3
4
  require 'granite/form/model/attributes/represents'
4
5
 
5
6
  module Granite
@@ -12,6 +12,12 @@ module Granite
12
12
  alias_method :validate, :valid?
13
13
  end
14
14
 
15
+ class_methods do
16
+ def validates_presence?(attr)
17
+ _validators[attr.to_sym].grep(ActiveModel::Validations::PresenceValidator).present?
18
+ end
19
+ end
20
+
15
21
  def validate!(context = nil)
16
22
  valid?(context) || raise_validation_error
17
23
  end
@@ -3,11 +3,8 @@ require 'granite/form/model/attributes'
3
3
  require 'granite/form/model/validations'
4
4
  require 'granite/form/model/scopes'
5
5
  require 'granite/form/model/primary'
6
- require 'granite/form/model/lifecycle'
7
6
  require 'granite/form/model/persistence'
8
- require 'granite/form/model/callbacks'
9
7
  require 'granite/form/model/associations'
10
- require 'granite/form/model/localization'
11
8
  require 'granite/form/model/representation'
12
9
  require 'granite/form/model/dirty'
13
10
 
@@ -24,6 +21,7 @@ module Granite
24
21
  include ActiveModel::Serialization
25
22
  include ActiveModel::Serializers::JSON
26
23
 
24
+ include Util
27
25
  include Conventions
28
26
  include Attributes
29
27
  include Validations
@@ -5,6 +5,8 @@ module Granite
5
5
  module Types
6
6
  module ActiveSupport
7
7
  class TimeZone < Float
8
+ private
9
+
8
10
  def typecast(value)
9
11
  case value
10
12
  when ::ActiveSupport::TimeZone
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class Array < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  if value.is_a?(::String)
9
11
  value.split(',').map(&:strip)
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class BigDecimal < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  BigDecimal(Float(value).to_s) if value
9
11
  rescue ArgumentError, TypeError
@@ -29,6 +29,8 @@ module Granite
29
29
  MAPPING[value]
30
30
  end
31
31
 
32
+ private
33
+
32
34
  def typecast(value)
33
35
  self.class.typecast(value)
34
36
  end
@@ -0,0 +1,11 @@
1
+ module Granite
2
+ module Form
3
+ module Types
4
+ class Collection < HasSubtype
5
+ def prepare(value)
6
+ ::Array.wrap(value).map { |v| subtype_definition.prepare(v) }
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class Date < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  value.try(:to_date)
9
11
  rescue ArgumentError
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class DateTime < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  value.try(:to_datetime)
9
11
  rescue ArgumentError
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Dictionary < HasSubtype
7
+ def prepare(value)
8
+ value = to_hash(value)
9
+ value = value.stringify_keys.slice(*reflection.keys) if reflection.keys.present?
10
+ value.transform_values { |v| subtype_definition.prepare(v) }.with_indifferent_access
11
+ end
12
+
13
+ private
14
+
15
+ def to_hash(value)
16
+ Hash[value]
17
+ rescue ArgumentError
18
+ {}
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class Float < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  Float(value)
9
11
  rescue ArgumentError, TypeError
@@ -0,0 +1,18 @@
1
+ module Granite
2
+ module Form
3
+ module Types
4
+ class HasSubtype
5
+ attr_reader :subtype_definition
6
+ delegate :reflection, :owner, :type, :name, :enum, to: :subtype_definition
7
+
8
+ def initialize(subtype_definition)
9
+ @subtype_definition = subtype_definition
10
+ end
11
+
12
+ def build_duplicate(*args)
13
+ self.class.new(subtype_definition.build_duplicate(*args))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class HashWithActionControllerParameters < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  case value
9
11
  when ActionController::Parameters
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class Integer < Float
7
+ private
8
+
7
9
  def typecast(value)
8
10
  super.try(:to_i)
9
11
  end
@@ -13,6 +13,29 @@ module Granite
13
13
  @owner = owner
14
14
  end
15
15
 
16
+ def build_duplicate(reflection, owner)
17
+ self.class.new(type, reflection, owner)
18
+ end
19
+
20
+ def prepare(value)
21
+ enumerize(ensure_type(value))
22
+ end
23
+
24
+ def enum
25
+ source = owner.evaluate(reflection.enum)
26
+
27
+ case source
28
+ when ::Range
29
+ source.to_a
30
+ when ::Set
31
+ source
32
+ else
33
+ ::Array.wrap(source)
34
+ end.to_set
35
+ end
36
+
37
+ private
38
+
16
39
  def ensure_type(value)
17
40
  if value.instance_of?(type)
18
41
  value
@@ -24,6 +47,11 @@ module Granite
24
47
  def typecast(value)
25
48
  value if value.is_a?(type)
26
49
  end
50
+
51
+ def enumerize(value)
52
+ set = enum if reflection.enum
53
+ value if !set || (set.none? || set.include?(value))
54
+ end
27
55
  end
28
56
  end
29
57
  end
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class String < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  value.to_s
9
11
  end
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class Time < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  value.is_a?(::String) && ::Time.zone ? ::Time.zone.parse(value) : value.try(:to_time)
9
11
  rescue ArgumentError
@@ -4,6 +4,8 @@ module Granite
4
4
  module Form
5
5
  module Types
6
6
  class UUID < Object
7
+ private
8
+
7
9
  def typecast(value)
8
10
  case value
9
11
  when UUIDTools::UUID
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'granite/form/types/has_subtype'
3
4
  require 'granite/form/types/object'
4
5
  require 'granite/form/types/array'
5
6
  require 'granite/form/types/big_decimal'
6
7
  require 'granite/form/types/boolean'
8
+ require 'granite/form/types/collection'
7
9
  require 'granite/form/types/date'
8
10
  require 'granite/form/types/date_time'
11
+ require 'granite/form/types/dictionary'
9
12
  require 'granite/form/types/hash_with_action_controller_parameters'
10
13
  require 'granite/form/types/float'
11
14
  require 'granite/form/types/integer'
@@ -0,0 +1,55 @@
1
+ module Granite
2
+ module Form
3
+ module Util
4
+ extend ActiveSupport::Concern
5
+
6
+ # Evaluates value and returns result based on what was passed:
7
+ # - if Proc was passed, then executes it in context of self
8
+ # - if Symbol was passed, then calls a method with that name and returns result
9
+ # - otherwise just returns the value itself
10
+ # @param value [Object] value to evaluate
11
+ # @return [Object] result of evaluation
12
+ def evaluate(value, *args)
13
+ value.is_a?(Symbol) ? evaluate_symbol(value, *args) : evaluate_if_proc(value, *args)
14
+ end
15
+
16
+ # Evaluates value and returns result based on what was passed:
17
+ # - if Proc was passed, then executes it in context of self
18
+ # - otherwise just returns the value itself
19
+ # @param value [Object] value to evaluate
20
+ # @return [Object] result of evaluation
21
+ def evaluate_if_proc(value, *args)
22
+ value.is_a?(Proc) ? evaluate_proc(value, *args) : value
23
+ end
24
+
25
+ # Evaluates `if` or `unless` conditions present in the supplied
26
+ # `options` being it a symbol or callable.
27
+ #
28
+ # @param [Hash] options The method options to evaluate.
29
+ # @option options :if method name or callable
30
+ # @option options :unless method name or callable
31
+ # @return [Boolean] whether conditions are satisfied
32
+ def conditions_satisfied?(**options)
33
+ raise ArgumentError, 'You cannot specify both if and unless' if options.key?(:if) && options.key?(:unless)
34
+
35
+ if options.key?(:if)
36
+ evaluate(options[:if])
37
+ elsif options.key?(:unless)
38
+ !evaluate(options[:unless])
39
+ else
40
+ true
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def evaluate_proc(value, *args)
47
+ instance_exec(*args, &value)
48
+ end
49
+
50
+ def evaluate_symbol(value, *args)
51
+ __send__(value, *args)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  module Granite
2
2
  module Form
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
data/lib/granite/form.rb CHANGED
@@ -8,6 +8,7 @@ require 'singleton'
8
8
  require 'active_model'
9
9
 
10
10
  require 'granite/form/version'
11
+ require 'granite/form/util'
11
12
  require 'granite/form/errors'
12
13
  require 'granite/form/extensions'
13
14
  require 'granite/form/undefined_class'
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Granite::Form::ActiveRecord::Associations do
4
4
  before do
5
5
  stub_model(:project) do
6
- include Granite::Form::Model::Lifecycle
6
+ include Granite::Form::Model::Persistence
7
7
  include Granite::Form::Model::Associations
8
8
 
9
9
  attribute :title, String
@@ -18,7 +18,8 @@ describe Granite::Form::ActiveRecord::Associations do
18
18
  end
19
19
 
20
20
  stub_model(:profile) do
21
- include Granite::Form::Model::Lifecycle
21
+ include Granite::Form::Model::Persistence
22
+ include Granite::Form::Model::Associations
22
23
 
23
24
  attribute :first_name, String
24
25
  attribute :last_name, String
@@ -89,7 +90,10 @@ describe Granite::Form::ActiveRecord::Associations do
89
90
  end
90
91
 
91
92
  context 'with profile already set' do
92
- before { user.create_profile(admin: true) }
93
+ before do
94
+ user.build_profile(admin: true)
95
+ user.save!
96
+ end
93
97
 
94
98
  specify do
95
99
  user.profile.admin = false
@@ -104,13 +108,9 @@ describe Granite::Form::ActiveRecord::Associations do
104
108
  let(:user) { User.create }
105
109
 
106
110
  describe '#projects' do
107
- specify do
108
- expect { user.projects << Project.new }
109
- .not_to change { user.read_attribute(:projects) }
110
- end
111
111
  specify do
112
112
  expect { user.projects << Project.new(title: 'First') }
113
- .to change { user.projects.reload.count }.from(0).to(1)
113
+ .not_to change { user.read_attribute(:projects) }
114
114
  end
115
115
  specify do
116
116
  user.projects << Project.new(title: 'First')
@@ -124,15 +124,14 @@ describe Granite::Form::ActiveRecord::Associations do
124
124
 
125
125
  specify do
126
126
  expect { user.projects << project }
127
- .to change { user.read_attribute(:projects) }.from(nil)
128
- .to([{'title' => 'First', 'author' => {'name' => 'Author'}}])
127
+ .not_to change { user.read_attribute(:projects) }
129
128
  end
130
129
  specify do
131
130
  expect do
132
131
  user.projects << project
133
132
  user.save
134
133
  end
135
- .to change { user.reload.read_attribute(:projects) }.from(nil)
134
+ .to change { user.reload.read_attribute(:projects) }.from([])
136
135
  .to([{'title' => 'First', 'author' => {'name' => 'Author'}}])
137
136
  end
138
137
  end
@@ -150,8 +149,7 @@ describe Granite::Form::ActiveRecord::Associations do
150
149
  end
151
150
  specify do
152
151
  expect { user.profile = Profile.new(first_name: 'google.com') }
153
- .to change { user.read_attribute(:profile) }.from(nil)
154
- .to({first_name: 'google.com', last_name: nil, admin: nil}.to_json)
152
+ .not_to change { user.read_attribute(:profile) }
155
153
  end
156
154
  specify do
157
155
  expect do
@@ -196,16 +194,16 @@ describe Granite::Form::ActiveRecord::Associations do
196
194
 
197
195
  specify { expect(User.reflect_on_association(:projects).klass).to eq(User::Project) }
198
196
  specify { expect(User.new.projects).to eq([]) }
199
- specify { expect(User.new.tap { |u| u.projects.create(title: 'Project') }.projects).to be_a(Granite::Form::Model::Associations::Collection::Embedded) }
200
- specify { expect(User.new.tap { |u| u.projects.create(title: 'Project') }.read_attribute(:projects)).to eq([{title: 'Project'}].to_json) }
197
+ specify { expect(User.new.tap { |u| u.projects.build(title: 'Project') }.projects).to be_a(Granite::Form::Model::Associations::Collection::Embedded) }
198
+ specify { expect(User.new.tap { |u| u.projects.build(title: 'Project') }.projects).to match([have_attributes(title: 'Project')]) }
201
199
 
202
200
  specify { expect(User.reflect_on_association(:profile).klass).to eq(User::Profile) }
203
201
  specify { expect(User.reflect_on_association(:profile).klass).to be < Profile }
204
202
  specify { expect(User.new.profile).to be_nil }
205
- specify { expect(User.new.tap { |u| u.create_profile(first_name: 'Profile') }.profile).to be_a(User::Profile) }
203
+ specify { expect(User.new.tap { |u| u.build_profile(first_name: 'Profile') }.profile).to be_a(User::Profile) }
206
204
  specify do
207
- expect(User.new.tap { |u| u.create_profile(first_name: 'Profile') }.read_attribute(:profile))
208
- .to eq({first_name: 'Profile', last_name: nil, admin: nil, age: nil}.to_json)
205
+ expect(User.new.tap { |u| u.build_profile(first_name: 'Profile') }.profile)
206
+ .to have_attributes(first_name: 'Profile', last_name: nil, admin: nil, age: nil)
209
207
  end
210
208
  end
211
209
  end