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 +4 -4
- data/lib/standard_api/controller.rb +6 -10
- data/lib/standard_api/test_case/create_tests.rb +5 -4
- data/lib/standard_api/test_case/index_tests.rb +5 -5
- data/lib/standard_api/test_case/show_tests.rb +3 -3
- data/lib/standard_api/test_case/update_tests.rb +4 -4
- data/lib/standard_api/views/application/index.json.jbuilder +1 -3
- data/lib/standard_api/views/application/show.json.jbuilder +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61260c1422929988e5901869095a597b5b8df66b
|
4
|
+
data.tar.gz: 3e056ce5197af2755862368afb6ec75fbfd202d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
46
|
-
|
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
|
-
|
52
|
-
|
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(
|
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(
|
78
|
-
assert_equal json[included.to_s][key.to_s], normalize_to_json(assigns(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
63
|
-
message = "Model / Attribute: #{assigns(
|
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(
|
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
|