0

这是创建测试表的地方:

factory :reward_scheme, class: RewardsModels::RewardScheme do
    uid             { ExpectedData::COSTA_UID } 
    scheme_type     { "bricks" }
    reward_type     { "menu"}
    company_address { FactoryGirl.build(:company_address) }
    reward_config   { FactoryGirl.build(:reward_config) }
    brand           { FactoryGirl.build(:brand) }
    master_offers   { [ FactoryGirl.build(:master_offer) ] }
    master_specials { [ FactoryGirl.build(:master_special) ] }
    url "http://costa.com"
    after(:create) do |reward_scheme|
      reward_scheme.stores << FactoryGirl.create(:store)
      reward_scheme.user_cards << FactoryGirl.create(:user_card)
    end
end

日志如下:

CoreModels::交易失败/错误:reward_scheme.stores << FactoryGirl.create(:store)

 Mongoid::Errors::Validations:

   message:
     Validation of RewardsModels::Store failed.
   summary:
     The following errors were found: Reward scheme can't be blank
   resolution:
     Try persisting the document with valid data or remove the validations.
 # ./spec/factories/reward_scheme.rb:15:in `block (3 levels) in <top (required)>'
 # ./spec/core/transaction_spec.rb:6:in `block (2 levels) in <top (required)>'

这是模型文件的样子:

模块用户模型

类存储包括 Mongoid::Document 包括 Mongoid::Timestamps

field :reward_scheme_id, type: String
field :store_id, type: String
field :store_name, type: String, default: "HQ"
field :reward_scheme_name, type:String
field :about, type: String, default: "MyGravity - loyalty begins with trust"
field :logo, type: String, default: 'https://static.mygravity.co/partners/logo.svg'
field :splash_screen_url, type: String, default: "https://static.mygravity.co/assets/SplitShire_Blur_Background_XVI.jpg"
field :awaiting_update, type: Boolean, default:false

embeds_one :location, class_name:'UserModels::Location'
embeds_one :open_hours, class_name:'UserModels::OpenHours'
embeds_one :optional, class_name:'UserModels::Optional'
embeds_many :specials, class_name:'UserModels::Special'
embeds_many :offers, class_name:'UserModels::Offer'

before_create :set_defaults

def set_defaults
  self.location = UserModels::Location.new unless self.location
  self.optional = UserModels::Optional.new unless self.optional
end

结尾

类位置包括 Mongoid::Document

field :longitude, type: Float, default: -0.131425
field :latitude, type: Float, default: 51.507697
field :address_line_1, type: String, default: 'Impact Hub - Westmister'
field :post_code, type: String, default: 'SW1Y 4TE'
field :city_town, type: String, default: 'London'

embedded_in :store

结尾

类 OpenHours 包括 Mongoid::Document

field :monday, type: String
field :tuesday, type: String
field :wednesday, type: String
field :thursday, type: String
field :friday, type: String
field :saturday, type: String
field :sunday, type: String
field :sunday_1, type: String

embedded_in :store

结尾

类特殊包括 Mongoid::Document

# Need this to search 
field :special_id, type: Integer
field :special_uid, type: Integer
field :title, type: String
field :text, type: String

embedded_in :store

before_save :set_special_uid

def set_special_uid
  self.special_uid = self.special_id
end

def attributes
  # p super
  # p Hash[super.map{|k,v| [(alais[k] || k), v]}]

  hash = super
  alais = {'special_id' => 'id'}

  hash.keys.each do |k,v| 
    hash[ alais[k] ] = hash['special_id'].to_s if alais[k]
    # Need this as special_id is mapped in the iOS to a string...
    hash['special_id'] = hash['special_id'].to_s if k == 'special_id'
  end
  hash

end

结尾

类报价包括 Mongoid::Document

field :name, type: String 
field :offer_id, type: Integer
field :value, type: Float, default:0.0 # monetary value
field :points, type: Integer
field :icon_url, type: String
field :icon_name, type: String

embedded_in :store    

def attributes
  # p super
  # p Hash[super.map{|k,v| [(alais[k] || k), v]}]

  hash = super
  alais = {'offer_id' => 'id'}

  hash.keys.each { |k,v| hash[ alais[k] ] = hash['offer_id'] if alais[k] }
  hash

end

结尾

类可选包括 Mongoid::Document

field :email, type: String, default:""
field :twitter, type: String, default:""
field :telephone, type: String, default:""
field :wifi_password, type: String, default:""

embedded_in :store

结束结束

非常感谢有关升级到 mongoid 6 所需的代码更改的任何线索。谢谢

4

0 回答 0