Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ rvm:
- 1.8.7
env:
- RAILS_VERSION=master
- RAILS_VERSION=4.0.2
- RAILS_VERSION=4.0.4
- RAILS_VERSION=4-0-stable
- RAILS_VERSION=3.2.16
- RAILS_VERSION=3.2.17
- RAILS_VERSION=3-2-stable
- RAILS_VERSION=3.1.12
- RAILS_VERSION=3.0.20
Expand All @@ -28,9 +28,9 @@ matrix:
- rvm: 1.9.2
env: RAILS_VERSION=master
- rvm: 1.8.7
env: RAILS_VERSION=4.0.2
env: RAILS_VERSION=4.0.4
- rvm: 1.9.2
env: RAILS_VERSION=4.0.2
env: RAILS_VERSION=4.0.4
- rvm: 1.8.7
env: RAILS_VERSION=4-0-stable
- rvm: 1.9.2
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ when /master/
when /stable$/
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
when nil, false, ""
gem "rails", "4.0.2"
gem "rails", "4.0.4"
else
gem "rails", version
end
4 changes: 4 additions & 0 deletions lib/rspec/rails/mocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ def @object.__model_class_has_column?(method_name)
#{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s)
end

def @object.has_attribute?(attr_name)
__model_class_has_column?(attr_name)
end unless #{stubs.has_key?(:has_attribute?)}

def @object.respond_to?(method_name, include_private=false)
__model_class_has_column?(method_name) ? true : super
end unless #{stubs.has_key?(:respond_to?)}
Expand Down
27 changes: 27 additions & 0 deletions spec/rspec/rails/mocks/mock_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,33 @@
end
end

describe "#has_attribute?" do
context "with an ActiveRecord model" do
before(:each) do
MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
@model = mock_model(MockableModel)
end

it "has a given attribute if the underlying model has column of the same name" do
expect(@model.has_attribute?("column_a")).to be_true
expect(@model.has_attribute?("column_b")).to be_true
expect(@model.has_attribute?("column_c")).to be_false
end

it "accepts symbols" do
expect(@model.has_attribute?(:column_a)).to be_true
expect(@model.has_attribute?(:column_b)).to be_true
expect(@model.has_attribute?(:column_c)).to be_false
end

it "allows has_attribute? to be explicitly stubbed" do
@model = mock_model(MockableModel, :has_attribute? => false)
expect(@model.has_attribute?(:column_a)).to be_false
expect(@model.has_attribute?(:column_b)).to be_false
end
end
end

describe "#respond_to?" do
context "with an ActiveRecord model" do
before(:each) do
Expand Down