Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for STI referencing #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/fixtures/models/article_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require_relative './page'

class ArticlePage < Page
end
3 changes: 3 additions & 0 deletions spec/fixtures/models/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Page < ActiveRecord::Base
validates :title, :presence => true
end
5 changes: 5 additions & 0 deletions spec/fixtures/seeds/test/article_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
records:
- sprig_id: 1
title: "<%= sprig_record(Page, 1).title %>"
- sprig_id: 2
title: Second Title
5 changes: 5 additions & 0 deletions spec/fixtures/seeds/test/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
records:
- sprig_id: 1
title: First Title
- sprig_id: 2
title: "<%= sprig_record(ArticlePage, 2).title %>"
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
Tag.connection.execute "DROP TABLE IF EXISTS posts_tags;"
Tag.connection.execute "CREATE TABLE posts_tags (id INTEGER PRIMARY KEY , post_id INTEGER, tag_id INTEGER);"

Page.connection.execute "DROP TABLE IF EXISTS pages;"
Page.connection.execute "CREATE TABLE pages (id INTEGER PRIMARY KEY , title VARCHAR(255), type VARCHAR(255));"

# Helpers
#
# Setup fake `Rails.root`
Expand Down
17 changes: 17 additions & 0 deletions spec/sprig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@
end
end

context "with STI records" do
around do |example|
load_seeds('article_pages.yml', 'pages.yml', &example)
end

it "allows cross-referencing of STI records" do
sprig [
ArticlePage,
Page
]

Page.all.map(&:title).should == [
'First Title', 'First Title', 'Second Title', 'Second Title'
]
end
end

context "with cyclic dependencies" do
around do |example|
load_seeds('comments.yml', 'posts_with_cyclic_dependencies.yml', &example)
Expand Down