Skip to content

Instantly share code, notes, and snippets.

@danielspaniel
Created January 21, 2012 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielspaniel/1650477 to your computer and use it in GitHub Desktop.
Save danielspaniel/1650477 to your computer and use it in GitHub Desktop.
require "spec_helper"
describe Mongoid::Relations::Embedded::Many do
class Chef
include Mongoid::Document
embeds_many :menus
field :name
end
class Menu
include Mongoid::Document
embedded_in :chef
field :title
field :courses, type: Array
field :price, type: Integer
end
it "saves array field in embedded has_many" do
chef = Chef.create(:name => "dude")
old_menu = Menu.create(title: 'food', courses: ['fish', 'bread'], chef: chef)
new_menu = Menu.new(title: 'snacks', courses: ['soup', 'salad'])
old_menu.title = new_menu.title
old_menu.courses = new_menu.courses
old_menu.save
chef.reload.menus.first.courses.should == new_menu.courses
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment