Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/tip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ def was_undecided?


after_save :notify_user_if_just_decided
before_save :touch_decided_at_if_decided


def self.refund_unclaimed
unclaimed.non_refunded.
where('tips.created_at < ?', Time.now - 1.month).
where.not(decided_at: nil).
where('tips.decided_at < ?', Time.now - 1.month).
find_each do |tip|
tip.touch :refunded_at
end
Expand All @@ -96,6 +98,10 @@ def notify_user_if_just_decided
notify_user if amount_was.nil? and amount
end

def touch_decided_at_if_decided
self.decided_at = Time.now if amount_changed? && decided?
end

def coin_amount
amount.to_f / COIN if amount
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140620123610_add_decided_at_to_tips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDecidedAtToTips < ActiveRecord::Migration
def change
add_column :tips, :decided_at, :timestamp
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UpdateDecidedAtForExistingTips < ActiveRecord::Migration
def up
Tip.where.not(amount: nil).find_each do |tip|
tip.update decided_at: tip.created_at
end
end
end
12 changes: 7 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140616060504) do
ActiveRecord::Schema.define(version: 20140620124628) do

create_table "cold_storage_transfers", force: true do |t|
t.integer "project_id"
Expand Down Expand Up @@ -179,18 +179,19 @@
add_index "tipping_policies_texts", ["user_id"], name: "index_tipping_policies_texts_on_user_id"

create_table "tips", force: true do |t|
t.integer "user_id"
t.integer "amount", limit: 8
t.integer "distribution_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "commit"
t.integer "project_id"
t.datetime "refunded_at"
t.string "commit_message"
t.text "commit_message"
t.string "comment"
t.integer "reason_id"
t.string "reason_type"
t.integer "user_id"
t.datetime "decided_at"
end

add_index "tips", ["distribution_id"], name: "index_tips_on_distribution_id"
Expand All @@ -199,6 +200,7 @@
add_index "tips", ["user_id"], name: "index_tips_on_user_id"

create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
Expand All @@ -210,6 +212,7 @@
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "nickname"
t.string "name"
t.string "image"
t.string "bitcoin_address"
Expand All @@ -222,10 +225,9 @@
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "email"
t.string "nickname"
end

add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end