Add basic order cycle API

This commit is contained in:
Rob H
2014-03-05 12:00:26 +11:00
parent 9f19e91e90
commit fc65eefcfd
5 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
module Api
class OrderCyclesController < Spree::Api::BaseController
respond_to :json
def managed
@order_cycles = OrderCycle.ransack(params[:q]).result.managed_by(current_api_user)
render :bulk_index
end
end
end

View File

@@ -0,0 +1,2 @@
collection @order_cycles
extends "api/order_cycles/bulk_show"

View File

@@ -0,0 +1,3 @@
object @order_cycle
attributes :id, :name

View File

@@ -50,6 +50,12 @@ Openfoodnetwork::Application.routes.draw do
end
end
namespace :api do
resources :order_cycles do
get :managed, on: :collection
end
end
get "new_landing_page", :controller => 'home', :action => "new_landing_page"
get "darkswarm", controller: :darkswarm, action: :index
get "about_us", :controller => 'home', :action => "about_us"

View File

@@ -0,0 +1,26 @@
require 'spec_helper'
require 'spree/api/testing_support/helpers'
module Api
describe OrderCyclesController do
include Spree::Api::TestingSupport::Helpers
render_views
let!(:oc1) { FactoryGirl.create(:order_cycle) }
let!(:oc2) { FactoryGirl.create(:order_cycle) }
let(:attributes) { [:id, :name] }
before do
stub_authentication!
Spree.user_class.stub :find_by_spree_api_key => current_api_user
end
context "as a normal user" do
it "retrieves a list of variants with appropriate attributes" do
get :managed, { :format => :json }
keys = json_response.first.keys.map{ |key| key.to_sym }
attributes.all?{ |attr| keys.include? attr }.should == true
end
end
end
end