Module: Rhoconnect::TestMethods
- Defined in:
- lib/rhoconnect/test_methods.rb
Instance Method Summary collapse
-
#cd ⇒ Object
Returns the client document (:cd) for the source adapter + client under test.
-
#create_errors ⇒ Object
Returns any errors stored in redis from the previous source adapter create (same structure as query errors).
-
#delete_errors ⇒ Object
Returns any errors stored in redis from the previous source adapter delete (same structure as query errors).
-
#md ⇒ Object
Returns the master document (:md) for the source adapter stored in redis.
-
#query_errors ⇒ Object
Returns any errors stored in redis for the previous source adapter query For example: connecting to web service!”}.
-
#setup_test_for(adapter, user_id) ⇒ Object
Initializes the source adapter under test for a given user, typically in a before(:each) block setup_test_for(Product,‘testuser’) #=> ‘testuser’ will be used by rest of the specs.
-
#test_create(record) ⇒ Object
Execute’s the adapter’s create method with a provided record and returns the object string from the create method.
-
#test_delete(record) ⇒ Object
Execute the source adapter’s delete method.
-
#test_metadata ⇒ Object
Executes the adapter’s query method and returns the metadata stored in redis For example, if your source adapter metadata method was: def metadata row1 = { :label => ‘Address 1’, :value => ‘123 fake street’, :name => ‘address1’, :type => ‘labeledrow’ } table = { :label => ‘Table’, :type => ‘table’, :children => [ row1, row1, row1 ] } view = { :title => ‘UI meta panel’, :type => ‘iuipanel’, :children => [table] } return the definition as JSON => view.to_json.
-
#test_query ⇒ Object
Executes the adapter’s query method and returns the master document (:md) stored in redis For example, if your source adapter query method was: def query(params=nil) @result = { “1”=>“industry”=>“Electronics”, “2”=>“industry”=>“Software” } end.
-
#test_schema ⇒ Object
Executes the adapter’s schema method and returns the schema stored in redis For example, if your source adapter schema method was: def schema { ‘version’ => ‘1.0’, ‘property’ => { ‘name’ => ‘string’, ‘brand’ => ‘string’, ‘price’ => ‘string’, ‘image_url_cropped’ => ‘blob,overwrite’, ‘image_url’ => ‘blob’ }, ‘index’ => { ‘by_name_brand’ => ‘name,brand’ }, ‘unique_index’ => { ‘by_price’ => ‘price’ } }.to_json test_schema would return the above.
-
#test_search(search_params) ⇒ Object
Executes the adapter’s search method based on search_params and returns a hash of hashes.
-
#test_update(record) ⇒ Object
Execute the source adapter’s update method.
-
#update_errors ⇒ Object
Returns any errors stored in redis from the previous source adapter update (same structure as query errors).
Instance Method Details
#cd ⇒ Object
Returns the client document (:cd) for the source adapter + client under test. The master document (:md) and client document (:cd) should be equal
236 237 238 |
# File 'lib/rhoconnect/test_methods.rb', line 236 def cd @c.get_data(:cd) end |
#create_errors ⇒ Object
Returns any errors stored in redis from the previous source adapter create (same structure as query errors)
164 165 166 |
# File 'lib/rhoconnect/test_methods.rb', line 164 def create_errors @c.get_data(:create_errors) end |
#delete_errors ⇒ Object
Returns any errors stored in redis from the previous source adapter delete (same structure as query errors)
224 225 226 |
# File 'lib/rhoconnect/test_methods.rb', line 224 def delete_errors @c.get_data(:delete_errors) end |
#md ⇒ Object
Returns the master document (:md) for the source adapter stored in redis. This is equivalent to the @result hash of hashes structure.
230 231 232 |
# File 'lib/rhoconnect/test_methods.rb', line 230 def md @s.get_data(:md) end |
#query_errors ⇒ Object
Returns any errors stored in redis for the previous source adapter query For example: connecting to web service!”}
128 129 130 |
# File 'lib/rhoconnect/test_methods.rb', line 128 def query_errors @s.get_data(:errors) end |
#setup_test_for(adapter, user_id) ⇒ Object
Initializes the source adapter under test for a given user, typically in a before(:each) block setup_test_for(Product,‘testuser’) #=> ‘testuser’ will be used by rest of the specs
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rhoconnect/test_methods.rb', line 9 def setup_test_for(adapter,user_id) app_id = 'application' s_fields = { :user_id => user_id, :app_id => app_id } c_fields = { :device_type => 'Apple', :device_pin => 'abcd', :device_port => '3333', :user_id => user_id, :app_id => app_id } @u = User.create(:login => user_id) @s = Source.load(adapter.to_s,s_fields) @c = Client.create(c_fields,{:source_name => adapter.to_s}) @ss = SourceSync.new(@s) end |
#test_create(record) ⇒ Object
Execute’s the adapter’s create method with a provided record and returns the object string from the create method. If the create method returns a string, then a link will be saved for the device next time it synchronizes. This link can be tested here.
For example, in your spec: } new_product_id = test_create(@product) create_errors.should == {} md.should == @product
This will return the result of the adapter’s create method. The master document (:md) should also contain the new record.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rhoconnect/test_methods.rb', line 151 def test_create(record) if @s.is_pass_through? @ss.pass_through_cud({'create'=> {'temp-id' => record}},nil) else @s.put_zdata(:create,@c.id,{'temp-id' => record},true) @ss.process_cud links = @c.get_data(:create_links)['temp-id'] links ? links['l'] : nil end end |
#test_delete(record) ⇒ Object
Execute the source adapter’s delete method. Takes a record as hash of hashes (object_id => object)
For example: } test_delete(‘4’ => @product) delete_errors.should == {} md.should == {}
This will call the adapter’s delete method for product ‘4’ NOTE: The master document (:md) will be updated and can be verified as shown above.
213 214 215 216 217 218 219 220 |
# File 'lib/rhoconnect/test_methods.rb', line 213 def test_delete(record) if @s.is_pass_through? @ss.pass_through_cud({'delete'=> record },nil) else @s.put_zdata(:delete,@c.id,record,true) @ss.process_cud end end |
#test_metadata ⇒ Object
Executes the adapter’s query method and returns the metadata stored in redis For example, if your source adapter metadata method was: def metadata
row1 = {
:label => 'Address 1',
:value => '123 fake street',
:name => 'address1',
:type => 'labeledrow'
}
table = {
:label => 'Table',
:type => 'table',
:children => [ row1, row1, row1 ]
}
view = {
:title => 'UI meta panel',
:type => 'iuipanel',
:children => [table]
}
return the definition as JSON
{'index' => view}.to_json
test_metadata would return: {
{'index' => view}.to_json
}
95 96 97 98 |
# File 'lib/rhoconnect/test_methods.rb', line 95 def @ss.process_query return @s.get_value(:metadata) end |
#test_query ⇒ Object
Executes the adapter’s query method and returns the master document (:md) stored in redis For example, if your source adapter query method was: def query(params=nil)
@result = {
"1"=>{"name"=>"Acme", "industry"=>"Electronics"},
"2"=>{"name"=>"Best", "industry"=>"Software"}
}
end
test_query would return: {
"1"=>{"name"=>"Acme", "industry"=>"Electronics"},
"2"=>{"name"=>"Best", "industry"=>"Software"}
}
43 44 45 46 |
# File 'lib/rhoconnect/test_methods.rb', line 43 def test_query res = @ss.process_query return @s.is_pass_through? ? res : md end |
#test_schema ⇒ Object
Executes the adapter’s schema method and returns the schema stored in redis For example, if your source adapter schema method was: def schema {
'version' => '1.0',
'property' => {
'name' => 'string',
'brand' => 'string',
'price' => 'string',
'image_url_cropped' => 'blob,overwrite',
'image_url' => 'blob'
},
'index' => {
'by_name_brand' => 'name,brand'
},
'unique_index' => {
'by_price' => 'price'
}
}.to_json test_schema would return the above
121 122 123 124 |
# File 'lib/rhoconnect/test_methods.rb', line 121 def test_schema @ss.process_query return @s.get_value(:schema) end |
#test_search(search_params) ⇒ Object
Executes the adapter’s search method based on search_params and returns a hash of hashes. For example, if master document was
{
"1"=>{"name"=>"Acme", "industry"=>"Electronics"},
"2"=>{"name"=>"Best", "industry"=>"Software"}
}
Then call test_search(“name”=>“Acme”) would return
{
"1"=>{"name"=>"Acme", "industry"=>"Electronics"},
}
60 61 62 63 64 65 66 |
# File 'lib/rhoconnect/test_methods.rb', line 60 def test_search(search_params) pass_through = @s.pass_through @s.pass_through = 'true' res = @ss.search(@c.id, search_params) @s.pass_through = pass_through res end |
#test_update(record) ⇒ Object
Execute the source adapter’s update method. Takes a record as hash of hashes (object_id => object)
For example: test_update(=> {‘price’ => ‘$199.99’}) update_errors.should == {} test_query md[‘price’].should == ‘$199.99’
This will call the adapter’s update method for object_id ‘4’ NOTE: To test the master document, you will need to run def test_query as shown above
180 181 182 183 184 185 186 187 |
# File 'lib/rhoconnect/test_methods.rb', line 180 def test_update(record) if @s.is_pass_through? @ss.pass_through_cud({'update'=> record },nil) else @s.put_zdata(:update,@c.id,record,true) @ss.process_cud end end |
#update_errors ⇒ Object
Returns any errors stored in redis from the previous source adapter update (same structure as query errors)
191 192 193 |
# File 'lib/rhoconnect/test_methods.rb', line 191 def update_errors @c.get_data(:update_errors) end |