Commit f893cf3d7117c2b1eab4c6d6480f286d500537f1

Authored by Daniel
Committed by Diego Araújo
1 parent 75f3fbe9
Exists in colab and in 2 other branches master, stable

Update record #latest methods to be a bit more robust

Don't fail with NoMethodError if a KalibroConfiguration or Project does
not have Attributes saved.
app/models/kalibro_configuration.rb
... ... @@ -19,6 +19,13 @@ class KalibroConfiguration < KalibroClient::Entities::Configurations::KalibroCon
19 19 self.public_or_owned_by_user
20 20 end
21 21  
  22 + def self.latest(count = 1)
  23 + all.sort { |one, another| another.id <=> one.id }.select { |kalibro_configuration|
  24 + attributes = kalibro_configuration.attributes
  25 + attributes && attributes.public
  26 + }.first(count)
  27 + end
  28 +
22 29 def attributes
23 30 @attributes ||= KalibroConfigurationAttributes.find_by(kalibro_configuration_id: self.id)
24 31 end
... ... @@ -28,8 +35,4 @@ class KalibroConfiguration &lt; KalibroClient::Entities::Configurations::KalibroCon
28 35 @attributes = nil
29 36 super
30 37 end
31   -
32   - def self.latest(count=1)
33   - all.sort { |one, another| another.id <=> one.id }.select { |kalibro_configuration| kalibro_configuration.attributes.public }.first(count)
34   - end
35 38 end
... ...
app/models/project.rb
... ... @@ -17,7 +17,10 @@ class Project &lt; KalibroClient::Entities::Processor::Project
17 17 end
18 18  
19 19 def self.latest(count = 1)
20   - all.sort { |a, b| b.id <=> a.id }.select { |project| project.attributes.public }.first(count)
  20 + all.sort { |one, another| another.id <=> one.id }.select { |project|
  21 + attributes = project.attributes
  22 + attributes && attributes.public
  23 + }.first(count)
21 24 end
22 25  
23 26 def attributes
... ...