diff --git a/spec/fixtures/models/article_page.rb b/spec/fixtures/models/article_page.rb new file mode 100644 index 0000000..66d7169 --- /dev/null +++ b/spec/fixtures/models/article_page.rb @@ -0,0 +1,4 @@ +require_relative './page' + +class ArticlePage < Page +end diff --git a/spec/fixtures/models/page.rb b/spec/fixtures/models/page.rb new file mode 100644 index 0000000..335ee25 --- /dev/null +++ b/spec/fixtures/models/page.rb @@ -0,0 +1,3 @@ +class Page < ActiveRecord::Base + validates :title, :presence => true +end diff --git a/spec/fixtures/seeds/test/article_pages.yml b/spec/fixtures/seeds/test/article_pages.yml new file mode 100644 index 0000000..4f23721 --- /dev/null +++ b/spec/fixtures/seeds/test/article_pages.yml @@ -0,0 +1,5 @@ +records: + - sprig_id: 1 + title: "<%= sprig_record(Page, 1).title %>" + - sprig_id: 2 + title: Second Title diff --git a/spec/fixtures/seeds/test/pages.yml b/spec/fixtures/seeds/test/pages.yml new file mode 100644 index 0000000..f35c5b2 --- /dev/null +++ b/spec/fixtures/seeds/test/pages.yml @@ -0,0 +1,5 @@ +records: + - sprig_id: 1 + title: First Title + - sprig_id: 2 + title: "<%= sprig_record(ArticlePage, 2).title %>" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a195cd5..8b43d22 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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` diff --git a/spec/sprig_spec.rb b/spec/sprig_spec.rb index 4795ff8..94c373b 100644 --- a/spec/sprig_spec.rb +++ b/spec/sprig_spec.rb @@ -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)