0

我以以下格式向我的 API 发送请求

http://server/url?v=HEAD&access_token=TOKEN

我的问题是如何在控制器规范中的请求中附加v参数和access_token参数?

以下是我到目前为止的示例。它都不起作用:

describe Api::ShopsController do
  let(:application) { Doorkeeper::Application.create(:name => "MyApp", :redirect_uri => "http://app.com") }
  let(:user)        { FactoryGirl.create(:user) }
  let(:token)       { Doorkeeper::AccessToken.create! :application_id => application.id, :resource_owner_id => user.id }

  describe "GET #index" do
    it "should respond with 200" do
      get :index, :format => :json, :access_token => token.token
      response.status.should eq(200)
    end

    it "should list all shops" do
      Shop.should_receive(:all) { [] }
      get :index, :format => :json, :access_token => token.token
      response.body.should == [].to_json
    end
  end

  # Example url: localhost:3000/shops/1?v=HEAD&access_token=TOKEN
  describe "GET show" do
    it 'responds with 200' do
      shop = Shop.create! FactoryGirl.attributes_for :shop
      get :show, {id: shop.id, :access_token => access_token.token, v: "HEAD"}, :format => :json 
      response.status.should eq(200)
    end

    it "returns the requested shop" do
      shop = Shop.create! FactoryGirl.attributes_for :shop
      get :show, {:id => user.to_param}, :format => :json, :access_token => token.token
      assigns(:user).should eq(user)
  end
end
4

1 回答 1

0

你试过这个吗?

get shop_path(id: shop.id, v: 'HEAD', access_token: token.token, format: :json)
于 2014-07-12T02:09:14.067 回答