lib/scenarios/scenario_db.rb in scenario_server-0.0.7 vs lib/scenarios/scenario_db.rb in scenario_server-0.1.0

- old
+ new

@@ -44,14 +44,14 @@ else puts 'No records to display.' end end - if !options[:add_route].nil? && options[:add_route].length == 4 + if !options[:add_route].nil? && options[:add_route].length == 6 configure_database - add_route_for_scenario(options[:add_route][0], options[:add_route][1], options[:add_route][2], options[:add_route][3]) + add_route_for_scenario(options[:add_route][0], options[:add_route][1], options[:add_route][2], options[:add_route][3], options[:add_route][4], options[:add_route][5]) if self.routes.count > 0 Sequel::PrettyTable.print(self.routes) else puts 'No records to display.' end @@ -208,40 +208,39 @@ self.db.create_table :routes do primary_key :id foreign_key :scenario_id, :scenarios, :on_delete => :cascade, :on_update => :cascade String :route_type String :path + Integer :status_code + String :headers String :fixture DateTime :created_at DateTime :updated_at end end end - def add_route_for_scenario(route_type, path, fixture, scenario_id) - now = DateTime.now + def add_route_for_scenario(route_type, path, status_code, headers, fixture, scenario_id) + now = DateTime.now if self.routes.where(:scenario_id => scenario_id, :route_type=> route_type, :path=> path).to_a.count == 0 - self.routes.insert(:scenario_id => scenario_id, :route_type=>route_type, :path => path, :fixture => fixture, :created_at => now, :updated_at => now) + self.routes.insert(:scenario_id => scenario_id, :route_type=> route_type, :path => path, :status_code => status_code, :headers => headers, :fixture => fixture, :created_at => now, :updated_at => now) end # puts "<scenario_id: #{scenario_id} #{}route_type} #Path: #{path} fixture: #{fixture}>" end def delete_route(route_id) self.routes.filter(:id => route_id).delete end def get_routes_for_scenario(scenario_id) - return self.routes.filter(:scenario_id=>scenario_id).select(:id, :scenario_id,:route_type,:path,:fixture).to_a + return self.routes.filter(:scenario_id=>scenario_id).select(:id, :scenario_id, :route_type, :path, :status_code, :headers, :fixture).to_a end def get_fixture_from_routes(route_type, path, scenario_name) - self.routes.left_outer_join(:scenarios, :id=>:scenario_id).where(:route_type=>route_type, :path=>path, - :name=>scenario_name).map(:fixture).first + :name=>scenario_name).map([:status_code, :headers, :fixture]).first - - #TODO instead of returning first fixture, add checks to avoid duplicate insertions end def get_route(route_id) return self.routes.where(:id => route_id).first end