standardapi 1.0.15 → 1.0.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f892bfaae15d0e0561eedcf89269ff98d18f2044
4
- data.tar.gz: c9e734b482f12719dae0b6da8d384aadf64ac02c
3
+ metadata.gz: 61260c1422929988e5901869095a597b5b8df66b
4
+ data.tar.gz: 3e056ce5197af2755862368afb6ec75fbfd202d6
5
5
  SHA512:
6
- metadata.gz: 3c749360b6a4ceb688dbb0914bccf1c0d4680304a682e1fd57bd7a221552a8731ae3c93fd5f15de2ea6f4f46ae0c1101cc8ca652392553d795799e1f9d873061
7
- data.tar.gz: 548a8a618e9769b88ba0bab84e921ab0fdd4e36a8c04b3f7cc8958f1927c3e689c29b512f6398402e247363ed4b5090e4c5a7840ef9282c794516ae0d8541e68
6
+ metadata.gz: 3832b69251900970b8eaab0b4960581b09c0889278fb77968c2305c52384eafc3f320061fdced9f8fbece289f230cda0b5d0ef72fd4a7cd0e0f4e87400e60d83
7
+ data.tar.gz: cd87f79b7107332b2189c8bf12428aae328ebfa4a64e7dc20aac43d5a06fa176c69ca385f8a9288efc9b5808280e31e1fb6174a51adf8f108020de6bfb2cbeb3
@@ -21,8 +21,7 @@ module StandardAPI
21
21
  end
22
22
 
23
23
  def index
24
- @records = resources.limit(params[:limit]).offset(params[:offset]).sort(orders)
25
- instance_variable_set("@#{model.model_name.plural}", @records)
24
+ instance_variable_set("@#{model.model_name.plural}", resources.limit(params[:limit]).offset(params[:offset]).sort(orders))
26
25
  end
27
26
 
28
27
  def calculate
@@ -37,20 +36,17 @@ module StandardAPI
37
36
  end
38
37
 
39
38
  def show
40
- @record = resources.find(params[:id])
41
- instance_variable_set("@#{model.model_name.singular}", @record)
39
+ instance_variable_set("@#{model.model_name.singular}", resources.find(params[:id]))
42
40
  end
43
41
 
44
42
  def create
45
- @record = model.new(model_params)
46
- instance_variable_set("@#{model.model_name.singular}", @record)
47
- render :show, status: @record.save ? :created : :bad_request
43
+ instance_variable_set("@#{model.model_name.singular}", model.new(model_params))
44
+ render :show, status: instance_variable_get("@#{model.model_name.singular}").save ? :created : :bad_request
48
45
  end
49
46
 
50
47
  def update
51
- @record = resources.find(params[:id])
52
- instance_variable_set("@#{model.model_name.singular}", @record)
53
- render :show, status: @record.update_attributes(model_params) ? :ok : :bad_request
48
+ instance_variable_set("@#{model.model_name.singular}", resources.find(params[:id]))
49
+ render :show, status: instance_variable_get("@#{model.model_name.singular}").update_attributes(model_params) ? :ok : :bad_request
54
50
  end
55
51
 
56
52
  def destroy
@@ -34,6 +34,7 @@ module StandardAPI
34
34
 
35
35
  json = JSON.parse(response.body)
36
36
  assert json.is_a?(Hash)
37
+
37
38
  m = assigns(singular_name).reload
38
39
  view_attributes(m).select { |x| attrs.keys.map(&:to_s).include?(x) }.each do |key, value|
39
40
  message = "Model / Attribute: #{m.class.name}##{key}"
@@ -70,15 +71,15 @@ module StandardAPI
70
71
  includes.each do |included|
71
72
  assert json.key?(included.to_s), "#{included.inspect} not included in response"
72
73
 
73
- association = assigns(:record).class.reflect_on_association(included)
74
+ association = assigns(singular_name).class.reflect_on_association(included)
74
75
  next if !association
75
76
 
76
77
  if ['belongs_to', 'has_one'].include?(association.macro.to_s)
77
- view_attributes(assigns(:record).send(included)) do |key, value|
78
- assert_equal json[included.to_s][key.to_s], normalize_to_json(assigns(:record), key, value)
78
+ view_attributes(assigns(singular_name).send(included)) do |key, value|
79
+ assert_equal json[included.to_s][key.to_s], normalize_to_json(assigns(singular_name), key, value)
79
80
  end
80
81
  else
81
- m = assigns(:record).send(included).first.try(:reload)
82
+ m = assigns(singular_name).send(included).first.try(:reload)
82
83
 
83
84
  m_json = if m && m.has_attribute?(:id)
84
85
  json[included.to_s].find { |x| x['id'] == normalize_to_json(m, :id, m.id) }
@@ -26,13 +26,13 @@ module StandardAPI
26
26
  orders.each do |order|
27
27
  @controller.instance_variable_set('@orders', nil) # Hack for dealing with caching / multiple request per controller life
28
28
  get :index, order: order, format: 'json'
29
- assert_equal model.sort(order).to_sql, assigns(:records).to_sql
29
+ assert_equal model.sort(order).to_sql, assigns(plural_name).to_sql
30
30
  end
31
31
  end
32
32
 
33
33
  test '#index.json params[:offset]' do
34
34
  get :index, offset: 13, format: 'json'
35
- assert_equal model.offset(13).to_sql, assigns(:records).to_sql
35
+ assert_equal model.offset(13).to_sql, assigns(plural_name).to_sql
36
36
  end
37
37
 
38
38
  test '#index.json params[:include]' do
@@ -45,17 +45,17 @@ module StandardAPI
45
45
  includes.each do |included|
46
46
  assert json.key?(included.to_s), "#{included.inspect} not included in response"
47
47
 
48
- association = assigns(:records).first.class.reflect_on_association(included)
48
+ association = assigns(plural_name).first.class.reflect_on_association(included)
49
49
  next if !association
50
50
 
51
51
  if ['belongs_to', 'has_one'].include?(association.macro.to_s)
52
- m = assigns(:records).first.send(included)
52
+ m = assigns(plural_name).first.send(included)
53
53
  view_attributes(m) do |key, value|
54
54
  message = "Model / Attribute: #{m.class.name}##{key}"
55
55
  assert_equal json[included.to_s][key.to_s], normalize_to_json(m, key, value), message
56
56
  end
57
57
  else
58
- m = assigns(:records).first.send(included).first.try(:reload)
58
+ m = assigns(plural_name).first.send(included).first.try(:reload)
59
59
 
60
60
  m_json = if m && m.has_attribute?(:id)
61
61
  json[included.to_s].find { |x| x['id'] == normalize_to_json(m, :id, m.id) }
@@ -21,15 +21,15 @@ module StandardAPI
21
21
  includes.each do |included|
22
22
  assert json.key?(included.to_s), "#{included.inspect} not included in response"
23
23
 
24
- association = assigns(:record).class.reflect_on_association(included)
24
+ association = assigns(singular_name).class.reflect_on_association(included)
25
25
  next if !association
26
26
 
27
27
  if ['belongs_to', 'has_one'].include?(association.macro.to_s)
28
- view_attributes(assigns(:record).send(included)) do |key, value|
28
+ view_attributes(assigns(singular_name).send(included)) do |key, value|
29
29
  assert_equal json[included.to_s][key.to_s], value
30
30
  end
31
31
  else
32
- m = assigns(:record).send(included).first.try(:reload)
32
+ m = assigns(singular_name).send(included).first.try(:reload)
33
33
 
34
34
  m_json = if m && m.has_attribute?(:id)
35
35
  json[included.to_s].find { |x| x['id'] == normalize_to_json(m, :id, m.id) }
@@ -55,16 +55,16 @@ module StandardAPI
55
55
  includes.each do |included|
56
56
  assert json.key?(included.to_s), "#{included.inspect} not included in response"
57
57
 
58
- association = assigns(:record).class.reflect_on_association(included)
58
+ association = assigns(singular_name).class.reflect_on_association(included)
59
59
  next if !association
60
60
 
61
61
  if ['belongs_to', 'has_one'].include?(association.macro.to_s)
62
- view_attributes(assigns(:record).send(included)) do |key, value|
63
- message = "Model / Attribute: #{assigns(:record).send(included).class.name}##{key}"
62
+ view_attributes(assigns(singular_name).send(included)) do |key, value|
63
+ message = "Model / Attribute: #{assigns(singular_name).send(included).class.name}##{key}"
64
64
  assert_equal json[included.to_s][key.to_s], value, message
65
65
  end
66
66
  else
67
- m = assigns(:record).send(included).first.try(:reload)
67
+ m = assigns(singular_name).send(included).first.try(:reload)
68
68
  m_json = if m && m.has_attribute?(:id)
69
69
  json[included.to_s].find { |x| x['id'] == normalize_to_json(m, :id, m.id) }
70
70
  elsif m
@@ -1,3 +1 @@
1
- records = @records if !records
2
-
3
- json.array! records, partial: model_partial(model), as: :record, includes: includes
1
+ json.array! instance_variable_get("@#{model.model_name.plural}"), partial: model_partial(model), as: :record, includes: includes
@@ -1,3 +1 @@
1
- record = @record if !record
2
-
3
- json.partial! model_partial(model), record: record, includes: includes
1
+ json.partial! model_partial(model), record: instance_variable_get("@#{model.model_name.singular}"), includes: includes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standardapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bracy