Skip to content

Instantly share code, notes, and snippets.

@carlesjove
Last active March 8, 2016 08:23
Show Gist options
  • Save carlesjove/7c9465b5c6ca27cefab2 to your computer and use it in GitHub Desktop.
Save carlesjove/7c9465b5c6ca27cefab2 to your computer and use it in GitHub Desktop.
How to use Temping to test a module
require "rails_helper"
# In this example I'm testing a module that introduces some
# AR validations to the model. Using shoulda matchers, as I
# normally would in a model spec, works just fine :-)
describe "Scopable concern" do
before do
Temping.create :parent_model do
end
Temping.create :dummy do
with_columns do |t|
t.integer :parent_model_id
end
include Scopable
must_belong_to :parent_model
end
end
subject { Dummy.new }
describe "associations" do
it { should belong_to(:parent_model) }
end
describe "validations" do
it { should validate_presence_of(:parent_model) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment