diff options
| author | Marc Florisson | 2012-12-03 17:14:25 +0100 | 
|---|---|---|
| committer | Marc Florisson | 2012-12-03 17:14:25 +0100 | 
| commit | b07166f27d64a4847ab2a1c439cb94b522b876e4 (patch) | |
| tree | 888684a427895a5363e33ec4a4ad8bd8e2c984d4 /spec/controllers/api/v1 | |
| parent | 966a9f62b3ffd8029c0104cee0d63d98582d95d9 (diff) | |
| download | chouette-core-b07166f27d64a4847ab2a1c439cb94b522b876e4.tar.bz2 | |
add some specs
Diffstat (limited to 'spec/controllers/api/v1')
| -rw-r--r-- | spec/controllers/api/v1/networks_controller_spec.rb | 71 | 
1 files changed, 71 insertions, 0 deletions
| diff --git a/spec/controllers/api/v1/networks_controller_spec.rb b/spec/controllers/api/v1/networks_controller_spec.rb new file mode 100644 index 000000000..3047d2b63 --- /dev/null +++ b/spec/controllers/api/v1/networks_controller_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + + +describe Api::V1::NetworksController do +  let!(:organisation) {Organisation.find_by_name("first") || create(:organisation, :name => "first")} +  let!(:referential) {Referential.find_by_name("first") || create(:referential, :organisation => organisation)} +  let!(:network) {referential.networks.where(:name => "first") || create(:network, :referential => referential)} + +  context "no authorization provided" do +    it "should return HTTP 401" do +      get :index +      response.response_code.should == 401 +    end +  end +  context "an invalid authorization is provided" do +    before(@each) do +      @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials("dummy") +    end +    it "should return HTTP 401" do +      get :index +      response.response_code.should == 401 +    end +  end +  context "a valid authorization is provided" do +    let!(:api_key) {Api::V1::ApiKey.create( organisation, referential)} + +    before(@each) do +      request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials( api_key.token) +      request.accept = "application/json" +    end +    it "should assign expected api_key" do +      get :index +      assigns[:api_key].should eql(api_key)  +    end +    it "should assign expected referential" do +      get :index +      assigns[:referential].should == api_key.referential +    end +    it "should assign referntial's networks" do +      get :index +      assigns[:networks].should == api_key.referential.networks +    end +    context "the request format is HTML" do +      before(@each) do +        request.accept = "application/html" +      end +      it "should return HTTP 406" do +        get :index +        response.response_code.should == 406 +      end +    end +    context "the request format is XML" do +      before(@each) do +        request.accept = "application/xml" +      end +      it "should return HTTP 200" do +        get :index +        response.response_code.should == 200 +      end +    end +    context "the request format is JSON" do +      before(@each) do +        request.accept = "application/json" +      end +      it "should return HTTP 200" do +        get :index +        response.response_code.should == 200 +      end +    end +  end +end | 
