Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Define primary_key method on class generated by mock_model("WithAStri…

…ng").

- Closes #435.
  • Loading branch information...
commit cf3f04c03abb40b52b83bcc743b8a1dab530205d 1 parent c7388eb
@dchelimsky dchelimsky authored
View
2  Changelog.md
@@ -18,6 +18,8 @@
fixure_file_upload reads from ActiveSupport::TestCase.fixture_path and misses
RSpec's configuration (David Chelimsky)
* Support nested resource in view spec generator (David Chelimsky)
+ * Define `primary_key` on class generated by mock_model("WithAString") (David
+ Chelimsky)
### 2.6.1 / 2011-05-25
View
1  lib/rspec/rails/mocks.rb
@@ -63,6 +63,7 @@ def mock_model(string_or_model_class, stubs = {})
else
model_class = Object.const_set(string_or_model_class, Class.new do
extend ActiveModel::Naming
+ def self.primary_key; :id; end
end)
end
else
View
16 spec/rspec/rails/mocks/mock_model_spec.rb
@@ -101,6 +101,22 @@
end
end
+ describe "as association that doesn't exist yet" do
+ before(:each) do
+ @real = AssociatedModel.create!
+ @mock_model = mock_model("Other")
+ @real.nonexistent_model = @mock_model
+ end
+
+ it "passes: associated_model == mock" do
+ @mock_model.should == @real.nonexistent_model
+ end
+
+ it "passes: mock == associated_model" do
+ @real.nonexistent_model.should == @mock_model
+ end
+ end
+
describe "#is_a?" do
before(:each) do
@model = mock_model(SubMockableModel)
View
1  spec/support/ar_classes.rb
@@ -30,6 +30,7 @@ class SubMockableModel < MockableModel
class AssociatedModel < ActiveRecord::Base
extend Connections
belongs_to :mockable_model
+ belongs_to :nonexistent_model, :class_name => "Other"
end
class AlternatePrimaryKeyModel < ActiveRecord::Base
Please sign in to comment.
Something went wrong with that request. Please try again.