diff --git a/lib/graphiti/resource/persistence.rb b/lib/graphiti/resource/persistence.rb index 5a1c61a9..9840f413 100644 --- a/lib/graphiti/resource/persistence.rb +++ b/lib/graphiti/resource/persistence.rb @@ -76,10 +76,10 @@ def assign(assign_params, meta = nil, action_name = nil) run_callbacks :attributes, action_name, assign_params, meta do |params| model_instance = if action_name != :create && id - self.class._find(id: id).data - else - call_with_meta(:build, model, meta) - end + self.class._find(id: id).data + else + call_with_meta(:build, model, meta) + end call_with_meta(:assign_attributes, model_instance, params, meta) model_instance end diff --git a/lib/graphiti/resource_proxy.rb b/lib/graphiti/resource_proxy.rb index fc3abee3..0ccb8890 100644 --- a/lib/graphiti/resource_proxy.rb +++ b/lib/graphiti/resource_proxy.rb @@ -81,8 +81,8 @@ def data end end - alias to_a data - alias resolve_data data + alias_method :to_a, :data + alias_method :resolve_data, :data def meta @meta ||= data.respond_to?(:meta) ? data.meta : {} diff --git a/lib/graphiti/serializer.rb b/lib/graphiti/serializer.rb index 95a8950a..5583f38b 100644 --- a/lib/graphiti/serializer.rb +++ b/lib/graphiti/serializer.rb @@ -98,7 +98,7 @@ def strip_relationships!(hash) end def strip_relationships? - return false unless Graphiti.config.links_on_demand + return false unless Graphiti.config.links_on_demand params = Graphiti.context[:object].try(:params) || {} [false, nil, "false"].include?(params[:links]) diff --git a/spec/integration/rails/callbacks_spec.rb b/spec/integration/rails/callbacks_spec.rb index 51da826a..893b9853 100644 --- a/spec/integration/rails/callbacks_spec.rb +++ b/spec/integration/rails/callbacks_spec.rb @@ -35,7 +35,7 @@ class ApplicationResource < Graphiti::Resource class EmployeeResource < ApplicationResource self.model = Employee - self.type= "employees" + self.type = "employees" before_attributes :one before_attributes :two @@ -208,7 +208,7 @@ def params { data: { type: "employees", - attributes: { first_name: "Jane"} + attributes: {first_name: "Jane"} } } end @@ -244,16 +244,14 @@ def params describe "update callbacks" do let!(:employee) { Employee.create!(first_name: "asdf") } let(:payload) { - { id: employee.id, - data: { - id: employee.id, - type: 'employees', - attributes: { first_name: "Jane" } - } - } + {id: employee.id, + data: { + id: employee.id, + type: "employees", + attributes: {first_name: "Jane"} + }} } - it "fires hooks in order" do expect { put :update, params: payload diff --git a/spec/support/rails/employee_controller.rb b/spec/support/rails/employee_controller.rb index 8ef6313c..5ed045fc 100644 --- a/spec/support/rails/employee_controller.rb +++ b/spec/support/rails/employee_controller.rb @@ -15,7 +15,7 @@ def create def update employee = resource.find(params) - + if employee.update_attributes render jsonapi: employee else