Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created September 12, 2013 13:58
Show Gist options
  • Save arthurnn/6537849 to your computer and use it in GitHub Desktop.
Save arthurnn/6537849 to your computer and use it in GitHub Desktop.
require "spec_helper"
class Publication
include Mongoid::Document
embeds_many :issues
end
class Issue
include Mongoid::Document
embedded_in :publication
embeds_many :articles, :as => :articleable, :class_name => 'Article'
accepts_nested_attributes_for :articles, :allow_destroy => true, :autosave => true
end
class Article
include Mongoid::Document
embedded_in :articleable, polymorphic: true
field :title
end
describe "3265" do
before do
p = Publication.create!
i = Issue.new(articles: [Article.new(title: 'Some value')] )
p.issues << i
end
let(:issue) do
Publication.last.issues.first
end
it "works" do
count = 0
issue.articles.each do |article|
count += 1
expect(article.title).to eq("Some value")
end
expect(count).to eq(1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment