poisol 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/poisol/config_map.rb +3 -3
- data/lib/poisol/template/base_template.rb +4 -1
- data/lib/poisol/template/response_handler.rb +42 -9
- data/spec/functional/array_spec.rb +9 -8
- data/spec/functional/get_spec.rb +6 -6
- data/spec/functional/nested_array_spec.rb +20 -8
- 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: 102174b8f05e7b43926297e717bc76c7c3b81d46
|
4
|
+
data.tar.gz: 829318caf733df87e6f9c26c2980c6bc6b3d08d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c62558579d2916b39ec215446b895fed0917c99cd75dd4c9bae47722df202f78f167d0bf1f5159a214c3e40b01063ee3610048323765f33c43aeda8b695e087c
|
7
|
+
data.tar.gz: 290dcda3d475dfcd579ad959b44c885ae93e42229eb577a101a57fac5137a5b661b07c37658fa16d276378e13370d7123748c9845d92007cc2c926055c443924
|
data/lib/poisol/config_map.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class ConfigMap
|
2
|
-
|
2
|
+
@config_file_map = {}
|
3
3
|
|
4
4
|
def self.add map
|
5
|
-
|
5
|
+
@config_file_map.update map
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.file class_name
|
9
|
-
|
9
|
+
@config_file_map[class_name]
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module ClassTemplate
|
2
|
+
attr_accessor :response_body
|
2
3
|
|
3
4
|
def initialize
|
4
5
|
@config = ConfigMap.file self.class.name
|
@@ -29,7 +30,9 @@ module ClassTemplate
|
|
29
30
|
stub = stub_request(@type, "http://#{Domain.base_url}/#{@url}")
|
30
31
|
stub.with(:query => @query) unless @query.eql? ""
|
31
32
|
stub.with(:body => @request_body) unless @request_body.eql? ""
|
32
|
-
|
33
|
+
if @config.response.array_type == "column_array"
|
34
|
+
@response_body = Parse.hash_array_to_column_hash(@response_body)
|
35
|
+
end
|
33
36
|
stub.to_return(:status => 200, :body => @response_body.to_s, :headers => {})
|
34
37
|
end
|
35
38
|
|
@@ -39,23 +39,56 @@ module ClassTemplate
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def generate_methods_to_alter_response_object
|
42
|
-
@response_body = @config.response.body
|
42
|
+
@response_body = @config.response.body.clone
|
43
43
|
@response_body.each do |field|
|
44
44
|
field_name = field[0]
|
45
45
|
actual_field_value = field[1]
|
46
46
|
is_array = (actual_field_value.class.to_s == "Array")
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
input_value = input_value[0]
|
52
|
-
assignment_value = get_assignment_value actual_field_value,input_value
|
53
|
-
@response_body[field_name] = is_array ? (@response_body[field_name] << assignment_value) : assignment_value
|
54
|
-
self
|
47
|
+
if is_array
|
48
|
+
generate_method_to_alter_response_field_array field_name,actual_field_value
|
49
|
+
else
|
50
|
+
generate_method_to_alter_response_field field_name,actual_field_value
|
55
51
|
end
|
52
|
+
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
56
|
+
def generate_method_to_alter_response_field_array field_name,actual_field_values
|
57
|
+
actual_field_value = actual_field_values[0]
|
58
|
+
method_name = "has_#{field_name.classify.underscore}"
|
59
|
+
define_singleton_method(method_name) do |*input_value|
|
60
|
+
input_value = input_value[0]
|
61
|
+
assignment_value = get_assignment_value actual_field_value,input_value
|
62
|
+
@response_body[field_name] = [assignment_value]
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
method_name = "has_another_#{field_name.classify.underscore}"
|
67
|
+
define_singleton_method(method_name) do |*input_value|
|
68
|
+
input_value = input_value[0]
|
69
|
+
assignment_value = get_assignment_value actual_field_value,input_value
|
70
|
+
@response_body[field_name] = @response_body[field_name] << assignment_value
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
method_name = "has_no_#{field_name.classify.underscore}"
|
75
|
+
define_singleton_method(method_name) do
|
76
|
+
@response_body[field_name] = []
|
77
|
+
self
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def generate_method_to_alter_response_field field_name,actual_field_value
|
82
|
+
method_name = "has_#{field_name.underscore}"
|
83
|
+
self.class.send(:define_method, method_name) do |*input_value|
|
84
|
+
input_value = input_value[0]
|
85
|
+
assignment_value = get_assignment_value actual_field_value,input_value
|
86
|
+
@response_body[field_name] = assignment_value
|
87
|
+
self
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
59
92
|
def get_assignment_value actual_field_value,input_value
|
60
93
|
if actual_field_value.class.to_s == "Hash"
|
61
94
|
input_value = {} if input_value.blank?
|
@@ -1,14 +1,20 @@
|
|
1
1
|
describe ClassTemplate, "#array" do
|
2
2
|
|
3
|
+
it "empty column array" do
|
4
|
+
Columns.new.build
|
5
|
+
response = RestClient.get "http://localhost:80/column"
|
6
|
+
expect(response.body).to eq("[]")
|
7
|
+
end
|
8
|
+
|
3
9
|
it "column array" do
|
4
10
|
Columns.new.has_column.has_column.with_title("abc").with_category("12").build
|
5
11
|
response = RestClient.get "http://localhost:80/column"
|
6
12
|
expect(response.body).to eq({"title"=>["independance", "abc"], "category"=>["10","12"]}.to_s)
|
7
13
|
end
|
8
14
|
|
9
|
-
it "empty
|
10
|
-
|
11
|
-
response = RestClient.get "http://localhost:80/
|
15
|
+
it "empty row array" do
|
16
|
+
Rows.new.build
|
17
|
+
response = RestClient.get "http://localhost:80/row"
|
12
18
|
expect(response.body).to eq("[]")
|
13
19
|
end
|
14
20
|
|
@@ -18,10 +24,5 @@ describe ClassTemplate, "#array" do
|
|
18
24
|
expect(response.body).to eq([{"title"=>"independance", "category"=>{"age_group"=>"10"}}, {"title"=>"abc", "category"=>{"age_group"=>"12"}}].to_s)
|
19
25
|
end
|
20
26
|
|
21
|
-
it "empty row array" do
|
22
|
-
Rows.new.build
|
23
|
-
response = RestClient.get "http://localhost:80/row"
|
24
|
-
expect(response.body).to eq("[]")
|
25
|
-
end
|
26
27
|
|
27
28
|
end
|
data/spec/functional/get_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
describe ClassTemplate, "#get_books" do
|
2
2
|
|
3
|
-
it "default request and response" do
|
4
|
-
Book.new.build()
|
5
|
-
response = RestClient.get "http://localhost:80/book",{:params => {:author=>'bharathi'}}
|
6
|
-
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.to_s)
|
7
|
-
end
|
8
|
-
|
9
3
|
it "dynamic response" do
|
10
4
|
Book.new.has_category({"age_group"=>"11", "publisher"=>{"name"=>"oxford"}}).build()
|
11
5
|
response = RestClient.get "http://localhost:80/book",{:params => {:author=>'bharathi'}}
|
12
6
|
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"11", "genre"=>"action", "publisher"=>{"name"=>"oxford", "place"=>"erode"}}}.to_s)
|
13
7
|
end
|
14
8
|
|
9
|
+
it "default request and response" do
|
10
|
+
Book.new.build()
|
11
|
+
response = RestClient.get "http://localhost:80/book",{:params => {:author=>'bharathi'}}
|
12
|
+
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.to_s)
|
13
|
+
end
|
14
|
+
|
15
15
|
end
|
16
16
|
|
@@ -1,19 +1,31 @@
|
|
1
1
|
describe ClassTemplate, "#nested array" do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
it "empty" do
|
4
|
+
NestedArray.new.has_no_role.build()
|
5
|
+
response = RestClient.get "http://localhost:80/nested_array"
|
6
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[]}.to_s)
|
7
|
+
end
|
8
8
|
|
9
|
-
it "
|
9
|
+
it "without mentioning field" do
|
10
|
+
NestedArray.new.build()
|
11
|
+
response = RestClient.get "http://localhost:80/nested_array"
|
12
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"}]}.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "mentioning one field" do
|
10
16
|
NestedArray.new.has_role.build()
|
11
17
|
response = RestClient.get "http://localhost:80/nested_array"
|
12
18
|
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"}]}.to_s)
|
13
19
|
end
|
14
20
|
|
15
|
-
it "
|
16
|
-
NestedArray.new.has_role
|
21
|
+
it "mentioning one field with altered values" do
|
22
|
+
NestedArray.new.has_role("role_id"=>"test1").build()
|
23
|
+
response = RestClient.get "http://localhost:80/nested_array"
|
24
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"test1", "role_name"=>"sol"}]}.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "multiple fields with altered values" do
|
28
|
+
NestedArray.new.has_role.has_another_role("role_id"=>"test").build()
|
17
29
|
response = RestClient.get "http://localhost:80/nested_array"
|
18
30
|
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"},{"role_id"=>"test", "role_name"=>"sol"}]}.to_s)
|
19
31
|
end
|