Created
June 11, 2012 23:16
-
-
Save richievos/2913355 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 7e091a06e41070c005b2bbfa6f4b15c91dbfa3d5 | |
Author: Richie Vos <[email protected]> | |
Date: Mon Jun 11 18:16:25 2012 -0500 | |
Deleting the new order object | |
cr=akao | |
diff --git a/app/controllers/admin/transactional_email_controller.rb b/app/controllers/admin/transactional_email_controller.rb | |
index fae3b0f..8142498 100644 | |
--- a/app/controllers/admin/transactional_email_controller.rb | |
+++ b/app/controllers/admin/transactional_email_controller.rb | |
@@ -17,7 +17,6 @@ class Admin::TransactionalEmailController < Admin::BaseController | |
@pledges = [@campaigns.first.pledges.first] | |
@subject = 'Sample Deal Subject' | |
@message = 'Sample Deal message.' | |
- @order = Order.last | |
@gift_card = GiftCard.last | |
render :template => template, :layout => 'email_transactional_base' | |
end | |
diff --git a/app/views/groupon/tests/modals.html.haml b/app/views/groupon/tests/modals.html.haml | |
index 62b81c2..e71d48c 100644 | |
--- a/app/views/groupon/tests/modals.html.haml | |
+++ b/app/views/groupon/tests/modals.html.haml | |
@@ -43,9 +43,6 @@ | |
- flash[:my_price] = 20 | |
- modals = [{:template => 'deals/modal_gift_details', :setup => proc{ @order = Order.first }}, | | |
{:template => 'deals/modal_select_area', :locals => { :subscription_update_email => '[email protected]', :division_areas => [Division::Area.first], :area => Division::Area.first}}, | | |
- {:template => 'deals/post_purchase', :locals => {:campaign => Campaign.groupon.first, :order => Order.last}, :setup => proc{ @user = User.first}}, | | |
- {:template => 'deals/post_purchase', :locals => {:campaign => Campaign.groupon.first, :order => Order.find(:first, :conditions => {:gift => false}) }, :setup => proc{ @user = User.first ; flash[:my_price] = 1 }}, | | |
- {:template => 'gift_cards/post_purchase', :locals => {:gift_card => GiftCard.first}, :setup => proc{ @user = User.first }}, | | |
{:template => 'reward/first_time_in_rewards'}, | | |
{:template => 'reward/level_modal' }, | | |
{:template => 'reward/level_unlocked_modal'}, | | |
diff --git a/features/step_definitions/api/common_steps.rb b/features/step_definitions/api/common_steps.rb | |
index 6b54a51..74d3577 100644 | |
--- a/features/step_definitions/api/common_steps.rb | |
+++ b/features/step_definitions/api/common_steps.rb | |
@@ -39,11 +39,9 @@ Given /^I have a \$5 Marketing Drive Discount$/ do | |
end | |
Given /^I have an Order$/ do | |
- @order = orders(:launched_groupon) | |
end | |
Given /^Order belongs to me$/ do | |
- @order.membership_pledge.membership.update_attributes!(:member_id => @user.id) | |
end | |
And /^I make authenticated api request to get all my groupons$/ do | |
diff --git a/lib/app/models/order/binding_methods.rb b/lib/app/models/order/binding_methods.rb | |
deleted file mode 100644 | |
index 970e93b..0000000 | |
--- a/lib/app/models/order/binding_methods.rb | |
+++ /dev/null | |
@@ -1,56 +0,0 @@ | |
-module App::Models::Order | |
- module BindingMethods | |
- def self.included(base) | |
- base.send :attr_accessor, :delivery_method | |
- base.send :validates_presence_of, :gift_recipient_email, :if => :email_delivery? | |
- end | |
- | |
- def amount_ext | |
- amount * membership_pledge.pledge.unit_price | |
- end | |
- | |
- def delivery=(data) | |
- return unless gift? | |
- case self.delivery_method = data[:method] | |
- when 'email' | |
- #self.gift_recipient_email = data[:email_address] | |
- self.deliver_gift = true if self.collected? | |
- when 'print' # possibly deliver at this time | |
- end | |
- end | |
- | |
- def delivery | |
- BindingAdapter.new('delivery', :email_address => gift_recipient_email, | |
- :method => delivery_method, | |
- :errors => ActiveRecord::Errors.new(self)) | |
- end | |
- | |
- def email_delivery? | |
- delivery.method == 'email' | |
- end | |
- | |
- def print_delivery? | |
- delivery.method == 'print' | |
- end | |
- | |
- def save_action=(value) | |
- return if new_record? | |
- self.deliver_gift = (value.match(/send/i) && self.collected?) | |
- end | |
- | |
- def save_action | |
- end | |
- | |
- def member=(value) | |
- @member = value.is_a?(User) ? value : User[value] | |
- end | |
- | |
- def member | |
- @member || membership_pledge.try(:membership).try(:member) | |
- end | |
- | |
- def member? | |
- !member.blank? | |
- end | |
- end | |
-end | |
diff --git a/lib/app/models/order/deal_purchase_summary.rb b/lib/app/models/order/deal_purchase_summary.rb | |
deleted file mode 100644 | |
index 1c70ef7..0000000 | |
--- a/lib/app/models/order/deal_purchase_summary.rb | |
+++ /dev/null | |
@@ -1,126 +0,0 @@ | |
-module App::Models::Order | |
- class DealPurchaseSummary | |
- cattr_accessor :redis | |
- | |
- JUST_TIPPED_EXPIRATION_IN_SECONDS = 1.day.to_i | |
- | |
- def self.deal_ids_with_pretipped_orders | |
- redis.keys("deal:*:pretipped_orders").map { |string| string.split(':')[1] } | |
- end | |
- | |
- def self.active_just_tipped_deals | |
- redis.keys("deal:*:just_tipped").map { |string| string.split(':')[1] } | |
- end | |
- | |
- def self.active_quantity_sold_deals | |
- redis.keys("deal:*:quantity_sold").map { |string| string.split(':')[1] } | |
- end | |
- | |
- delegate :redis, :to => self | |
- attr_accessor :deal_id, :pretipped_order_key, :quantity_sold_key, :tipped_key, :just_tipped_key | |
- | |
- def initialize(deal_id) | |
- @deal_id = deal_id | |
- @pretipped_order_key = "deal:#{@deal_id}:pretipped_orders" | |
- @quantity_sold_key = "deal:#{@deal_id}:quantity_sold" | |
- @tipped_key = "deal:#{@deal_id}:tipped" | |
- @just_tipped_key = "deal:#{@deal_id}:just_tipped" | |
- end | |
- | |
- def increment_quantity_sold(delta) | |
- redis.incrby(@quantity_sold_key, delta) | |
- end | |
- | |
- def tipped? | |
- redis.get(@tipped_key) | |
- end | |
- | |
- def tipped! | |
- redis.set(@tipped_key, true) | |
- | |
- redis.set(@just_tipped_key, true) | |
- redis.expire(@just_tipped_key, JUST_TIPPED_EXPIRATION_IN_SECONDS) | |
- end | |
- | |
- def push_pretipped_order_id(order_id) | |
- redis.lpush(@pretipped_order_key, order_id) | |
- end | |
- | |
- def pop_pretipped_order_id | |
- redis.rpop(@pretipped_order_key) | |
- end | |
- | |
- # NOTE ONLY USE THIS IF YOU ARE POSITIVE YOU KNOW WHAT YOU'RE DOING: | |
- # only use this method when you are sure no one else will be using/writing to | |
- # this list. Otherwise you can delete a list with pretipped orders in it, so they'll | |
- # never get collected on. | |
- def delete_pretipped_orders_queue | |
- redis.del(@pretipped_order_key) | |
- end | |
- | |
- def expire_pretipped_orders_queue | |
- redis.expire(@pretipped_order_key, JUST_TIPPED_EXPIRATION_IN_SECONDS) | |
- end | |
- | |
- # this overwrites quantity sold, but it has a race condition: | |
- # thread 1: calc quantity sold | |
- # thread 2: do an incrby | |
- # thread 1: set quantity sold | |
- # thread 2's value was thrown away | |
- def unsafely_overwrite_quantity_sold(tipping_point, quantity) | |
- process_quantity(tipping_point, quantity) do | |
- redis.set(@quantity_sold_key, quantity) | |
- quantity | |
- end | |
- end | |
- | |
- def safely_overwrite_quantity_sold(tipping_point, quantity) | |
- process_quantity(tipping_point, quantity) do | |
- quantity = nil | |
- | |
- loop do | |
- # this will only write the data to redis if quantity sold doesn't change | |
- redis.watch(@quantity_sold_key) | |
- redis.multi | |
- | |
- quantity = yield | |
- | |
- # TODO rv: make sure to not destroy the db | |
- multi.set(@quantity_sold_key, quantity) | |
- | |
- break if redis.exec | |
- # sleep(1) | |
- end | |
- | |
- quantity | |
- end | |
- end | |
- | |
- def process_quantity_sold_change(tipping_point, quantity_delta=0) | |
- process_quantity(tipping_point, quantity_delta) do | |
- increment_quantity_sold(quantity_delta) | |
- end | |
- end | |
- | |
- def process_quantity(tipping_point, quantity_delta) | |
- was_already_tipped = tipped? | |
- # rv: yeah, these could probably be a .send, but people hate me when I use send | |
- new_quantity_sold = yield | |
- | |
- if was_already_tipped | |
- :tipped | |
- elsif is_now_tipped = (new_quantity_sold >= tipping_point) | |
- previous_quantity_sold = new_quantity_sold - quantity_delta | |
- | |
- # <= is because now orders have tipping point 0 | |
- if just_tipped = (previous_quantity_sold <= tipping_point) | |
- tipped! | |
- end | |
- | |
- :tipped | |
- else | |
- :not_tipped | |
- end | |
- end | |
- end | |
-end | |
diff --git a/lib/app/models/order/queue_manager.rb b/lib/app/models/order/queue_manager.rb | |
deleted file mode 100644 | |
index 7d9e3c1..0000000 | |
--- a/lib/app/models/order/queue_manager.rb | |
+++ /dev/null | |
@@ -1,38 +0,0 @@ | |
-module App | |
- module Models | |
- module Order | |
- class QueueManager | |
- def self.process_quantity_change(order, quantity_delta) | |
- deal_purchase_summary = DealPurchaseSummary.new(order.deal_id) | |
- tipping_status = deal_purchase_summary.process_quantity_sold_change(order.tipping_point, quantity_delta) | |
- [deal_purchase_summary, tipping_status] | |
- end | |
- | |
- def self.enqueue_order_worker(order) | |
- if order.collectible? | |
- worker = order.priority_collection? ? PriorityOrderCollectionWorker : OrderCollectionWorker | |
- Rails.logger.info "[#{Time.now.utc.iso8601}] order_id=#{order.id}. Enqueue'ing collectible order #{order.id}." | |
- Resque.enqueue_with_timeout_retry(worker, :order_id => order.id, :enqueued_at => Time.now.to_f) | |
- else | |
- Rails.logger.info "[#{Time.now.utc.iso8601}] order_id=#{order.id} source=enqueue_order_worker. Not enqueue'ing uncollectible order #{order.id}." | |
- end | |
- end | |
- | |
- def self.process(order, quantity_delta=0) | |
- deal_purchase_summary, tipping_status = process_quantity_change(order, quantity_delta) | |
- | |
- if order.collectible? | |
- if tipping_status == :tipped | |
- enqueue_order_worker(order) | |
- else | |
- Rails.logger.info "[#{Time.now.utc.iso8601}] order_id=#{order.id}. Placing order #{order.id} in pre-tipped order queue for deal #{deal_purchase_summary.deal_id}." | |
- deal_purchase_summary.push_pretipped_order_id(order.id) | |
- end | |
- else | |
- Rails.logger.info "[#{Time.now.utc.iso8601}] order_id=#{order.id} source=process. Not enqueue'ing uncollectible order #{order.id}." | |
- end | |
- end | |
- end | |
- end | |
- end | |
-end | |
diff --git a/lib/vip_utility.rb b/lib/vip_utility.rb | |
index 94a08be..f2d9ba1 100644 | |
--- a/lib/vip_utility.rb | |
+++ b/lib/vip_utility.rb | |
@@ -1,6 +1,6 @@ | |
class VipUtility | |
def bill_enrollment_request(enrollment, &block) | |
- uid = Order.connection.select_value("SELECT UUID_SHORT()") | |
+ uid = User.connection.select_value("SELECT UUID_SHORT()") | |
request = { | |
:uid => uid, | |
:billing_record => enrollment.billing_record_id, | |
diff --git a/services/orders/app/models/order.rb b/services/orders/app/models/order.rb | |
deleted file mode 100644 | |
index 317a284..0000000 | |
--- a/services/orders/app/models/order.rb | |
+++ /dev/null | |
@@ -1,92 +0,0 @@ | |
-class Order < OrdersRecord | |
- include App::Models::Order::Queryable | |
- | |
- set_table_name :parent_orders | |
- | |
- has_many :batches, :class_name => "::Order::Batch", :foreign_key => :parent_order_id | |
- has_many :fulfillments, :through => :batches, :source => :fulfillments | |
- has_many :line_items, :through => :batches, :source => :line_items | |
- | |
- belongs_to :billing_record, :class_name => "User::BillingRecord" | |
- | |
- validates_uniqueness_of :uid | |
- | |
- def validate_update(update_request) | |
- update_validation_errors = [] | |
- | |
- new_billing_record_id = update_request.billing_record | |
- if new_billing_record_id.present? | |
- begin | |
- User::BillingRecord.find(new_billing_record_id) | |
- rescue ActiveRecord::RecordNotFound | |
- update_validation_errors << {:message => "billing record with id: #{new_billing_record_id} does not exist", :error_code => "ERR_ORDER_UPDATE_VALIDATION_FAILURE"} | |
- end | |
- | |
- # TODO: check against order collection system to see if there is even a point in changing the billing record | |
- end | |
- | |
- new_items = update_request.items | |
- | |
- if new_items.present? | |
- new_items.each do |new_item_request| | |
- line_item = find_corresponding_line_item(new_item_request) | |
- if line_item.nil? | |
- update_validation_errors << {:message => "could not find an order line item to update for request: #{new_item_request.id}", :error_code => "ERR_ORDER_UPDATE_VALIDATION_FAILURE"} | |
- else | |
- update_validation_errors.concat(line_item.validate_update(new_item_request)) | |
- end | |
- end | |
- end | |
- | |
- update_validation_errors | |
- end | |
- | |
- def apply_update(update_request, updater_id) | |
- | |
- new_billing_record_id = update_request.billing_record | |
- if new_billing_record_id.present? | |
- self.billing_record_id = new_billing_record_id | |
- end | |
- | |
- new_items = update_request.items | |
- updated_line_items = [] | |
- if new_items.present? | |
- new_items.each do |new_item_request| | |
- line_item = find_corresponding_line_item(new_item_request) | |
- line_item.apply_update(new_item_request, updater_id) | |
- updated_line_items << line_item | |
- end | |
- end | |
- | |
- Order.transaction do | |
- updated_line_items.each do |line_item| | |
- line_item.save! | |
- end | |
- save! | |
- end | |
- end | |
- | |
- def enqueue_for_collection | |
- batches.each do |batch| | |
- batch.line_items.each do |line_item| | |
- if line_item.new_world_order? | |
- if line_item.collectible? | |
- worker = OrderCollectionWorker | |
- Rails.logger.info "[#{Time.now.utc.iso8601}] Enqueue'ing collectible line_item #{line_item.id}." | |
- COLLECTION_LOGGER.info(line_item.id, 'enqueued') | |
- Resque.enqueue_with_timeout_retry(worker, :order_id => line_item.id, :enqueued_at => Time.now.to_f) | |
- else | |
- Rails.logger.info "[#{Time.now.utc.iso8601}] Not enqueue'ing uncollectible line_item #{line_item.id}." | |
- end | |
- end | |
- end | |
- end | |
- end | |
- | |
- private | |
- | |
- def find_corresponding_line_item(item_update_request) | |
- (line_items.select { |line_item| line_item.id == item_update_request.id }).first | |
- end | |
- | |
-end | |
diff --git a/spec/controllers/deals/orders_controller_google_goals_spec.rb b/spec/controllers/deals/orders_controller_google_goals_spec.rb | |
index 48f7f43..6c66146 100644 | |
--- a/spec/controllers/deals/orders_controller_google_goals_spec.rb | |
+++ b/spec/controllers/deals/orders_controller_google_goals_spec.rb | |
@@ -48,7 +48,6 @@ describe Deals::OrdersController do | |
controller.instance_variable_set(:@option, @option) | |
# for lead tracking | |
- Order.stub(:find).with(1).and_return(stub(:membership => @membership)) | |
OrderLead.stub(:create => true) | |
@user.stub!(:subscriptions => stub.as_null_object) | |
diff --git a/spec/lib/service_wall_spec.rb b/spec/lib/service_wall_spec.rb | |
index f11e4a9..a6ac44b 100644 | |
--- a/spec/lib/service_wall_spec.rb | |
+++ b/spec/lib/service_wall_spec.rb | |
@@ -15,11 +15,6 @@ describe App::Controllers::ServiceWall, :type => :controller do | |
render :nothing => true | |
end | |
- def ignored | |
- Order::LineItem.first or raise "none found" | |
- render :nothing => true | |
- end | |
- | |
def nested_allow | |
as_a_hack_allow_model_access("services/orders/app") do | |
Order::LineItem.first or raise "none found" | |
@@ -98,10 +93,6 @@ describe App::Controllers::ServiceWall, :type => :controller do | |
end | |
end | |
- it "should allow access to when a non-blocked action" do | |
- lambda { get :ignored }.should_not raise_error(App::Controllers::ServiceWall::ModelAccessDenied) | |
- end | |
- | |
it "should not show a warning to a non-blocked action" do | |
Rails.logger.should_not_receive(:warn) | |
get :ignored_warning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment