poisol 0.0.5 → 0.0.6

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: ab045c2db93e3a33c6e1600cd750e705570d8fb8
4
- data.tar.gz: 7ff62860c55c2aa5d14ed1bc23d5aed18b5263ab
3
+ metadata.gz: d0b8aceb83226c0a5ab960181449ee1c97222aad
4
+ data.tar.gz: 3e9a45c5b4a17d5495f619b5019cbadde2f228f1
5
5
  SHA512:
6
- metadata.gz: 4c443130b5f4301c78c50f5b4548d72f6ea4b80c09b667b2f650dacb1eb5d125e24da914c9e0d5d7df070bc817b324c4bf34d45491947f37c9674f84a30b9d0a
7
- data.tar.gz: 497f8874d31157962385508373fc65a342d6ad111bdcdc971f754c6c1cb6d07bd9ae46da9d79bbe1e2fb1e30351b43a552e7ec617830840762f5cccb73026c6f
6
+ metadata.gz: 5949c61a61ae33352d30dd4619bc2fa3357c69afc570dd1a761d0d446b6dd8ce3c558e9e3d9121c3f093440f50c634e23af8e06011a3ebb02ff8b9c72cbb9264
7
+ data.tar.gz: 8b034551be7568755e2f0d5f2165e20a31d60874426b9d71aae41b3add80268d2d9f0b16122320989879c6b48c6e4c1a68992d531e17c2a8cfde67ef5ddf32f1
@@ -2,8 +2,8 @@ class StubConfig
2
2
  attr_reader :response,:request
3
3
 
4
4
  def with_file file_name
5
- @config_file = file_name
6
- @config = Parse.yaml_file file_name
5
+ @config_yml_file = file_name
6
+ @config_yml = Parse.yaml_file file_name
7
7
  self
8
8
  end
9
9
 
@@ -26,9 +26,11 @@ class StubConfig
26
26
  private
27
27
  def build_request
28
28
  @request = Request.new
29
- @request.url = @config["request"]["url"]
30
- @request.type = @config["request"]["type"].intern
31
- @request.query = @config["request"]["query"]
29
+ @request.url = @config_yml["request"]["url"]
30
+ @request.type = @config_yml["request"]["type"].intern
31
+ @request.query = @config_yml["request"]["query"]
32
+ include_explicit_only = @config_yml["request"]["include_explicit_only"]
33
+ @request.include_explicit_only = include_explicit_only.blank? ? false : include_explicit_only
32
34
  @request.body = @is_inline? get_inline_request_body : get_exploaded_request_body
33
35
  end
34
36
 
@@ -39,29 +41,36 @@ class StubConfig
39
41
  end
40
42
 
41
43
  def handle_resonse_array_type
42
- return if @config["response"].nil?
43
- array_type = @config["response"]["array_type"]
44
+ return if @config_yml["response"].nil?
45
+ array_type = @config_yml["response"]["array_type"]
44
46
  @response.array_type = array_type.nil? ? "" : array_type
45
47
  end
46
48
 
47
49
 
48
50
  def get_inline_response_body
49
- body = @config["response"]["body"]
51
+ body = @config_yml["response"]["body"]
50
52
  return (body.nil?) ? "": (Parse.json_to_hash body)
51
53
  end
52
54
 
53
55
  def get_inline_request_body
54
- body = @config["request"]["body"]
55
- return (body.nil?) ? "": (Parse.json_to_hash body)
56
+ body = @config_yml["request"]["body"]
57
+ if body.nil?
58
+ return ""
59
+ elsif body.class.name == "String"
60
+ return Parse.json_to_hash body
61
+ else
62
+ @request.is_body_key_value = true
63
+ return body
64
+ end
56
65
  end
57
66
 
58
67
  def get_exploaded_request_body
59
- request_file = "#{File.dirname @config_file}/request.json"
68
+ request_file = "#{File.dirname @config_yml_file}/request.json"
60
69
  return (File.exists? request_file) ? Parse.json_file_to_hash(request_file) : ""
61
70
  end
62
71
 
63
72
  def get_exploaded_response_body
64
- response_file = "#{File.dirname @config_file}/response.json"
73
+ response_file = "#{File.dirname @config_yml_file}/response.json"
65
74
  return (File.exists? response_file)? Parse.json_file_to_hash(response_file) : ""
66
75
  end
67
76
 
@@ -69,7 +78,7 @@ end
69
78
 
70
79
 
71
80
  class Request
72
- attr_accessor :url,:type,:query,:body
81
+ attr_accessor :url,:type,:query,:body,:is_body_key_value,:include_explicit_only
73
82
  end
74
83
 
75
84
  class Response
@@ -19,22 +19,11 @@ module ClassTemplate
19
19
  end
20
20
 
21
21
  def prepare_request_query
22
- @query = (@config.request.query.nil?) ? "" : generate_query_methods
22
+ generate_query_methods if @config.request.query.present?
23
23
  end
24
24
 
25
25
  def prepare_request_body
26
- @request_body = @config.request.body == "" ? "" : generate_request_methods
27
- end
28
-
29
- def build
30
- remove_path_param_name_from_url
31
- stub = stub_request(@type, "http://#{Domain.base_url}/#{@url}")
32
- stub.with(:query => @query) unless @query.eql? ""
33
- stub.with(:body => @request_body) unless @request_body.eql? ""
34
- if @config.response.array_type == "column_array"
35
- @response_body = Parse.hash_array_to_column_hash(@response_body)
36
- end
37
- stub.to_return(:status => 200, :body => @response_body.to_s, :headers => {})
26
+ generate_request_methods if @config.request.body.present?
38
27
  end
39
28
 
40
29
  end
@@ -0,0 +1,31 @@
1
+ module ClassTemplate
2
+ def build
3
+ build_url
4
+ build_query
5
+ build_request_body
6
+ build_response_body
7
+ end
8
+
9
+ def build_url
10
+ remove_path_param_name_from_url
11
+ @stub = stub_request(@type, "http://#{Domain.base_url}/#{@url}")
12
+ end
13
+
14
+ def build_query
15
+ @stub.with(:query => @query) unless @query.eql? ""
16
+ end
17
+
18
+ def build_request_body
19
+ return if @request_body.blank?
20
+ @request_body = Parse.hash_to_concatenated_key_value(@request_body) if @config.request.is_body_key_value
21
+ @stub.with(:body => @request_body)
22
+ end
23
+
24
+ def build_response_body
25
+ if @config.response.array_type == "column_array"
26
+ @response_body = Parse.hash_array_to_column_hash(@response_body)
27
+ end
28
+ @stub.to_return(:status => 200, :body => @response_body.to_s, :headers => {})
29
+ end
30
+ end
31
+
@@ -1,12 +1,14 @@
1
1
  module ClassTemplate
2
- def generate_request_methods
3
- @request_body = @config.request.body
4
- return if @request_body.nil?
5
- @request_body.each do |field|
6
- define_singleton_method("by_#{field[0].underscore}") do |*value|
7
- @request_body[field[0]] = value[0]
8
- self
9
- end
2
+ def generate_request_methods
3
+ @request_body = @config.request.body.deep_dup
4
+ return if @request_body.nil?
5
+ @request_body.each do |field|
6
+ field_name = field[0]
7
+ define_singleton_method("by_#{field[0].underscore}") do |*value|
8
+ @request_body[field_name] = value[0]
9
+ self
10
10
  end
11
11
  end
12
+ @request_body = {} if @config.request.include_explicit_only
13
+ end
12
14
  end
@@ -19,7 +19,15 @@ class Parse
19
19
  hash_array.each do |hash|
20
20
  column_hash.each_key {|key| column_hash[key].append hash[key]}
21
21
  end
22
- return column_hash
22
+ column_hash
23
+ end
24
+
25
+ def self.hash_to_concatenated_key_value hash
26
+ concatenated_body = ""
27
+ hash.each do |key,value|
28
+ concatenated_body = concatenated_body + "#{key}=#{value}&"
29
+ end
30
+ concatenated_body.chomp('&')
23
31
  end
24
32
 
25
33
  end
@@ -0,0 +1,15 @@
1
+ describe ClassTemplate, "#key_value" do
2
+
3
+ it "partial dynamic request" do
4
+ Explicit.new.by_name("ram").build()
5
+ response = RestClient.post "http://localhost:80/explicit","name=ram"
6
+ expect(response.body).to eq({"hi"=>1}.to_s)
7
+ end
8
+
9
+ it "dynamic request" do
10
+ Explicit.new.by_name("ram").by_age(11).build()
11
+ response = RestClient.post "http://localhost:80/explicit","name=ram&age=11"
12
+ expect(response.body).to eq({"hi"=>1}.to_s)
13
+ end
14
+
15
+ end
@@ -0,0 +1,21 @@
1
+ describe ClassTemplate, "#key_value" do
2
+
3
+ it "default request" do
4
+ KeyValue.new.build()
5
+ response = RestClient.post "http://localhost:80/keyvalue","name=sea&age=10"
6
+ expect(response.body).to eq({"hi"=>1}.to_s)
7
+ end
8
+
9
+ it "partial dynamic request" do
10
+ KeyValue.new.by_name("ram").build()
11
+ response = RestClient.post "http://localhost:80/keyvalue","name=ram&age=10"
12
+ expect(response.body).to eq({"hi"=>1}.to_s)
13
+ end
14
+
15
+ it "dynamic request" do
16
+ KeyValue.new.by_name("ram").by_age(11).build()
17
+ response = RestClient.post "http://localhost:80/keyvalue","name=ram&age=11"
18
+ expect(response.body).to eq({"hi"=>1}.to_s)
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poisol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepak
@@ -135,6 +135,7 @@ files:
135
135
  - lib/poisol/stub_config.rb
136
136
  - lib/poisol/stub_factory.rb
137
137
  - lib/poisol/template/base_template.rb
138
+ - lib/poisol/template/build.rb
138
139
  - lib/poisol/template/query_handler.rb
139
140
  - lib/poisol/template/request_handler.rb
140
141
  - lib/poisol/template/response_handler.rb
@@ -143,6 +144,8 @@ files:
143
144
  - lib/poisol/utils/parse.rb
144
145
  - spec/functional/array_spec.rb
145
146
  - spec/functional/get_spec.rb
147
+ - spec/functional/key_value/explicit_inclusion_spec.rb
148
+ - spec/functional/key_value/implicit_inclusion_spec.rb
146
149
  - spec/functional/nested_array_spec.rb
147
150
  - spec/functional/post_spec.rb
148
151
  - spec/functional/url_spec.rb
@@ -175,6 +178,8 @@ test_files:
175
178
  - spec/spec_helper.rb
176
179
  - spec/functional/array_spec.rb
177
180
  - spec/functional/get_spec.rb
181
+ - spec/functional/key_value/explicit_inclusion_spec.rb
182
+ - spec/functional/key_value/implicit_inclusion_spec.rb
178
183
  - spec/functional/post_spec.rb
179
184
  - spec/functional/url_spec.rb
180
185
  - spec/functional/nested_array_spec.rb