spec/support/models.rb in amoeba-3.2.0 vs spec/support/models.rb in amoeba-3.3.0
- old
+ new
@@ -32,45 +32,45 @@
validates_presence_of :topic
validates_presence_of :author
amoeba do
enable
- clone [:widgets, :notes]
+ clone %i[widgets notes]
prepend title: 'Copy of '
append contents: ' (copied version)'
regex contents: { replace: /dog/, with: 'cat' }
customize([
- lambda do |orig_obj, copy_of_obj|
- orig_obj.comments.each do |oc|
- if oc.nerf == 'ratatat'
- hash = oc.attributes
- hash[:id] = nil
- hash[:post_id] = nil
- hash[:contents] = nil
+ lambda do |orig_obj, copy_of_obj|
+ orig_obj.comments.each do |oc|
+ next unless oc.nerf == 'ratatat'
- cc = Comment.new(hash)
+ hash = oc.attributes
+ hash[:id] = nil
+ hash[:post_id] = nil
+ hash[:contents] = nil
- copy_of_obj.comments << cc
- end
- end
- end,
- lambda do |orig_obj, copy_of_obj|
- orig_obj.comments.each do |oc|
- if oc.nerf == 'bonk'
- hash = oc.attributes
- hash[:id] = nil
- hash[:post_id] = nil
- hash[:contents] = nil
- hash[:nerf] = 'bonkers'
+ cc = Comment.new(hash)
- cc = Comment.new(hash)
+ copy_of_obj.comments << cc
+ end
+ end,
+ lambda do |orig_obj, copy_of_obj|
+ orig_obj.comments.each do |oc|
+ next unless oc.nerf == 'bonk'
- copy_of_obj.comments << cc
- end
- end
- end
- ])
+ hash = oc.attributes
+ hash[:id] = nil
+ hash[:post_id] = nil
+ hash[:contents] = nil
+ hash[:nerf] = 'bonkers'
+
+ cc = Comment.new(hash)
+
+ copy_of_obj.comments << cc
+ end
+ end
+ ])
end
def truthy?
true
end
@@ -95,15 +95,17 @@
class ArrayPack
def self.load(str)
return [] unless str.present?
return str if str.is_a?(Array)
+
str.split(',').map(&:to_i)
end
def self.dump(int_array)
return '' unless int_array.present?
+
int_array.join(',')
end
end
serialize :value, ArrayPack
@@ -259,11 +261,11 @@
class Photo < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
amoeba do
- customize(lambda { |original_photo,new_photo|
+ customize(lambda { |original_photo, new_photo|
new_photo.name = original_photo.name.to_s + ' Copy'
})
end
end
@@ -271,23 +273,22 @@
has_many :employees
has_many :customers
amoeba do
include_associations :employees,
- :customers
+ :customers
end
end
class Employee < ActiveRecord::Base
has_many :addresses, as: :addressable
has_many :photos, as: :imageable
belongs_to :company
amoeba do
- include_associations [:addresses, :photos]
+ include_associations %i[addresses photos]
end
-
end
class Customer < ActiveRecord::Base
has_many :addresses, as: :addressable
has_many :photos, as: :imageable
@@ -311,11 +312,11 @@
through :become_real
remapper :remap_subobjects
end
def become_real
- self.dup.becomes RealObject
+ dup.becomes RealObject
end
def remap_subobjects(relation_name)
:subobjects if relation_name == :subobject_prototypes
end
@@ -330,11 +331,11 @@
enable
through :become_subobject
end
def become_subobject
- self.dup.becomes Subobject
+ dup.becomes Subobject
end
end
class Subobject < MetalObject
end
@@ -358,10 +359,10 @@
enable
end
end
class BoxProduct < ActiveRecord::Base
- belongs_to :box, class_name: 'Box'
+ belongs_to :box, class_name: 'Box'
amoeba do
enable
propagate
end