# When shared examples are called as # it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false # then :rhoconnect_data group (@product1, ..., @data) skipped. # To enable this group call examples as # it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true shared_examples_for "SharedRhoconnectHelper" do |params| include TestHelpers # "TestappHelper" let(:test_app_name) { 'application' } # "RhoconnectHelper" before(:all) do Rhoconnect.bootstrap(get_testapp_path) do |rhoconnect| rhoconnect.vendor_directory = File.join(File.dirname(__FILE__), '..', '..', 'vendor') end end before(:each) do # "RhoconnectHelper" Store.create Store.db.flushdb # "DBObjectsHelper" @a_fields = { :name => test_app_name } @a = (App.load(test_app_name) || App.create(@a_fields)) @u_fields = {:login => 'testuser'} @u = User.create(@u_fields) @u.password = 'testpass' @c_fields = { :device_type => 'Apple', :device_pin => 'abcd', :device_port => '3333', :user_id => @u.id, :app_id => @a.id } @s_fields = { :name => 'SampleAdapter', :url => 'http://example.com', :login => 'testuser', :password => 'testpass', } @s1_fields = { :name => 'FixedSchemaAdapter', :url => 'http://example.com', :login => 'testuser', :password => 'testpass', } @s_params = { :user_id => @u.id, :app_id => @a.id } @c = Client.create(@c_fields,{:source_name => @s_fields[:name]}) @s = Source.create(@s_fields,@s_params) @s1 = Source.create(@s1_fields,@s_params) @s2 = Source.create({:name=> 'Product2'},@s_params) @s3 = Source.create({:name=> 'SimpleAdapter',:partition_type=> 'app'},@s_params) @s1.belongs_to = [{'brand' => 'SampleAdapter'}].to_json config = Rhoconnect.source_config('FixedSchemaAdapter') @s1.update(config) @r = @s.read_state @a.sources << @s.id @a.sources << @s1.id @a.sources << @s3.id Source.update_associations(@a.sources) @a.users << @u.id # "RhoconnectDataHelper" if params && params[:rhoconnect_data] @source = 'Product' @user_id = 5 @client_id = 1 @product1 = { 'name' => 'iPhone', 'brand' => 'Apple', 'price' => '199.99' } @product2 = { 'name' => 'G2', 'brand' => 'Android', 'price' => '99.99' } @product3 = { 'name' => 'Fuze', 'brand' => 'HTC', 'price' => '299.99' } @product4 = { 'name' => 'Droid', 'brand' => 'Android', 'price' => '249.99'} @data = {'1'=>@product1,'2'=>@product2,'3'=>@product3} end end end shared_examples_for "BenchSpecHelper" do before(:each) do Store.create Store.db.flushdb @product1 = { 'name' => 'iPhone', 'brand' => 'Apple', 'price' => '199.99' } @product2 = { 'name' => 'G2', 'brand' => 'Android', 'price' => '99.99' } @product3 = { 'name' => 'Fuze', 'brand' => 'HTC', 'price' => '299.99' } @product4 = { 'name' => 'Droid', 'brand' => 'Android', 'price' => '249.99'} @data = {'1'=>@product1,'2'=>@product2,'3'=>@product3} end end shared_examples_for "ApiHelper" do include Rack::Test::Methods include Rhoconnect include TestHelpers let(:test_app_name) { 'application' } before(:each) do Store.create Store.db.flushdb require File.join(get_testapp_path, test_app_name) Rhoconnect.bootstrap(get_testapp_path) do |rhoconnect| rhoconnect.vendor_directory = File.join(rhoconnect.base_directory,'..','..','..','vendor') end Rhoconnect::Server.set :environment, :test Rhoconnect::Server.set :run, false Rhoconnect::Server.set :secret, "secure!" @api_token = User.load('rhoadmin').token_id @a_fields = { :name => test_app_name } @a = (App.load(test_app_name) || App.create(@a_fields)) @u_fields = {:login => 'testuser'} @u = User.create(@u_fields) @u.password = 'testpass' @c_fields = { :device_type => 'Apple', :device_pin => 'abcd', :device_port => '3333', :user_id => @u.id, :app_id => @a.id } @s_fields = { :name => 'SampleAdapter', :url => 'http://example.com', :login => 'testuser', :password => 'testpass', } @s1_fields = { :name => 'FixedSchemaAdapter', :url => 'http://example.com', :login => 'testuser', :password => 'testpass', } @s_params = { :user_id => @u.id, :app_id => @a.id } @c = Client.create(@c_fields,{:source_name => @s_fields[:name]}) @s = Source.create(@s_fields,@s_params) @s1 = Source.create(@s1_fields,@s_params) @s2 = Source.create({:name=> 'Product2'},@s_params) @s1.belongs_to = [{'brand' => 'SampleAdapter'}].to_json config = Rhoconnect.source_config('FixedSchemaAdapter') @s1.update(config) @r = @s.read_state @a.sources << @s.id @a.sources << @s1.id Source.update_associations(@a.sources) @a.users << @u.id @source = 'Product' @user_id = 5 @client_id = 1 @product1 = { 'name' => 'iPhone', 'brand' => 'Apple', 'price' => '199.99' } @product2 = { 'name' => 'G2', 'brand' => 'Android', 'price' => '99.99' } @product3 = { 'name' => 'Fuze', 'brand' => 'HTC', 'price' => '299.99' } @product4 = { 'name' => 'Droid', 'brand' => 'Android', 'price' => '249.99'} @data = {'1'=>@product1,'2'=>@product2,'3'=>@product3} end end