Skip to content

Commit 6044ecd

Browse files
Thomas Holmesalindeman
authored andcommitted
Update generators and tests to use doubles/actual models
1 parent 29c1758 commit 6044ecd

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

features/matchers/render_template_matcher.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Feature: render_template matcher
3636
3737
describe "gadgets/index" do
3838
it "renders the index template" do
39-
assign(:gadgets, [stub_model(Gadget)])
39+
assign(:gadgets, [Gadget.create!])
4040
render
4141
4242
expect(view).to render_template(:index)

features/view_specs/stub_template.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Feature: stub template
1111
describe "gadgets/list" do
1212
it "renders the gadget partial for each gadget" do
1313
assign(:gadgets, [
14-
mock_model(Gadget, :id => 1, :name => "First"),
15-
mock_model(Gadget, :id => 2, :name => "Second")
14+
double(:name => "First"),
15+
double(:name => "Second")
1616
])
1717
stub_template "gadgets/_gadget.html.erb" => "<%= gadget.name %><br/>"
1818
render
@@ -36,7 +36,7 @@ Feature: stub template
3636
3737
describe "gadgets/edit" do
3838
before(:each) do
39-
@gadget = assign(:gadget, stub_model(Gadget))
39+
@gadget = assign(:gadget, Gadget.create!)
4040
end
4141
4242
it "renders the form partial" do

features/view_specs/view_spec.feature

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Feature: view spec
1010
describe "widgets/index" do
1111
it "displays all the widgets" do
1212
assign(:widgets, [
13-
stub_model(Widget, :name => "slicer"),
14-
stub_model(Widget, :name => "dicer")
13+
Widget.create!(:name => "slicer"),
14+
Widget.create!(:name => "dicer")
1515
])
1616
1717
render
@@ -34,8 +34,8 @@ Feature: view spec
3434
context "with 2 widgets" do
3535
before(:each) do
3636
assign(:widgets, [
37-
stub_model(Widget, :name => "slicer"),
38-
stub_model(Widget, :name => "dicer")
37+
Widget.create!(:name => "slicer"),
38+
Widget.create!(:name => "dicer")
3939
])
4040
end
4141
@@ -58,7 +58,7 @@ Feature: view spec
5858
5959
describe "rendering the widget template" do
6060
it "displays the widget" do
61-
assign(:widget, stub_model(Widget, :name => "slicer"))
61+
assign(:widget, Widget.create!(:name => "slicer"))
6262
6363
render :template => "widgets/widget.html.erb"
6464
@@ -112,7 +112,7 @@ Feature: view spec
112112
113113
describe "rendering locals in a partial" do
114114
it "displays the widget" do
115-
widget = stub_model(Widget, :name => "slicer")
115+
widget = Widget.create!(:name => "slicer")
116116
117117
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
118118
@@ -134,7 +134,7 @@ Feature: view spec
134134
135135
describe "rendering locals in a partial" do
136136
it "displays the widget" do
137-
widget = stub_model(Widget, :name => "slicer")
137+
widget = Widget.create!(:name => "slicer")
138138
139139
render "widgets/widget", :widget => widget
140140

lib/generators/rspec/scaffold/templates/edit_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/edit" do
55
before(:each) do
6-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
6+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
77
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
88
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
99
<% end -%>

lib/generators/rspec/scaffold/templates/index_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
before(:each) do
66
assign(:<%= table_name %>, [
77
<% [1,2].each_with_index do |id, model_index| -%>
8-
stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
8+
<%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
99
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
1010
:<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
1111
<% end -%>

lib/generators/rspec/scaffold/templates/new_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/new" do
55
before(:each) do
6-
assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
6+
assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
77
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
88
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
99
<% end -%>
10-
<%= !output_attributes.empty? ? " ).as_new_record)\n end" : " end" %>
10+
<%= !output_attributes.empty? ? " ))\n end" : " end" %>
1111
1212
it "renders new <%= ns_file_name %> form" do
1313
render

lib/generators/rspec/scaffold/templates/show_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/show" do
55
before(:each) do
6-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
6+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
77
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
88
:<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
99
<% end -%>

0 commit comments

Comments
 (0)