Permalink
Browse files

Update generators and tests to use doubles/actual models

  • Loading branch information...
thomas-holmes authored and alindeman committed Dec 30, 2013
1 parent 29c1758 commit 6044ecd6f5cb571b2e4fb4a113172d34951402c9
@@ -36,7 +36,7 @@ Feature: render_template matcher
describe "gadgets/index" do
it "renders the index template" do
- assign(:gadgets, [stub_model(Gadget)])
+ assign(:gadgets, [Gadget.create!])
render
expect(view).to render_template(:index)
@@ -11,8 +11,8 @@ Feature: stub template
describe "gadgets/list" do
it "renders the gadget partial for each gadget" do
assign(:gadgets, [
- mock_model(Gadget, :id => 1, :name => "First"),
- mock_model(Gadget, :id => 2, :name => "Second")
+ double(:name => "First"),
+ double(:name => "Second")
])
stub_template "gadgets/_gadget.html.erb" => "<%= gadget.name %><br/>"
render
@@ -36,7 +36,7 @@ Feature: stub template
describe "gadgets/edit" do
before(:each) do
- @gadget = assign(:gadget, stub_model(Gadget))
+ @gadget = assign(:gadget, Gadget.create!)
end
it "renders the form partial" do
@@ -10,8 +10,8 @@ Feature: view spec
describe "widgets/index" do
it "displays all the widgets" do
assign(:widgets, [
- stub_model(Widget, :name => "slicer"),
- stub_model(Widget, :name => "dicer")
+ Widget.create!(:name => "slicer"),
+ Widget.create!(:name => "dicer")
])
render
@@ -34,8 +34,8 @@ Feature: view spec
context "with 2 widgets" do
before(:each) do
assign(:widgets, [
- stub_model(Widget, :name => "slicer"),
- stub_model(Widget, :name => "dicer")
+ Widget.create!(:name => "slicer"),
+ Widget.create!(:name => "dicer")
])
end
@@ -58,7 +58,7 @@ Feature: view spec
describe "rendering the widget template" do
it "displays the widget" do
- assign(:widget, stub_model(Widget, :name => "slicer"))
+ assign(:widget, Widget.create!(:name => "slicer"))
render :template => "widgets/widget.html.erb"
@@ -112,7 +112,7 @@ Feature: view spec
describe "rendering locals in a partial" do
it "displays the widget" do
- widget = stub_model(Widget, :name => "slicer")
+ widget = Widget.create!(:name => "slicer")
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
@@ -134,7 +134,7 @@ Feature: view spec
describe "rendering locals in a partial" do
it "displays the widget" do
- widget = stub_model(Widget, :name => "slicer")
+ widget = Widget.create!(:name => "slicer")
render "widgets/widget", :widget => widget
@@ -3,7 +3,7 @@
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/edit" do
before(:each) do
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
@@ -5,7 +5,7 @@
before(:each) do
assign(:<%= table_name %>, [
<% [1,2].each_with_index do |id, model_index| -%>
- stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
+ <%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
@@ -3,11 +3,11 @@
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/new" do
before(:each) do
- assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
+ assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
-<%= !output_attributes.empty? ? " ).as_new_record)\n end" : " end" %>
+<%= !output_attributes.empty? ? " ))\n end" : " end" %>
it "renders new <%= ns_file_name %> form" do
render
@@ -3,7 +3,7 @@
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/show" do
before(:each) do
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>

0 comments on commit 6044ecd

Please sign in to comment.