spree_api 1.3.5 → 2.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +14 -6
  2. data/Rakefile +1 -1
  3. data/app/controllers/spree/api/addresses_controller.rb +0 -1
  4. data/app/controllers/spree/api/base_controller.rb +21 -9
  5. data/app/controllers/spree/api/checkouts_controller.rb +40 -20
  6. data/app/controllers/spree/api/countries_controller.rb +0 -1
  7. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  8. data/app/controllers/spree/api/option_types_controller.rb +46 -0
  9. data/app/controllers/spree/api/option_values_controller.rb +56 -0
  10. data/app/controllers/spree/api/orders_controller.rb +1 -21
  11. data/app/controllers/spree/api/product_properties_controller.rb +0 -1
  12. data/app/controllers/spree/api/products_controller.rb +12 -27
  13. data/app/controllers/spree/api/properties_controller.rb +61 -0
  14. data/app/controllers/spree/api/shipments_controller.rb +51 -1
  15. data/app/controllers/spree/api/states_controller.rb +32 -0
  16. data/app/controllers/spree/api/stock_items_controller.rb +70 -0
  17. data/app/controllers/spree/api/stock_locations_controller.rb +45 -0
  18. data/app/controllers/spree/api/stock_movements_controller.rb +55 -0
  19. data/app/controllers/spree/api/taxonomies_controller.rb +5 -0
  20. data/app/controllers/spree/api/taxons_controller.rb +16 -2
  21. data/app/controllers/spree/api/variants_controller.rb +1 -1
  22. data/app/controllers/spree/api/zones_controller.rb +0 -1
  23. data/app/helpers/spree/api/api_helpers.rb +34 -7
  24. data/app/models/spree/api_configuration.rb +1 -2
  25. data/app/models/spree/line_item_decorator.rb +1 -1
  26. data/app/models/spree/order_decorator.rb +6 -169
  27. data/app/overrides/api_admin_user_edit_form.rb +7 -6
  28. data/app/views/spree/admin/users/_api_fields.html.erb +7 -8
  29. data/app/views/spree/api/addresses/show.v1.rabl +2 -2
  30. data/app/views/spree/api/adjustments/show.v1.rabl +2 -0
  31. data/app/views/spree/api/credit_cards/show.v1.rabl +2 -0
  32. data/app/views/spree/api/option_types/index.v1.rabl +3 -0
  33. data/app/views/spree/api/option_types/show.v1.rabl +5 -0
  34. data/app/views/spree/api/option_values/index.v1.rabl +3 -0
  35. data/app/views/spree/api/option_values/show.v1.rabl +2 -0
  36. data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +2 -0
  37. data/app/views/spree/api/orders/delivery.v1.rabl +2 -2
  38. data/app/views/spree/api/orders/payment.v1.rabl +3 -0
  39. data/app/views/spree/api/orders/show.v1.rabl +8 -0
  40. data/app/views/spree/api/properties/index.v1.rabl +7 -0
  41. data/app/views/spree/api/properties/new.v1.rabl +2 -0
  42. data/app/views/spree/api/properties/show.v1.rabl +2 -0
  43. data/app/views/spree/api/shared/stock_location_required.v1.rabl +2 -0
  44. data/app/views/spree/api/shipments/show.v1.rabl +7 -0
  45. data/app/views/spree/api/states/index.v1.rabl +14 -0
  46. data/app/views/spree/api/states/show.v1.rabl +2 -0
  47. data/app/views/spree/api/stock_items/index.v1.rabl +7 -0
  48. data/app/views/spree/api/stock_items/show.v1.rabl +5 -0
  49. data/app/views/spree/api/stock_locations/index.v1.rabl +7 -0
  50. data/app/views/spree/api/stock_locations/show.v1.rabl +8 -0
  51. data/app/views/spree/api/stock_movements/index.v1.rabl +7 -0
  52. data/app/views/spree/api/stock_movements/show.v1.rabl +5 -0
  53. data/app/views/spree/api/taxonomies/jstree.rabl +8 -0
  54. data/app/views/spree/api/taxons/jstree.rabl +8 -0
  55. data/app/views/spree/api/variants/index.v1.rabl +14 -1
  56. data/app/views/spree/api/variants/variant.v1.rabl +0 -4
  57. data/config/locales/en.yml +1 -0
  58. data/config/routes.rb +29 -3
  59. data/lib/spree/api.rb +0 -2
  60. data/lib/spree/api/controller_setup.rb +6 -1
  61. data/lib/spree/api/testing_support/helpers.rb +1 -1
  62. data/lib/spree/api/testing_support/setup.rb +13 -0
  63. data/spec/controllers/spree/api/base_controller_spec.rb +14 -1
  64. data/spec/controllers/spree/api/checkouts_controller_spec.rb +59 -28
  65. data/spec/controllers/spree/api/line_items_controller_spec.rb +1 -5
  66. data/spec/controllers/spree/api/option_types_controller_spec.rb +116 -0
  67. data/spec/controllers/spree/api/option_values_controller_spec.rb +128 -0
  68. data/spec/controllers/spree/api/orders_controller_spec.rb +11 -93
  69. data/spec/controllers/spree/api/product_properties_controller_spec.rb +2 -2
  70. data/spec/controllers/spree/api/products_controller_spec.rb +18 -76
  71. data/spec/controllers/spree/api/properties_controller_spec.rb +89 -0
  72. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +1 -9
  73. data/spec/controllers/spree/api/shipments_controller_spec.rb +80 -5
  74. data/spec/controllers/spree/api/states_controller_spec.rb +76 -0
  75. data/spec/controllers/spree/api/stock_items_controller_spec.rb +88 -0
  76. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +86 -0
  77. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +72 -0
  78. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +7 -0
  79. data/spec/controllers/spree/api/taxons_controller_spec.rb +29 -2
  80. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -1
  81. data/spec/controllers/spree/api/variants_controller_spec.rb +5 -16
  82. data/spec/fixtures/thinking-cat.jpg +0 -0
  83. data/spec/models/spree/order_spec.rb +7 -328
  84. data/spec/spec_helper.rb +18 -2
  85. data/spree_api.gemspec +2 -1
  86. metadata +67 -16
  87. data/.rspec +0 -1
  88. data/app/controllers/spree/base_controller_decorator.rb +0 -15
  89. data/app/overrides/api_key_spree_layout.rb +0 -7
  90. data/app/views/spree/api/_key.html.erb +0 -4
  91. data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -1,6 +1,7 @@
1
- Deface::Override.new(:virtual_path => "spree/admin/users/edit",
2
- :name => "api_admin_user_edit_form",
3
- :insert_after => "[data-hook='admin_user_edit_general_settings']",
4
- :partial => "spree/admin/users/api_fields",
5
- :disabled => false)
6
-
1
+ if defined?(Deface)
2
+ Deface::Override.new(:virtual_path => "spree/admin/users/edit",
3
+ :name => "api_admin_user_edit_form",
4
+ :insert_after => "[data-hook='admin_user_edit_general_settings']",
5
+ :partial => "spree/admin/users/api_fields",
6
+ :disabled => false)
7
+ end
@@ -1,32 +1,31 @@
1
1
  <fieldset data-hook="admin_user_api_key" class="omega six columns">
2
- <legend><%= t('access', :scope => 'spree.api') %></legend>
2
+ <legend><%= Spree.t('access', :scope => 'api') %></legend>
3
3
 
4
4
  <% if @user.spree_api_key.present? %>
5
5
  <div class="field">
6
- <%= label_tag t('key', :scope => 'spree.api') %>:
6
+ <%= label_tag Spree.t('key', :scope => 'api') %>:
7
7
  <%= @user.spree_api_key %>
8
8
  </div>
9
9
  <div class="filter-actions actions">
10
10
  <%= form_tag spree.clear_api_key_admin_user_path(@user), :method => :put do %>
11
- <%= button t('clear_key', :scope => 'spree.api'), 'icon-trash' %>
11
+ <%= button Spree.t('clear_key', :scope => 'api'), 'icon-trash' %>
12
12
  <% end %>
13
13
 
14
- <span class="or"><%= t(:or)%></span>
14
+ <span class="or"><%= Spree.t(:or)%></span>
15
15
 
16
16
  <%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
17
- <%= button t('regenerate_key', :scope => 'spree.api'), 'icon-refresh' %>
17
+ <%= button Spree.t('regenerate_key', :scope => 'api'), 'icon-refresh' %>
18
18
  <% end %>
19
19
  </div>
20
20
 
21
21
  <% else %>
22
22
 
23
- <div class="no-objects-found"><%= t('no_key', :scope => 'spree.api') %></div>
23
+ <div class="no-objects-found"><%= Spree.t('no_key', :scope => 'api') %></div>
24
24
 
25
25
  <div class="filter-actions actions">
26
26
  <%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
27
- <%= button t('generate_key', :scope => 'spree.api'), 'icon-key' %>
27
+ <%= button Spree.t('generate_key', :scope => 'api'), 'icon-key' %>
28
28
  <% end %>
29
29
  </div>
30
30
  <% end %>
31
-
32
31
  </fieldset>
@@ -4,8 +4,8 @@ attributes :id, :firstname, :lastname, :address1, :address2,
4
4
  :company, :alternative_phone, :country_id, :state_id,
5
5
  :state_name
6
6
  child(:country) do |address|
7
- attributes :id, :iso_name, :iso, :iso3, :name, :numcode
7
+ attributes *country_attributes
8
8
  end
9
9
  child(:state) do |address|
10
- attributes :abbr, :country_id, :id, :name
10
+ attributes *state_attributes
11
11
  end
@@ -0,0 +1,2 @@
1
+ object @adjustment
2
+ attributes *adjustment_attributes
@@ -0,0 +1,2 @@
1
+ object @credit_card
2
+ attributes *creditcard_attributes
@@ -0,0 +1,3 @@
1
+ collection @option_types
2
+
3
+ extends "spree/api/option_types/show"
@@ -0,0 +1,5 @@
1
+ object @option_type
2
+ attributes *option_type_attributes
3
+ child :option_values => :option_values do
4
+ attributes *option_value_attributes
5
+ end
@@ -0,0 +1,3 @@
1
+ collection @option_values
2
+
3
+ extends "spree/api/option_values/show"
@@ -0,0 +1,2 @@
1
+ object @option_value
2
+ attributes *option_value_attributes
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { @coupon_message }
@@ -1,3 +1,3 @@
1
- child(:rate_hash => :shipping_methods) do
2
- attributes :id, :name, :cost
1
+ child(:shipments => :shipments) do
2
+ extends "spree/api/shipments/show"
3
3
  end
@@ -0,0 +1,3 @@
1
+ child :available_payment_methods => :payment_methods do
2
+ attributes :id, :name, :environment
3
+ end
@@ -27,3 +27,11 @@ end
27
27
  child :shipments => :shipments do
28
28
  extends "spree/api/shipments/show"
29
29
  end
30
+
31
+ child :adjustments => :adjustments do
32
+ extends "spree/api/adjustments/show"
33
+ end
34
+
35
+ child :credit_cards => :credit_cards do
36
+ extends "spree/api/credit_cards/show"
37
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@properties => :properties) do
3
+ attributes *property_attributes
4
+ end
5
+ node(:count) { @properties.count }
6
+ node(:current_page) { params[:page] || 1 }
7
+ node(:pages) { @properties.num_pages }
@@ -0,0 +1,2 @@
1
+ node(:attributes) { [*property_attributes] }
2
+ node(:required_attributes) { [] }
@@ -0,0 +1,2 @@
1
+ object @property
2
+ attributes *property_attributes
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:stock_location_required, scope: "spree.api") }
@@ -1,7 +1,14 @@
1
1
  object @shipment
2
2
  attributes *shipment_attributes
3
3
  node(:order_id) { |shipment| shipment.order.number }
4
+ node(:stock_location_name) { |shipment| shipment.stock_location.name }
5
+ child :shipping_rates => :shipping_rates do
6
+ attributes :id, :cost, :selected, :shipment_id, :shipping_method_id
7
+ end
4
8
  child :shipping_method => :shipping_method do
5
9
  attributes :name, :zone_id, :shipping_category_id
6
10
  end
7
11
 
12
+ child :inventory_units => :inventory_units do
13
+ attribute *inventory_unit_attributes
14
+ end
@@ -0,0 +1,14 @@
1
+ object false
2
+ if @country
3
+ node(:states_required) { @country.states_required }
4
+ end
5
+
6
+ child(@states => :states) do
7
+ attributes *state_attributes
8
+ end
9
+
10
+ if @states.respond_to?(:num_pages)
11
+ node(:count) { @states.count }
12
+ node(:current_page) { params[:page] || 1 }
13
+ node(:pages) { @states.num_pages }
14
+ end
@@ -0,0 +1,2 @@
1
+ object @state
2
+ attributes *state_attributes
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@stock_items => :stock_items) do
3
+ extends 'spree/api/stock_items/show'
4
+ end
5
+ node(:count) { @stock_items.count }
6
+ node(:current_page) { params[:page] || 1 }
7
+ node(:pages) { @stock_items.num_pages }
@@ -0,0 +1,5 @@
1
+ object @stock_item
2
+ attributes *stock_item_attributes
3
+ child(:variant) do
4
+ extends "spree/api/variants/variant"
5
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@stock_locations => :stock_locations) do
3
+ extends 'spree/api/stock_locations/show'
4
+ end
5
+ node(:count) { @stock_locations.count }
6
+ node(:current_page) { params[:page] || 1 }
7
+ node(:pages) { @stock_locations.num_pages }
@@ -0,0 +1,8 @@
1
+ object @stock_location
2
+ attributes *stock_location_attributes
3
+ child(:country) do |address|
4
+ attributes *country_attributes
5
+ end
6
+ child(:state) do |address|
7
+ attributes *state_attributes
8
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@stock_movements => :stock_movements) do
3
+ extends 'spree/api/stock_movements/show'
4
+ end
5
+ node(:count) { @stock_movements.count }
6
+ node(:current_page) { params[:page] || 1 }
7
+ node(:pages) { @stock_movements.num_pages }
@@ -0,0 +1,5 @@
1
+ object @stock_movement
2
+ attributes *stock_movement_attributes
3
+ child :stock_item do
4
+ extends "spree/api/stock_items/show"
5
+ end
@@ -0,0 +1,8 @@
1
+ object false
2
+ node(:data) { @taxonomy.root.name }
3
+ node(:attr) do
4
+ { :id => @taxonomy.root.id,
5
+ :name => @taxonomy.root.name
6
+ }
7
+ end
8
+ node(:state) { "closed" }
@@ -0,0 +1,8 @@
1
+ collection @taxon.children, :object_root => false
2
+ node(:data) { |taxon| taxon.name }
3
+ node(:attr) do |taxon|
4
+ { :id => taxon.id,
5
+ :name => taxon.name
6
+ }
7
+ end
8
+ node(:state) { "closed" }
@@ -7,5 +7,18 @@ node(:pages) { @variants.num_pages }
7
7
  child(@variants => :variants) do
8
8
  attributes *variant_attributes
9
9
  child(:option_values => :option_values) { attributes *option_value_attributes }
10
- child(:images => :images) { extends "spree/api/images/show" }
10
+ child(:images => :images) do
11
+ attributes *image_attributes
12
+ code(:urls) do |v|
13
+ v.attachment.styles.keys.inject({}) { |urls, style| urls[style] = v.attachment.url(style); urls }
14
+ end
15
+ end
16
+
17
+ child(:stock_items) do
18
+ attributes :id, :count_on_hand, :stock_location_id, :backorderable
19
+
20
+ glue(:stock_location) do
21
+ attribute :name => :stock_location_name
22
+ end
23
+ end
11
24
  end
@@ -1,5 +1 @@
1
1
  attributes *variant_attributes
2
- node(:options_text) { |v| v.options_text }
3
- child :option_values => :option_values do
4
- attributes *option_value_attributes
5
- end
@@ -21,4 +21,5 @@ en:
21
21
  invalid_shipping_method: "Invalid shipping method specified."
22
22
  shipment:
23
23
  cannot_ready: "Cannot ready shipment."
24
+ stock_location_required: "A stock_location_id parameter must be provided in order to retrieve stock movements."
24
25
  invalid_taxonomy_id: "Invalid taxonomy id."
data/config/routes.rb CHANGED
@@ -15,10 +15,19 @@ Spree::Core::Engine.routes.draw do
15
15
  end
16
16
 
17
17
  resources :images
18
- resources :checkouts
18
+ resources :checkouts do
19
+ member do
20
+ put :next
21
+ end
22
+ end
23
+
19
24
  resources :variants, :only => [:index] do
20
25
  end
21
26
 
27
+ resources :option_types do
28
+ resources :option_values
29
+ end
30
+
22
31
  resources :orders do
23
32
  resources :return_authorizations
24
33
  member do
@@ -39,21 +48,38 @@ Spree::Core::Engine.routes.draw do
39
48
  end
40
49
  end
41
50
 
42
- resources :shipments do
51
+ resources :shipments, :only => [:create, :update] do
43
52
  member do
44
53
  put :ready
45
54
  put :ship
55
+ put :add
56
+ put :remove
46
57
  end
47
58
  end
48
59
  end
49
60
 
50
61
  resources :zones
51
62
  resources :countries, :only => [:index, :show]
63
+ resources :states, :only => [:index, :show]
52
64
  resources :addresses, :only => [:show, :update]
65
+
53
66
  resources :taxonomies do
54
- resources :taxons
67
+ member do
68
+ get :jstree
69
+ end
70
+ resources :taxons do
71
+ member do
72
+ get :jstree
73
+ end
74
+ end
55
75
  end
76
+ resources :taxons, :only => [:index]
56
77
  resources :inventory_units, :only => [:show, :update]
57
78
  resources :users
79
+ resources :properties
80
+ resources :stock_locations do
81
+ resources :stock_movements
82
+ resources :stock_items
83
+ end
58
84
  end
59
85
  end
data/lib/spree/api.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'spree/core'
2
2
 
3
- require 'spree/api/controller_setup'
4
-
5
3
  require 'rabl'
6
4
 
7
5
  module Spree
@@ -1,3 +1,5 @@
1
+ require 'spree/api/responders'
2
+
1
3
  module Spree
2
4
  module Api
3
5
  module ControllerSetup
@@ -14,12 +16,15 @@ module Spree
14
16
  include ActionController::ImplicitRender
15
17
  include ActionController::Rescue
16
18
  include ActionController::MimeResponds
19
+ include ActionController::Head
17
20
 
18
21
  include CanCan::ControllerAdditions
19
- include SslRequirement
22
+ include Spree::Core::ControllerHelpers::Auth
23
+
20
24
  prepend_view_path Rails.root + "app/views"
21
25
  append_view_path File.expand_path("../../../app/views", File.dirname(__FILE__))
22
26
 
27
+ self.responder = Spree::Api::Responders::AppResponder
23
28
  respond_to :json
24
29
  end
25
30
  end
@@ -12,7 +12,7 @@ module Spree
12
12
  end
13
13
 
14
14
  def stub_authentication!
15
- controller.stub :check_for_api_key
15
+ controller.stub :check_for_user_or_api_key
16
16
  Spree::LegacyUser.stub :find_by_spree_api_key => current_api_user
17
17
  end
18
18
 
@@ -9,6 +9,19 @@ module Spree
9
9
  user
10
10
  end
11
11
  end
12
+
13
+ # Default kaminari's pagination to a certain range
14
+ # Means that you don't need to create 25 objects to test pagination
15
+ def default_per_page(count)
16
+ before do
17
+ @current_default_per_page = Kaminari.config.default_per_page
18
+ Kaminari.config.default_per_page = 1
19
+ end
20
+
21
+ after do
22
+ Kaminari.config.default_per_page = @current_default_per_page
23
+ end
24
+ end
12
25
  end
13
26
  end
14
27
  end
@@ -4,7 +4,20 @@ describe Spree::Api::BaseController do
4
4
  render_views
5
5
  controller(Spree::Api::BaseController) do
6
6
  def index
7
- render :json => { "products" => [] }
7
+ render :text => { "products" => [] }.to_json
8
+ end
9
+ end
10
+
11
+ context "signed in as a user using an authentication extension" do
12
+ before do
13
+ controller.stub :try_spree_current_user => stub(:email => "spree@example.com")
14
+ Spree::Api::Config[:requires_authentication] = true
15
+ end
16
+
17
+ it "can make a request" do
18
+ api_get :index
19
+ json_response.should == { "products" => [] }
20
+ response.status.should == 200
8
21
  end
9
22
  end
10
23