module Stratify
  module Garmin
    class Activity < Stratify::Activity
      field :guid, :type => Integer
      field :title
      field :description
      field :username
      field :activity_type
      field :event_type
      field :distance_in_miles, :type => Float
      field :time_in_seconds, :type => Integer
      field :starting_latitude, :type => BigDecimal
      field :starting_longitude, :type => BigDecimal

      natural_key :guid

      validates_presence_of :guid, :title, :username, :activity_type, :event_type, :distance_in_miles, :time_in_seconds

      template %q[
        <p class="summary"><%= summary %></p>
        <p class="details"><%= details %></p>
      ]

      def permalink
        "http://connect.garmin.com/activity/#{guid}"
      end

      def presenter
        Stratify::Garmin::Presenter.new(self)
      end
    end
  end
end

module Stratify
  module Garmin
    class Activity < Stratify::Activity
      field :guid, :type => Integer
      field :title
      field :description
      field :username
      field :activity_type
      field :event_type
      field :distance_in_miles, :type => Float
      field :time_in_seconds, :type => Integer
      field :elevation_gain_in_feet, :type => Integer
      field :starting_latitude, :type => BigDecimal
      field :starting_longitude, :type => BigDecimal

      natural_key :guid

      validates_presence_of :guid, :title, :username, :activity_type, :event_type, :distance_in_miles, :time_in_seconds

      template %q[
        <p class="summary"><%= summary %></p>
        <p class="details"><%= details %></p>
      ]

      def permalink
        "http://connect.garmin.com/activity/#{guid}"
      end

      def presenter
        Stratify::Garmin::Presenter.new(self)
      end
    end
  end
end

Declare missing field in Stratify::Garmin::Activity
Declare missing field in Stratify::Garmin::Activity

Missing field was detected by test failure after upgrading to Mongoid 4:

  stratify-garmin collects and stores data from Garmin Connect
   Failure/Error: collector.run
   Mongoid::Errors::UnknownAttribute:

     Problem:
       Attempted to set a value for 'elevation_gain_in_feet' which is
       not allowed on the model Stratify::Garmin::Activity.
     Summary:
       Without including Mongoid::Attributes::Dynamic in your model and
       the attribute does not already exist in the attributes hash,
       attempting to call
       Stratify::Garmin::Activity#elevation_gain_in_feet= for it is not
       allowed. This is also triggered by passing the attribute to any
       method that accepts an attributes hash, and is raised instead of
       getting a NoMethodError.
     Resolution:
       You can include Mongoid::Attributes::Dynamic if you expect to be
       writing values for undefined fields often.
