Scaffolding in some mashy stuff
This commit is contained in:
131
rails/map-mash/spec/controllers/mashes_controller_spec.rb
Normal file
131
rails/map-mash/spec/controllers/mashes_controller_spec.rb
Normal file
@@ -0,0 +1,131 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MashesController do
|
||||
|
||||
def mock_mash(stubs={})
|
||||
@mock_mash ||= mock_model(Mash, stubs)
|
||||
end
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns all mashes as @mashes" do
|
||||
Mash.stub(:find).with(:all).and_return([mock_mash])
|
||||
get :index
|
||||
assigns[:mashes].should == [mock_mash]
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested mash as @mash" do
|
||||
Mash.stub(:find).with("37").and_return(mock_mash)
|
||||
get :show, :id => "37"
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new mash as @mash" do
|
||||
Mash.stub(:new).and_return(mock_mash)
|
||||
get :new
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested mash as @mash" do
|
||||
Mash.stub(:find).with("37").and_return(mock_mash)
|
||||
get :edit, :id => "37"
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST create" do
|
||||
|
||||
describe "with valid params" do
|
||||
it "assigns a newly created mash as @mash" do
|
||||
Mash.stub(:new).with({'these' => 'params'}).and_return(mock_mash(:save => true))
|
||||
post :create, :mash => {:these => 'params'}
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
|
||||
it "redirects to the created mash" do
|
||||
Mash.stub(:new).and_return(mock_mash(:save => true))
|
||||
post :create, :mash => {}
|
||||
response.should redirect_to(mash_url(mock_mash))
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns a newly created but unsaved mash as @mash" do
|
||||
Mash.stub(:new).with({'these' => 'params'}).and_return(mock_mash(:save => false))
|
||||
post :create, :mash => {:these => 'params'}
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
Mash.stub(:new).and_return(mock_mash(:save => false))
|
||||
post :create, :mash => {}
|
||||
response.should render_template('new')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "PUT update" do
|
||||
|
||||
describe "with valid params" do
|
||||
it "updates the requested mash" do
|
||||
Mash.should_receive(:find).with("37").and_return(mock_mash)
|
||||
mock_mash.should_receive(:update_attributes).with({'these' => 'params'})
|
||||
put :update, :id => "37", :mash => {:these => 'params'}
|
||||
end
|
||||
|
||||
it "assigns the requested mash as @mash" do
|
||||
Mash.stub(:find).and_return(mock_mash(:update_attributes => true))
|
||||
put :update, :id => "1"
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
|
||||
it "redirects to the mash" do
|
||||
Mash.stub(:find).and_return(mock_mash(:update_attributes => true))
|
||||
put :update, :id => "1"
|
||||
response.should redirect_to(mash_url(mock_mash))
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "updates the requested mash" do
|
||||
Mash.should_receive(:find).with("37").and_return(mock_mash)
|
||||
mock_mash.should_receive(:update_attributes).with({'these' => 'params'})
|
||||
put :update, :id => "37", :mash => {:these => 'params'}
|
||||
end
|
||||
|
||||
it "assigns the mash as @mash" do
|
||||
Mash.stub(:find).and_return(mock_mash(:update_attributes => false))
|
||||
put :update, :id => "1"
|
||||
assigns[:mash].should equal(mock_mash)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
Mash.stub(:find).and_return(mock_mash(:update_attributes => false))
|
||||
put :update, :id => "1"
|
||||
response.should render_template('edit')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys the requested mash" do
|
||||
Mash.should_receive(:find).with("37").and_return(mock_mash)
|
||||
mock_mash.should_receive(:destroy)
|
||||
delete :destroy, :id => "37"
|
||||
end
|
||||
|
||||
it "redirects to the mashes list" do
|
||||
Mash.stub(:find).and_return(mock_mash(:destroy => true))
|
||||
delete :destroy, :id => "1"
|
||||
response.should redirect_to(mashes_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
13
rails/map-mash/spec/fixtures/mashes.yml
vendored
Normal file
13
rails/map-mash/spec/fixtures/mashes.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
requester: MyString
|
||||
map_a: 1
|
||||
map_b: 1
|
||||
winner: 1
|
||||
|
||||
two:
|
||||
requester: MyString
|
||||
map_a: 1
|
||||
map_b: 1
|
||||
winner: 1
|
11
rails/map-mash/spec/helpers/mashes_helper_spec.rb
Normal file
11
rails/map-mash/spec/helpers/mashes_helper_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MashesHelper do
|
||||
|
||||
#Delete this example and add some real ones or delete this file
|
||||
it "is included in the helper object" do
|
||||
included_modules = (class << helper; self; end).send :included_modules
|
||||
included_modules.should include(MashesHelper)
|
||||
end
|
||||
|
||||
end
|
4
rails/map-mash/spec/integration/mashes_spec.rb
Normal file
4
rails/map-mash/spec/integration/mashes_spec.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Mashes" do
|
||||
end
|
13
rails/map-mash/spec/models/map_spec.rb
Normal file
13
rails/map-mash/spec/models/map_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Map do
|
||||
before(:each) do
|
||||
@valid_attributes = {
|
||||
:name => "value for name"
|
||||
}
|
||||
end
|
||||
|
||||
it "should create a new instance given valid attributes" do
|
||||
Map.create!(@valid_attributes)
|
||||
end
|
||||
end
|
33
rails/map-mash/spec/routing/mashes_routing_spec.rb
Normal file
33
rails/map-mash/spec/routing/mashes_routing_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MashesController do
|
||||
describe "routing" do
|
||||
it "recognizes and generates #index" do
|
||||
{ :get => "/mashes" }.should route_to(:controller => "mashes", :action => "index")
|
||||
end
|
||||
|
||||
it "recognizes and generates #new" do
|
||||
{ :get => "/mashes/new" }.should route_to(:controller => "mashes", :action => "new")
|
||||
end
|
||||
|
||||
it "recognizes and generates #show" do
|
||||
{ :get => "/mashes/1" }.should route_to(:controller => "mashes", :action => "show", :id => "1")
|
||||
end
|
||||
|
||||
it "recognizes and generates #edit" do
|
||||
{ :get => "/mashes/1/edit" }.should route_to(:controller => "mashes", :action => "edit", :id => "1")
|
||||
end
|
||||
|
||||
it "recognizes and generates #create" do
|
||||
{ :post => "/mashes" }.should route_to(:controller => "mashes", :action => "create")
|
||||
end
|
||||
|
||||
it "recognizes and generates #update" do
|
||||
{ :put => "/mashes/1" }.should route_to(:controller => "mashes", :action => "update", :id => "1")
|
||||
end
|
||||
|
||||
it "recognizes and generates #destroy" do
|
||||
{ :delete => "/mashes/1" }.should route_to(:controller => "mashes", :action => "destroy", :id => "1")
|
||||
end
|
||||
end
|
||||
end
|
26
rails/map-mash/spec/views/mashes/edit.html.erb_spec.rb
Normal file
26
rails/map-mash/spec/views/mashes/edit.html.erb_spec.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/mashes/edit.html.erb" do
|
||||
include MashesHelper
|
||||
|
||||
before(:each) do
|
||||
assigns[:mash] = @mash = stub_model(Mash,
|
||||
:new_record? => false,
|
||||
:requester => "value for requester",
|
||||
:map_a => 1,
|
||||
:map_b => 1,
|
||||
:winner => 1
|
||||
)
|
||||
end
|
||||
|
||||
it "renders the edit mash form" do
|
||||
render
|
||||
|
||||
response.should have_tag("form[action=#{mash_path(@mash)}][method=post]") do
|
||||
with_tag('input#mash_requester[name=?]', "mash[requester]")
|
||||
with_tag('input#mash_map_a[name=?]', "mash[map_a]")
|
||||
with_tag('input#mash_map_b[name=?]', "mash[map_b]")
|
||||
with_tag('input#mash_winner[name=?]', "mash[winner]")
|
||||
end
|
||||
end
|
||||
end
|
30
rails/map-mash/spec/views/mashes/index.html.erb_spec.rb
Normal file
30
rails/map-mash/spec/views/mashes/index.html.erb_spec.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/mashes/index.html.erb" do
|
||||
include MashesHelper
|
||||
|
||||
before(:each) do
|
||||
assigns[:mashes] = [
|
||||
stub_model(Mash,
|
||||
:requester => "value for requester",
|
||||
:map_a => 1,
|
||||
:map_b => 1,
|
||||
:winner => 1
|
||||
),
|
||||
stub_model(Mash,
|
||||
:requester => "value for requester",
|
||||
:map_a => 1,
|
||||
:map_b => 1,
|
||||
:winner => 1
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
it "renders a list of mashes" do
|
||||
render
|
||||
response.should have_tag("tr>td", "value for requester".to_s, 2)
|
||||
response.should have_tag("tr>td", 1.to_s, 2)
|
||||
response.should have_tag("tr>td", 1.to_s, 2)
|
||||
response.should have_tag("tr>td", 1.to_s, 2)
|
||||
end
|
||||
end
|
26
rails/map-mash/spec/views/mashes/new.html.erb_spec.rb
Normal file
26
rails/map-mash/spec/views/mashes/new.html.erb_spec.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/mashes/new.html.erb" do
|
||||
include MashesHelper
|
||||
|
||||
before(:each) do
|
||||
assigns[:mash] = stub_model(Mash,
|
||||
:new_record? => true,
|
||||
:requester => "value for requester",
|
||||
:map_a => 1,
|
||||
:map_b => 1,
|
||||
:winner => 1
|
||||
)
|
||||
end
|
||||
|
||||
it "renders new mash form" do
|
||||
render
|
||||
|
||||
response.should have_tag("form[action=?][method=post]", mashes_path) do
|
||||
with_tag("input#mash_requester[name=?]", "mash[requester]")
|
||||
with_tag("input#mash_map_a[name=?]", "mash[map_a]")
|
||||
with_tag("input#mash_map_b[name=?]", "mash[map_b]")
|
||||
with_tag("input#mash_winner[name=?]", "mash[winner]")
|
||||
end
|
||||
end
|
||||
end
|
21
rails/map-mash/spec/views/mashes/show.html.erb_spec.rb
Normal file
21
rails/map-mash/spec/views/mashes/show.html.erb_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/mashes/show.html.erb" do
|
||||
include MashesHelper
|
||||
before(:each) do
|
||||
assigns[:mash] = @mash = stub_model(Mash,
|
||||
:requester => "value for requester",
|
||||
:map_a => 1,
|
||||
:map_b => 1,
|
||||
:winner => 1
|
||||
)
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
response.should have_text(/value\ for\ requester/)
|
||||
response.should have_text(/1/)
|
||||
response.should have_text(/1/)
|
||||
response.should have_text(/1/)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user