Skip to content
databyte edited this page Jun 28, 2012 · 10 revisions

Check out these resources:

In a nutshell be sure to use render_views to get tests passing:

describe ApplicationsController do
  render_views

  let(:model) { Factory.create(:model) }

  subject { model }

  context "JSON" do

    describe "creating a new model" do
      context "when not authorized" do
        it "should not allow creation of an application" do
          json = { :format => 'json', :model => { :name => "foo", :description => "bar" } }

          post :create, json

          Application.count.should == 0
          response.status.should eq(403)
          JSON.parse(response.body)["status"] == "error"
          JSON.parse(response.body)["message"] =~ /authorized/
        end 
      end 
    end

  end
end