Actually mashing maps now, but not handling form post-back or making it pretty
This commit is contained in:
126
rails/map-mash/spec/controllers/maps_controller_spec.rb
Normal file
126
rails/map-mash/spec/controllers/maps_controller_spec.rb
Normal file
@@ -0,0 +1,126 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MapsController do
|
||||
|
||||
def mock_map(stubs={})
|
||||
@mock_map ||= mock_model(Map, stubs)
|
||||
end
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns all maps as @maps" do
|
||||
Map.stub(:find).with(:all).and_return([mock_map])
|
||||
get :index
|
||||
assigns[:maps].should == [mock_map]
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new map as @map" do
|
||||
Map.stub(:new).and_return(mock_map)
|
||||
get :new
|
||||
assigns[:map].should equal(mock_map)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested map as @map" do
|
||||
Map.stub(:find).with("37").and_return(mock_map)
|
||||
get :edit, :id => "37"
|
||||
assigns[:map].should equal(mock_map)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST create" do
|
||||
|
||||
describe "with valid params" do
|
||||
it "assigns a newly created map as @map" do
|
||||
Map.stub(:new).with({'these' => 'params'}).and_return(mock_map(:save => true))
|
||||
post :create, :map => {:these => 'params'}
|
||||
assigns[:map].should equal(mock_map)
|
||||
end
|
||||
|
||||
it "redirects to the created map" do
|
||||
Map.stub(:new).and_return(mock_map(:save => true))
|
||||
post :create, :map => {}
|
||||
response.should redirect_to(map_url(mock_map))
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns a newly created but unsaved map as @map" do
|
||||
Map.stub(:new).with({'these' => 'params'}).and_return(mock_map(:save => false))
|
||||
post :create, :map => {:these => 'params'}
|
||||
assigns[:map].should equal(mock_map)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
Map.stub(:new).and_return(mock_map(:save => false))
|
||||
post :create, :map => {}
|
||||
response.should render_template('new')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "PUT update" do
|
||||
|
||||
describe "with valid params" do
|
||||
it "updates the requested map" do
|
||||
Map.should_receive(:find).with("37").and_return(mock_map)
|
||||
mock_map.should_receive(:update_attributes).with({'these' => 'params'})
|
||||
put :update, :id => "37", :map => {:these => 'params'}
|
||||
end
|
||||
|
||||
it "assigns the requested map as @map" do
|
||||
Map.stub(:find).and_return(mock_map(:update_attributes => true))
|
||||
put :update, :id => "1"
|
||||
assigns[:map].should equal(mock_map)
|
||||
end
|
||||
|
||||
it "redirects to the map" do
|
||||
Map.stub(:find).and_return(mock_map(:update_attributes => true))
|
||||
put :update, :id => "1"
|
||||
response.should redirect_to(map_url(mock_map))
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "updates the requested map" do
|
||||
Map.should_receive(:find).with("37").and_return(mock_map)
|
||||
mock_map.should_receive(:update_attributes).with({'these' => 'params'})
|
||||
put :update, :id => "37", :map => {:these => 'params'}
|
||||
end
|
||||
|
||||
it "assigns the map as @map" do
|
||||
Map.stub(:find).and_return(mock_map(:update_attributes => false))
|
||||
put :update, :id => "1"
|
||||
assigns[:map].should equal(mock_map)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
Map.stub(:find).and_return(mock_map(:update_attributes => false))
|
||||
put :update, :id => "1"
|
||||
response.should render_template('edit')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys the requested map" do
|
||||
Map.should_receive(:find).with("37").and_return(mock_map)
|
||||
mock_map.should_receive(:destroy)
|
||||
delete :destroy, :id => "37"
|
||||
end
|
||||
|
||||
it "redirects to the maps list" do
|
||||
Map.stub(:find).and_return(mock_map(:destroy => true))
|
||||
delete :destroy, :id => "1"
|
||||
response.should redirect_to(maps_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
7
rails/map-mash/spec/fixtures/maps.yml
vendored
Normal file
7
rails/map-mash/spec/fixtures/maps.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
name: MyString
|
11
rails/map-mash/spec/helpers/maps_helper_spec.rb
Normal file
11
rails/map-mash/spec/helpers/maps_helper_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MapsHelper 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(MapsHelper)
|
||||
end
|
||||
|
||||
end
|
4
rails/map-mash/spec/integration/maps_spec.rb
Normal file
4
rails/map-mash/spec/integration/maps_spec.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Maps" do
|
||||
end
|
33
rails/map-mash/spec/routing/maps_routing_spec.rb
Normal file
33
rails/map-mash/spec/routing/maps_routing_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MapsController do
|
||||
describe "routing" do
|
||||
it "recognizes and generates #index" do
|
||||
{ :get => "/maps" }.should route_to(:controller => "maps", :action => "index")
|
||||
end
|
||||
|
||||
it "recognizes and generates #new" do
|
||||
{ :get => "/maps/new" }.should route_to(:controller => "maps", :action => "new")
|
||||
end
|
||||
|
||||
it "recognizes and generates #show" do
|
||||
{ :get => "/maps/1" }.should route_to(:controller => "maps", :action => "show", :id => "1")
|
||||
end
|
||||
|
||||
it "recognizes and generates #edit" do
|
||||
{ :get => "/maps/1/edit" }.should route_to(:controller => "maps", :action => "edit", :id => "1")
|
||||
end
|
||||
|
||||
it "recognizes and generates #create" do
|
||||
{ :post => "/maps" }.should route_to(:controller => "maps", :action => "create")
|
||||
end
|
||||
|
||||
it "recognizes and generates #update" do
|
||||
{ :put => "/maps/1" }.should route_to(:controller => "maps", :action => "update", :id => "1")
|
||||
end
|
||||
|
||||
it "recognizes and generates #destroy" do
|
||||
{ :delete => "/maps/1" }.should route_to(:controller => "maps", :action => "destroy", :id => "1")
|
||||
end
|
||||
end
|
||||
end
|
20
rails/map-mash/spec/views/maps/edit.html.erb_spec.rb
Normal file
20
rails/map-mash/spec/views/maps/edit.html.erb_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/maps/edit.html.erb" do
|
||||
include MapsHelper
|
||||
|
||||
before(:each) do
|
||||
assigns[:map] = @map = stub_model(Map,
|
||||
:new_record? => false,
|
||||
:name => "value for name"
|
||||
)
|
||||
end
|
||||
|
||||
it "renders the edit map form" do
|
||||
render
|
||||
|
||||
response.should have_tag("form[action=#{map_path(@map)}][method=post]") do
|
||||
with_tag('input#map_name[name=?]', "map[name]")
|
||||
end
|
||||
end
|
||||
end
|
21
rails/map-mash/spec/views/maps/index.html.erb_spec.rb
Normal file
21
rails/map-mash/spec/views/maps/index.html.erb_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/maps/index.html.erb" do
|
||||
include MapsHelper
|
||||
|
||||
before(:each) do
|
||||
assigns[:maps] = [
|
||||
stub_model(Map,
|
||||
:name => "value for name"
|
||||
),
|
||||
stub_model(Map,
|
||||
:name => "value for name"
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
it "renders a list of maps" do
|
||||
render
|
||||
response.should have_tag("tr>td", "value for name".to_s, 2)
|
||||
end
|
||||
end
|
20
rails/map-mash/spec/views/maps/new.html.erb_spec.rb
Normal file
20
rails/map-mash/spec/views/maps/new.html.erb_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/maps/new.html.erb" do
|
||||
include MapsHelper
|
||||
|
||||
before(:each) do
|
||||
assigns[:map] = stub_model(Map,
|
||||
:new_record? => true,
|
||||
:name => "value for name"
|
||||
)
|
||||
end
|
||||
|
||||
it "renders new map form" do
|
||||
render
|
||||
|
||||
response.should have_tag("form[action=?][method=post]", maps_path) do
|
||||
with_tag("input#map_name[name=?]", "map[name]")
|
||||
end
|
||||
end
|
||||
end
|
15
rails/map-mash/spec/views/maps/show.html.erb_spec.rb
Normal file
15
rails/map-mash/spec/views/maps/show.html.erb_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "/maps/show.html.erb" do
|
||||
include MapsHelper
|
||||
before(:each) do
|
||||
assigns[:map] = @map = stub_model(Map,
|
||||
:name => "value for name"
|
||||
)
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
response.should have_text(/value\ for\ name/)
|
||||
end
|
||||
end
|
@@ -1,26 +0,0 @@
|
||||
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
|
Reference in New Issue
Block a user