Controller spec api improvements

This commit is contained in:
2014-12-02 19:24:09 +01:00
parent 60e6b2a648
commit a0774caeff
7 changed files with 61 additions and 164 deletions
@@ -104,7 +104,7 @@ module Suppliers
@tables = current_supplier.active_tables
render action: "new"
end
format.json { render json: @list.errors, status: :unprocessable_entity }
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
end
end
end
@@ -123,13 +123,10 @@ module Suppliers
respond_to do |format|
if @list.update_attributes(list_params)
format.html { redirect_to [:suppliers, @list], notice: t('action.update.successfull', model: List.model_name.human) }
format.json { head :no_content }
format.js { head :no_content }
format.json { render json: @list }
else
@tables = current_supplier.active_tables
format.html { render action: "edit" }
format.json { render json: @list.errors, status: :unprocessable_entity }
format.js { head :no_content }
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
end
end
end
@@ -149,7 +146,7 @@ module Suppliers
private
def list_params
params.require(:list).permit(:state, :needs_help, :needs_payment, :closed_at, :join_requests, :price, :is_paid, :paid_at, :table_id, :section_id)
params.require(:list).permit(:state, :needs_help, :needs_payment, :closed_at, :join_requests, :price, :is_paid, :paid_at, :table_id, :section_id, :foo)
end
end
end
@@ -61,7 +61,7 @@ module Suppliers
format.json { render json: @section, serializer: SupplierSectionSerializer, status: :created }
else
format.html { render action: "new" }
format.json { render json: @section.errors, status: :unprocessable_entity }
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
end
end
end
@@ -77,7 +77,7 @@ module Suppliers
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @section.errors, status: :unprocessable_entity }
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
end
end
end
+1 -1
View File
@@ -17,7 +17,7 @@ class Table
validates :supplier_id, presence: true
#validates :list_id, presence: true
validates :number, numericality: {greater_than: 0}
validates :number, numericality: true #{greater_than: 0}
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
view :by_supplier_id_and_number, key: [:supplier_id, :number]