Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generate stub_model(X).as_new_record in generated "new" view specs

- Closes #232.
  • Loading branch information...
commit d2ef5930d556ccc286e63e33e91b55c27f3ca8b2 1 parent b45d093
@dchelimsky dchelimsky authored
View
14 Gotchas.markdown
@@ -1,14 +0,0 @@
-# Gotchas
-
-## Name conflicts with upstream dependencies
-
-Examples in rspec-rails mix in Rails' assertion modules, which mix in assertion
-libraries from Minitest (if available) or Test::Unit. This makes it easy to
-accidentally override a method defined in one of those upstream modules in an
-example.
-
-For example, if you have a model named `Message`, and you define a `message`
-method (using `def message` or `let(:message)` in an example group, it will
-override Minitest's `message` method, which is used internally by Minitest, and
-is also a public API of Minitest. In this case, you would need to use a
-different method name or work with instance variables instead of methods.
View
1  History.md
@@ -6,6 +6,7 @@
* Changes
* route_to matcher delegates to assert_recognizes instead of assert_routing
+ * update generators to use as_new_record instead of :new_record => true
### 2.0.0.rc / 2010-10-05
View
25 Upgrade.markdown
@@ -1,11 +1,10 @@
-# Changes in beta.20
-
-### Webrat or Capybara
+# Upgrade to rspec-rails-2
-rspec-rails-2.0.0.beta.20 removes the dependency and offers you a choice of
-using webrat or capybara. Just add the library of your choice to your Gemfile.
+## Webrat and Capybara
-# Upgrade to rspec-rails-2
+Earlier 2.0.0.beta versions depended on Webrat. As of
+rspec-rails-2.0.0.beta.20, this dependency and offers you a choice of using
+webrat or capybara. Just add the library of your choice to your Gemfile.
## Controller specs
@@ -29,3 +28,17 @@ partial gets rendered:
render
view.should render_template(:partial => "widget/_row")
+## as_new_record
+
+Earlier versions of the view generators generated stub_model with `:new_record?
+=> true`. As of rspec-rails-2.0.0.rc, that is no longer recognized, so you need
+to change this:
+
+ stub_model(Widget, :new_record? => true)
+
+to this:
+
+ stub_model(Widget).as_new_record
+
+Generators in 2.0.0 final release will do the latter.
+
View
6 lib/generators/rspec/scaffold/templates/new_spec.rb
@@ -3,13 +3,11 @@
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= table_name %>/new.html.<%= options[:template_engine] %>" do
before(:each) do
- assign(:<%= file_name %>, stub_model(<%= class_name %>,
- :new_record? => true<%= output_attributes.empty? ? '' : ',' %>
+ assign(:<%= file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
- ))
- end
+<%= !output_attributes.empty? ? " ).as_new_record)\n end" : " end" %>
it "renders new <%= file_name %> form" do
render
Please sign in to comment.
Something went wrong with that request. Please try again.