Module: NmDatafile::Debug
- Included in:
- NmDatafile
- Defined in:
- lib/nm_datafile/debug.rb
Overview
Just a (drunken) note about all this stuff… This code, is specific to the rails app AnonymousPublications And is dependant on factory_girl, the factories defined in the rails app, and active record and also the sale model in AnonymousPubliactions. That sucks (sux), right? Yes.
To fix it, I should not have a #create_sale method, instead I should create those sales using Factories in the rails app, and then send those records in… For now, this stuff is just going to sit here though
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#add_sale(sale) ⇒ Object
Don’t use push on #sales, it will use the push on the array.
- #all_data_matches?(other) ⇒ Boolean
- #capture_addresses(sales) ⇒ Object
- #capture_line_items(sales) ⇒ Object
-
#create_sales_and_return_data(n) ⇒ Object
puts “Deprecated due to the test being specific to a kind of model and schema”.
-
#create_sales_and_return_data_address_completion_file(n, e) ⇒ Object
puts “Deprecated due to the test being specific to a kind of model and schema”.
-
#create_sales_for_shippable_file(n, e = nil) ⇒ Object
(also: #create_sales)
create’s n valid sales and e erroneous sales Line items are created in this process This is to be run form AnonymousPublications only until it gets ‘the big refactor’.
- #generate_upload_params(action = "upload_shippable_file") ⇒ Object
- #inspect ⇒ Object
- #regenerate_rfsb ⇒ Object
-
#should_gen_a_new_rfsb?(sale) ⇒ Boolean
we should NOT make a new rfsb if we’re adding an old erroneous sale to the object to check for age…
-
#simulate_address_completion_response(n_shipped) ⇒ Object
creates an address_completion file based on the contents of the current shippable_file object.
-
#simulate_rfsb_existance_on_webserver ⇒ Object
do as address_completion_file to create an rfsb that should have already existed, but didn’t because a fresh db was used for testing.
-
#to_s ⇒ Object
Debug methods #.
Instance Method Details
#==(other) ⇒ Object
167 168 169 170 171 |
# File 'lib/nm_datafile/debug.rb', line 167 def ==(other) return false if other.class != self.class return true if all_data_matches?(other) false end |
#add_sale(sale) ⇒ Object
Don’t use push on #sales, it will use the push on the array. TODu: to fix this, make the @sales arrays collections and give those collections special properties when push is invoked
54 55 56 57 58 |
# File 'lib/nm_datafile/debug.rb', line 54 def add_sale(sale) # add to collection the sale self.sales << sale regenerate_rfsb if should_gen_a_new_rfsb?(sale) end |
#all_data_matches?(other) ⇒ Boolean
173 174 175 176 177 178 179 180 |
# File 'lib/nm_datafile/debug.rb', line 173 def all_data_matches?(other) if self.integrity_hash == other.integrity_hash if self.build_attributes == other.build_attributes return true end end false end |
#capture_addresses(sales) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/nm_datafile/debug.rb', line 136 def capture_addresses(sales) a = [] sales.each do |s| a << s.address end a end |
#capture_line_items(sales) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/nm_datafile/debug.rb', line 128 def capture_line_items(sales) l = [] sales.each do |s| l += s.line_items end l end |
#create_sales_and_return_data(n) ⇒ Object
puts “Deprecated due to the test being specific to a kind of model and schema”
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/nm_datafile/debug.rb', line 117 def create_sales_and_return_data(n) sales = [] n.times { sales << FactoryGirl.create(:sale_with_1_book) } rfsb = ReadyForShipmentBatch.gen sales.each {|s| s.ready_for_shipment_batch_id = rfsb.id} l = capture_line_items(sales) a = capture_addresses(sales) [sales, l, a, rfsb] end |
#create_sales_and_return_data_address_completion_file(n, e) ⇒ Object
puts “Deprecated due to the test being specific to a kind of model and schema”
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/nm_datafile/debug.rb', line 102 def create_sales_and_return_data_address_completion_file(n, e) e = 0 if e.nil? sales = [] errors = [] n.times { sales << FactoryGirl.create(:sale_with_1_book) } e.times { errors << FactoryGirl.create(:sale_with_1_book) } rfsb = ReadyForShipmentBatch.gen sales.each {|s| s.ready_for_shipment_batch_id = rfsb.id} errors.each {|s| s.ready_for_shipment_batch_id = rfsb.id} [ sales, errors, rfsb ] end |
#create_sales_for_shippable_file(n, e = nil) ⇒ Object Also known as: create_sales
create’s n valid sales and e erroneous sales Line items are created in this process This is to be run form AnonymousPublications only until it gets ‘the big refactor’
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/nm_datafile/debug.rb', line 77 def create_sales_for_shippable_file(n, e=nil) if @file_type == :shippable_file s, l, a, rfsb = create_sales_and_return_data(n) self.sales += s self.line_items += l self.addresses += a self.ready_for_shipment_batch = rfsb rfsb.delete Sale.deep_delete_sales(s) elsif @file_type == :address_completion_file s, e, rfsb = create_sales_and_return_data_address_completion_file(n, e) self.sales += s self.erroneous_sales += e self.ready_for_shipment_batch = rfsb rfsb.delete Sale.deep_delete_sales(s) end end |
#generate_upload_params(action = "upload_shippable_file") ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nm_datafile/debug.rb', line 41 def generate_upload_params(action = "upload_shippable_file") temp_zip = Tempfile.new('temp_zip', "#{Rails.root}/tmp") save_to_file(temp_zip.path) upload_shippable_params = { "file_upload" => { "my_file" => Rack::Test::UploadedFile.new(temp_zip.path, "application/zip") }, "controller"=>"admin_pages", "action"=>action } end |
#inspect ⇒ Object
163 164 165 |
# File 'lib/nm_datafile/debug.rb', line 163 def inspect puts self.to_s end |
#regenerate_rfsb ⇒ Object
67 68 69 70 71 |
# File 'lib/nm_datafile/debug.rb', line 67 def regenerate_rfsb rfsb = ReadyForShipmentBatch.gen self.ready_for_shipment_batch = rfsb rfsb.delete end |
#should_gen_a_new_rfsb?(sale) ⇒ Boolean
we should NOT make a new rfsb if we’re adding an old erroneous sale to the object to check for age… see if it already has an rfsb_id
62 63 64 65 |
# File 'lib/nm_datafile/debug.rb', line 62 def should_gen_a_new_rfsb?(sale) return true if sale.ready_for_shipment_batch_id.nil? false end |
#simulate_address_completion_response(n_shipped) ⇒ Object
creates an address_completion file based on the contents of the current shippable_file object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nm_datafile/debug.rb', line 22 def simulate_address_completion_response(n_shipped) raise "can't make an address_completion_response unless it's a shippable_file" if @file_type != :shippable_file setup_object_for_schema # TODu: I put this in, there was a bug in the test where it needs to be run... does it not run on init somehow? shipped_sales = [] erroneous_addresses = [] sales.each.with_index do |sale, i| if i < n_shipped shipped_sales << { "id" => sale["id"] } else erroneous_addresses << { "id" => sale["id"] } end end simulated_response = [shipped_sales, erroneous_addresses, ready_for_shipment_batch] nmd_address_completion = NmDatafile.new(:address_completion_file, *simulated_response) end |
#simulate_rfsb_existance_on_webserver ⇒ Object
do as address_completion_file to create an rfsb that should have already existed, but didn’t because a fresh db was used for testing
16 17 18 19 |
# File 'lib/nm_datafile/debug.rb', line 16 def simulate_rfsb_existance_on_webserver rfsb = self.ready_for_shipment_batch ReadyForShipmentBatch.create(batch_stamp: rfsb["batch_stamp"], sf_integrity_hash: rfsb["integrity_hash"]) end |
#to_s ⇒ Object
Debug methods #
render a count of sales
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/nm_datafile/debug.rb', line 150 def to_s string = "NmDatafile: \n" data_collection_names.each.with_index do |collection_name, i| string << " #{collection_name}: #{@data_collections[i].count} \n" end data_object_names.each.with_index do |variable_name, i| string << " #{variable_name}: #{1} \n" end string end |