From fc65eefcfddd9d7912a824cdc7d674cd5f07bf90 Mon Sep 17 00:00:00 2001 From: Rob H Date: Wed, 5 Mar 2014 12:00:26 +1100 Subject: [PATCH] Add basic order cycle API --- .../api/order_cycles_controller.rb | 10 +++++++ app/views/api/order_cycles/bulk_index.v1.rabl | 2 ++ app/views/api/order_cycles/bulk_show.v1.rabl | 3 +++ config/routes.rb | 6 +++++ .../api/order_cycles_controller_spec.rb | 26 +++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 app/controllers/api/order_cycles_controller.rb create mode 100644 app/views/api/order_cycles/bulk_index.v1.rabl create mode 100644 app/views/api/order_cycles/bulk_show.v1.rabl create mode 100644 spec/controllers/api/order_cycles_controller_spec.rb diff --git a/app/controllers/api/order_cycles_controller.rb b/app/controllers/api/order_cycles_controller.rb new file mode 100644 index 0000000000..89c815ea3c --- /dev/null +++ b/app/controllers/api/order_cycles_controller.rb @@ -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 + \ No newline at end of file diff --git a/app/views/api/order_cycles/bulk_index.v1.rabl b/app/views/api/order_cycles/bulk_index.v1.rabl new file mode 100644 index 0000000000..22923d69c0 --- /dev/null +++ b/app/views/api/order_cycles/bulk_index.v1.rabl @@ -0,0 +1,2 @@ +collection @order_cycles +extends "api/order_cycles/bulk_show" diff --git a/app/views/api/order_cycles/bulk_show.v1.rabl b/app/views/api/order_cycles/bulk_show.v1.rabl new file mode 100644 index 0000000000..7acffca853 --- /dev/null +++ b/app/views/api/order_cycles/bulk_show.v1.rabl @@ -0,0 +1,3 @@ +object @order_cycle + +attributes :id, :name \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 76c192dc67..4fa61e8754 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/spec/controllers/api/order_cycles_controller_spec.rb b/spec/controllers/api/order_cycles_controller_spec.rb new file mode 100644 index 0000000000..3524aafc94 --- /dev/null +++ b/spec/controllers/api/order_cycles_controller_spec.rb @@ -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 \ No newline at end of file