Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'spec_helper'

describe Api::V1::StoresController do
  let(:mock_user) { mock_model(User, :to_param => ':user_id').as_null_object }
  let(:mock_store) { mock_model(Store, :to_param => ':id').as_null_object }

  shared_examples_for "succesful assigment and response with json" do
    it { response.should be_success }
    it { response.content_type.should eq("application/json") }
    it { should assign_to(:store).with(mock_store) }
    it { assigns[:store].should equal(mock_store) }
  end    

  context "GET index" do
    it "should get json" do
      User.stub(:find).with("37").and_return(mock_user)
      get :index, :format => :json, :user_id => "37"
      should assign_to(:stores)
      respond_with(:success)
      respond_with_content_type(:json)
    end
  end

  context "GET /user/:user_id/stores/:id" do
    before do
      Store.stub(:find).with("18").and_return(mock_store)
      User.stub(:find).with("37").and_return(mock_user)
      get :show, :format => :json, :id => "18", :user_id => "37"
    end

    it_should_behave_like "succesful assigment and response with json"
  end

  context "POST :create" do
    describe "with valid params" do
      let(:params) { {:these => 'params'} }
      before do
        User.stub(:find).and_return(mock_user)
        Store.stub(:new).with({'these' => 'params'}).and_return(mock_store(:save => true))
        post :create, :user_id => "37", :store => params, :format => :json
      end 

      it_should_behave_like "succesful assigment and response with json"
    end
  end
end