From e878253b4033efa4a29aec911833047fb470bcad Mon Sep 17 00:00:00 2001 From: Gnewt Date: Wed, 5 Feb 2014 19:19:07 -0800 Subject: [PATCH 01/19] Added support for sorting by watchers --- app/controllers/projects_controller.rb | 5 +++++ app/views/projects/index.html.haml | 4 ++-- config/routes.rb | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 18c28caf..bb1e7e68 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -4,6 +4,11 @@ class ProjectsController < ApplicationController def index @projects = Project.order(available_amount_cache: :desc, watchers_count: :desc, full_name: :asc).page(params[:page]).per(30) end + + def by_watchers + @projects = Project.order(watchers_count: :desc, available_amount_cache: :desc, full_name: :asc).page(params[:page]).per(30) + render "index" + end def show @project = Project.find params[:id] diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index d9345199..c42caeaa 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -13,8 +13,8 @@ %tr %th Repository %th Description - %th Watchers - %th Balance + %th= link_to 'Watchers', by_watchers_projects_path + %th= link_to 'Balance', projects_path %th %tbody - @projects.each do |project| diff --git a/config/routes.rb b/config/routes.rb index cc205fcd..191b38e3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,9 @@ end end resources :projects, :only => [:show, :index, :create] do + collection do + get 'by_watchers' + end resources :tips, :only => [:index] end resources :tips, :only => [:index] From b6ff1fa3ef80d688ecb8431c041d39b6b7f2ed46 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Fri, 7 Feb 2014 12:21:39 +0700 Subject: [PATCH 02/19] updates projects information. closes #8 --- app/models/project.rb | 14 ++++++++++++++ app/views/projects/index.html.haml | 4 ++-- lib/bitcoin_tipper.rb | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2e5db9cd..20bb8c6f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -119,4 +119,18 @@ def self.update_cache end end + def update_info + client = Octokit::Client.new \ + :client_id => CONFIG['github']['key'], + :client_secret => CONFIG['github']['secret'] + begin + update_github_info(client.repo(full_name)) + rescue Octokit::BadGateway, Octokit::NotFound, Octokit::InternalServerError, + Errno::ETIMEDOUT, Net::ReadTimeout, Faraday::Error::ConnectionFailed => e + Rails.logger.info "Project ##{id}: #{e.class} happened" + rescue StandardError => e + Airbrake.notify(e) + end + end + end diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index c42caeaa..ad92332c 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -13,8 +13,8 @@ %tr %th Repository %th Description - %th= link_to 'Watchers', by_watchers_projects_path - %th= link_to 'Balance', projects_path + %th= link_to_unless_current 'Watchers', by_watchers_projects_path + %th= link_to_unless_current 'Balance', projects_path %th %tbody - @projects.each do |project| diff --git a/lib/bitcoin_tipper.rb b/lib/bitcoin_tipper.rb index da10ccb2..45bae235 100644 --- a/lib/bitcoin_tipper.rb +++ b/lib/bitcoin_tipper.rb @@ -14,6 +14,12 @@ def self.work end end + Rails.logger.info "Updating projects info..." + Project.order(:updated_at => :desc).last(5).each do |project| + Rails.logger.info " Project #{project.id} #{project.full_name}" + project.update_info + end + Rails.logger.info "Traversing users..." is_sendmany_needed = false User.find_each do |user| From 96a99d216305cfba232c58dfee9839cef1e1479d Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Fri, 7 Feb 2014 16:45:30 +0700 Subject: [PATCH 03/19] used github id to identify repo --- app/models/project.rb | 13 +++++++++++-- .../20140207061855_add_github_id_to_projects.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20140207061855_add_github_id_to_projects.rb diff --git a/app/models/project.rb b/app/models/project.rb index 20bb8c6f..2f632d87 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -3,6 +3,7 @@ class Project < ActiveRecord::Base has_many :tips def update_github_info repo + self.github_id = repo.id self.name = repo.name self.full_name = repo.full_name self.source_full_name = repo.source.full_name rescue '' @@ -119,12 +120,20 @@ def self.update_cache end end - def update_info + def github_info client = Octokit::Client.new \ :client_id => CONFIG['github']['key'], :client_secret => CONFIG['github']['secret'] + if github_id.present? + client.get("/repositories/#{github_id}") + else + client.repo(full_name) + end + end + + def update_info begin - update_github_info(client.repo(full_name)) + update_github_info(github_info) rescue Octokit::BadGateway, Octokit::NotFound, Octokit::InternalServerError, Errno::ETIMEDOUT, Net::ReadTimeout, Faraday::Error::ConnectionFailed => e Rails.logger.info "Project ##{id}: #{e.class} happened" diff --git a/db/migrate/20140207061855_add_github_id_to_projects.rb b/db/migrate/20140207061855_add_github_id_to_projects.rb new file mode 100644 index 00000000..9f2e8f24 --- /dev/null +++ b/db/migrate/20140207061855_add_github_id_to_projects.rb @@ -0,0 +1,5 @@ +class AddGithubIdToProjects < ActiveRecord::Migration + def change + add_column :projects, :github_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index aa2be27e..6998333c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140102095035) do +ActiveRecord::Schema.define(version: 20140207061855) do create_table "deposits", force: true do |t| t.integer "project_id" @@ -40,6 +40,7 @@ t.string "language" t.string "last_commit" t.integer "available_amount_cache" + t.string "github_id" end create_table "sendmanies", force: true do |t| From 766b6bcb16a97286c2083d229556f99459334f79 Mon Sep 17 00:00:00 2001 From: Cristian Mircea Messel Date: Sat, 8 Feb 2014 14:14:37 +0200 Subject: [PATCH 04/19] replace fixtures with factory_girl also fixed the test env so rake test works --- Gemfile | 4 +++- Gemfile.lock | 6 ++++++ config/environments/test.rb | 2 ++ test/controllers/projects_controller_test.rb | 6 ------ test/controllers/users_controller_test.rb | 13 ++++--------- test/factories/deposits.rb | 10 ++++++++++ test/factories/projects.rb | 6 ++++++ test/factories/sendmanies.rb | 8 ++++++++ test/factories/tips.rb | 7 +++++++ test/factories/users.rb | 7 +++++++ test/fixtures/.keep | 0 test/fixtures/deposits.yml | 17 ----------------- test/fixtures/projects.yml | 9 --------- test/fixtures/sendmanies.yml | 13 ------------- test/fixtures/tips.yml | 13 ------------- test/fixtures/users.yml | 11 ----------- test/mailers/user_mailer_test.rb | 11 ++++++----- test/test_helper.rb | 7 ++++++- 18 files changed, 65 insertions(+), 85 deletions(-) create mode 100644 test/factories/deposits.rb create mode 100644 test/factories/projects.rb create mode 100644 test/factories/sendmanies.rb create mode 100644 test/factories/tips.rb create mode 100644 test/factories/users.rb delete mode 100644 test/fixtures/.keep delete mode 100644 test/fixtures/deposits.yml delete mode 100644 test/fixtures/projects.yml delete mode 100644 test/fixtures/sendmanies.yml delete mode 100644 test/fixtures/tips.yml delete mode 100644 test/fixtures/users.yml diff --git a/Gemfile b/Gemfile index 8f72fdae..d1cde0cc 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,8 @@ gem 'octokit' # Use debugger # gem 'debugger', group: [:development, :test] +gem 'factory_girl_rails', group: [:development, :test] + group :development do gem 'capistrano', '~> 3.0' gem 'capistrano-rvm', github: 'capistrano/rvm' @@ -63,4 +65,4 @@ group :development do gem 'capistrano-rails' end -gem 'airbrake' \ No newline at end of file +gem 'airbrake' diff --git a/Gemfile.lock b/Gemfile.lock index 30bc5d1a..e6102703 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,6 +78,11 @@ GEM warden (~> 1.2.3) erubis (2.7.0) execjs (2.0.2) + factory_girl (4.3.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.3.0) + factory_girl (~> 4.3.0) + railties (>= 3.0.0) faraday (0.8.9) multipart-post (~> 1.2.0) haml (4.0.5) @@ -217,6 +222,7 @@ DEPENDENCIES capistrano-rvm! coffee-rails (~> 4.0.0) devise + factory_girl_rails haml-rails jbuilder (~> 1.2) jquery-rails diff --git a/config/environments/test.rb b/config/environments/test.rb index 799d7195..10065d4a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -30,6 +30,8 @@ # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.action_mailer.raise_delivery_errors = false + config.action_mailer.default_url_options = { :host => "localhost:3000" } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/test/controllers/projects_controller_test.rb b/test/controllers/projects_controller_test.rb index 636444b0..711941be 100644 --- a/test/controllers/projects_controller_test.rb +++ b/test/controllers/projects_controller_test.rb @@ -5,10 +5,4 @@ class ProjectsControllerTest < ActionController::TestCase get :index assert_response :success end - - test "should get show" do - get :show - assert_response :success - end - end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 54ba7d94..b15265a6 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,14 +1,9 @@ require 'test_helper' class UsersControllerTest < ActionController::TestCase - test "should get show" do - get :show - assert_response :success + test "should redirect if not loggedd in" do + create(:user) + get :show, {:id => 1} + assert_response :redirect end - - test "should get update" do - get :update - assert_response :success - end - end diff --git a/test/factories/deposits.rb b/test/factories/deposits.rb new file mode 100644 index 00000000..f3a732ee --- /dev/null +++ b/test/factories/deposits.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :deposit do + association :project + txid "txid" + confirmations 1 + duration 1 + paid_out 1 + paid_out_at "2013-10-19 23:01:22" + end +end diff --git a/test/factories/projects.rb b/test/factories/projects.rb new file mode 100644 index 00000000..d50d5eec --- /dev/null +++ b/test/factories/projects.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :project do + url "MyString" + bitcoin_address "bitcoin_address" + end +end diff --git a/test/factories/sendmanies.rb b/test/factories/sendmanies.rb new file mode 100644 index 00000000..6cf19257 --- /dev/null +++ b/test/factories/sendmanies.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :sendmany do + txid "txid" + data "MyText" + result "MyString" + is_error false + end +end diff --git a/test/factories/tips.rb b/test/factories/tips.rb new file mode 100644 index 00000000..412b81c0 --- /dev/null +++ b/test/factories/tips.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :tip do + association :user + association :project + amount 1 + end +end diff --git a/test/factories/users.rb b/test/factories/users.rb new file mode 100644 index 00000000..e083293a --- /dev/null +++ b/test/factories/users.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :user do + email "john@doge.com" + password "password" + login_token "login_token" + end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/deposits.yml b/test/fixtures/deposits.yml deleted file mode 100644 index 0b8407f8..00000000 --- a/test/fixtures/deposits.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - project_id: - txid: MyString - confirmations: 1 - duration: 1 - paid_out: 1 - paid_out_at: 2013-10-19 23:01:22 - -two: - project_id: - txid: MyString - confirmations: 1 - duration: 1 - paid_out: 1 - paid_out_at: 2013-10-19 23:01:22 diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml deleted file mode 100644 index 51df7832..00000000 --- a/test/fixtures/projects.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - url: MyString - bitcoin_address: MyString - -two: - url: MyString - bitcoin_address: MyString diff --git a/test/fixtures/sendmanies.yml b/test/fixtures/sendmanies.yml deleted file mode 100644 index e6dd6dd9..00000000 --- a/test/fixtures/sendmanies.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - txid: MyString - data: MyText - result: MyString - is_error: false - -two: - txid: MyString - data: MyText - result: MyString - is_error: false diff --git a/test/fixtures/tips.yml b/test/fixtures/tips.yml deleted file mode 100644 index 1f9726c4..00000000 --- a/test/fixtures/tips.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - user_id: - amount: 1 - sendmany_id: - refunded_at: false - -two: - user_id: - amount: 1 - sendmany_id: - refunded_at: false diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml deleted file mode 100644 index c63aac0b..00000000 --- a/test/fixtures/users.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/mailers/user_mailer_test.rb b/test/mailers/user_mailer_test.rb index 19ab1f83..10b70006 100644 --- a/test/mailers/user_mailer_test.rb +++ b/test/mailers/user_mailer_test.rb @@ -2,11 +2,12 @@ class UserMailerTest < ActionMailer::TestCase test "new_tip" do - mail = UserMailer.new_tip - assert_equal "New tip", mail.subject - assert_equal ["to@example.org"], mail.to - assert_equal ["from@example.com"], mail.from - assert_match "Hi", mail.body.encoded + tip = build(:tip) + + mail = UserMailer.new_tip tip.user, tip + assert_equal "You received a tip for your commit", mail.subject + assert_equal ["john@doge.com"], mail.to + assert_match "Hello", mail.body.encoded end end diff --git a/test/test_helper.rb b/test/test_helper.rb index bc7e05d7..3251a053 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,7 +9,12 @@ class ActiveSupport::TestCase # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting - fixtures :all + # fixtures :all # Add more helper methods to be used by all tests here... + include FactoryGirl::Syntax::Methods +end + +class ActionController::TestCase + include Devise::TestHelpers end From 3f38ca491f37b15f8ac7876dd758c701d1f33bca Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 00:39:37 +0700 Subject: [PATCH 05/19] update user nickname --- app/models/project.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index 2f632d87..a81a3ff6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -73,6 +73,10 @@ def tip_for commit }) end + if commit.author && commit.author.login + user.update nickname: commit.author.login + end + # create tip tip = Tip.create({ project: self, From 008a84f61fb3769eb1c6d713495b71ebf45c8f53 Mon Sep 17 00:00:00 2001 From: Lipis Date: Sun, 9 Feb 2014 01:13:08 +0100 Subject: [PATCH 06/19] Fixed case for GitHub brand name --- app/controllers/users/omniauth_callbacks_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index a3ffad82..e4751774 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -17,6 +17,6 @@ def github @user.save sign_in_and_redirect @user, :event => :authentication - set_flash_message(:notice, :success, :kind => "Github") if is_navigational_format? + set_flash_message(:notice, :success, :kind => "GitHub") if is_navigational_format? end -end \ No newline at end of file +end From 6776e71cd0cbd63b8ee86a4f7802ece6ad2816bb Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 09:29:59 +0700 Subject: [PATCH 07/19] changet projects description type to text --- db/migrate/20140209022632_change_projects_description.rb | 8 ++++++++ db/schema.rb | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140209022632_change_projects_description.rb diff --git a/db/migrate/20140209022632_change_projects_description.rb b/db/migrate/20140209022632_change_projects_description.rb new file mode 100644 index 00000000..a02592e2 --- /dev/null +++ b/db/migrate/20140209022632_change_projects_description.rb @@ -0,0 +1,8 @@ +class ChangeProjectsDescription < ActiveRecord::Migration + def up + change_column :projects, :description, :text, :limit => nil + end + def down + change_column :projects, :description, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 6998333c..9c4fe922 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140207061855) do +ActiveRecord::Schema.define(version: 20140209022632) do create_table "deposits", force: true do |t| t.integer "project_id" @@ -35,7 +35,7 @@ t.string "name" t.string "full_name" t.string "source_full_name" - t.string "description" + t.text "description" t.integer "watchers_count" t.string "language" t.string "last_commit" From 653add9dfa9d97cb622fe48fe4fdeb8b3ec5176e Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 11:16:13 +0700 Subject: [PATCH 08/19] validates presence and uniqueness of full_name and github_id --- app/controllers/users/omniauth_callbacks_controller.rb | 2 +- app/models/project.rb | 6 +++++- db/migrate/20140209041123_create_indexes_for_projects.rb | 6 ++++++ db/schema.rb | 5 ++++- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20140209041123_create_indexes_for_projects.rb diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index e4751774..1faa8447 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -15,7 +15,7 @@ def github @user.name = info['name'] @user.image = info['image'] @user.save - + sign_in_and_redirect @user, :event => :authentication set_flash_message(:notice, :success, :kind => "GitHub") if is_navigational_format? end diff --git a/app/models/project.rb b/app/models/project.rb index a81a3ff6..742127b4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -2,6 +2,9 @@ class Project < ActiveRecord::Base has_many :deposits # todo: only confirmed deposits that have amount > paid_out has_many :tips + validates :full_name, uniqueness: true, presence: true + validates :github_id, uniqueness: true, presence: true + def update_github_info repo self.github_id = repo.id self.name = repo.name @@ -69,7 +72,8 @@ def tip_for commit user = User.create({ email: email, password: generated_password, - name: commit.commit.author.name + name: commit.commit.author.name, + nickname: (commit.author.login rescue nil) }) end diff --git a/db/migrate/20140209041123_create_indexes_for_projects.rb b/db/migrate/20140209041123_create_indexes_for_projects.rb new file mode 100644 index 00000000..30f06922 --- /dev/null +++ b/db/migrate/20140209041123_create_indexes_for_projects.rb @@ -0,0 +1,6 @@ +class CreateIndexesForProjects < ActiveRecord::Migration + def change + add_index :projects, :full_name, :unique => true + add_index :projects, :github_id, :unique => true + end +end diff --git a/db/schema.rb b/db/schema.rb index 9c4fe922..17121771 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140209022632) do +ActiveRecord::Schema.define(version: 20140209041123) do create_table "deposits", force: true do |t| t.integer "project_id" @@ -43,6 +43,9 @@ t.string "github_id" end + add_index "projects", ["full_name"], name: "index_projects_on_full_name", unique: true + add_index "projects", ["github_id"], name: "index_projects_on_github_id", unique: true + create_table "sendmanies", force: true do |t| t.string "txid" t.text "data" From a339c2732fde0cef62c91164a65dd38f74ffd8eb Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 11:24:00 +0700 Subject: [PATCH 09/19] fixed tests --- config/application.rb | 2 ++ test/factories/projects.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/config/application.rb b/config/application.rb index 6495eac6..c560c739 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,3 +26,5 @@ class Application < Rails::Application config.autoload_paths += %W(#{config.root}/lib) end end + +I18n.enforce_available_locales = false diff --git a/test/factories/projects.rb b/test/factories/projects.rb index d50d5eec..aa0ea185 100644 --- a/test/factories/projects.rb +++ b/test/factories/projects.rb @@ -1,6 +1,8 @@ FactoryGirl.define do factory :project do url "MyString" + full_name "test/test" + github_id "1234567890" bitcoin_address "bitcoin_address" end end From aa8f4b80fc36a8d4db6ece534252213ad2f86419 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 19:55:47 +0700 Subject: [PATCH 10/19] added travis-ci --- .travis.yml | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..83499550 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: ruby +rvm: + - 2.0.0 diff --git a/README.md b/README.md index 87254791..8fd3cf95 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Tip4commit ========== -[![tip for next commit](http://tip4commit.com/projects/307.svg)](http://tip4commit.com/projects/307) +[![tip for next commit](http://tip4commit.com/projects/307.svg)](http://tip4commit.com/projects/307) [![Build Status](https://travis-ci.org/tip4commit/tip4commit.png?branch=master)](https://travis-ci.org/tip4commit/tip4commit) Donate bitcoins to open source projects or make commits and get tips for it. From c865250240dd634e3df00708f539407ac4302c18 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 20:09:23 +0700 Subject: [PATCH 11/19] config for travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 83499550..12554f8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ language: ruby rvm: - 2.0.0 +before_script: + - cp config/config.yml.sample config/config.yml From b29a0a4d197798835e8945cfcdf9b79ae0be4267 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 9 Feb 2014 20:13:37 +0700 Subject: [PATCH 12/19] database configuration for travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 12554f8c..06cf186d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,4 @@ rvm: - 2.0.0 before_script: - cp config/config.yml.sample config/config.yml + - cp config/database.yml.sample config/database.yml From d45aaca56bc397cc28f01d4192b3921e82991504 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Thu, 13 Feb 2014 23:23:19 +0700 Subject: [PATCH 13/19] update balance cache after receiving a deposit --- app/controllers/home_controller.rb | 13 +++++++------ app/mailers/user_mailer.rb | 2 +- app/models/project.rb | 6 +++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 65a6314d..d6f5660b 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -6,7 +6,7 @@ def blockchain_info_callback # todo: check if remote IP address belongs to blockchain.info if (params[:secret]!=CONFIG["blockchain_info"]["callback_secret"]) - render :text => "Invalid secret #{params}!" + render :text => "Invalid secret #{params}!" return end @@ -19,7 +19,7 @@ def blockchain_info_callback if deposit = Deposit.find_by_txid(params[:transaction_hash]) deposit.update_attribute(:confirmations, confirmations = params[:confirmations]) if !test - if confirmations.to_i > 6 + if confirmations.to_i > 6 render :text => "*ok*" else render :text => "Deposit #{deposit.id} updated!" @@ -28,7 +28,7 @@ def blockchain_info_callback end if project = Project.find_by_bitcoin_address(params[:input_address]) - ( + if !test deposit = Deposit.create({ project_id: project.id, txid: params[:transaction_hash], @@ -38,11 +38,12 @@ def blockchain_info_callback paid_out: 0, paid_out_at: Time.now }) - ) if !test - render :text => "Deposit #{deposit[:txid]} has been created!" + project.update_cache + end + render :text => "Deposit #{deposit[:txid]} has been created!" else render :text => "Project with deposit address #{params[:input_address]} is not found!" end end - + end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index e21ded23..54d1fe16 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,6 +1,6 @@ class UserMailer < ActionMailer::Base add_template_helper(ApplicationHelper) - + def new_tip user, tip @user = user @tip = tip diff --git a/app/models/project.rb b/app/models/project.rb index 742127b4..d7ba8dcb 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -122,9 +122,13 @@ def next_tip_amount (CONFIG["tip"]*available_amount).ceil end + def update_cache + update available_amount_cache: project.available_amount + end + def self.update_cache find_each do |project| - project.update available_amount_cache: project.available_amount + project.update_cache end end From bd045d98134a891aa7b5c582e033d95565a31885 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Thu, 13 Feb 2014 23:29:17 +0700 Subject: [PATCH 14/19] fixed label for tips that will be withdrawn soon --- app/views/tips/index.html.haml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/views/tips/index.html.haml b/app/views/tips/index.html.haml index 0b7093ad..ac4363c8 100644 --- a/app/views/tips/index.html.haml +++ b/app/views/tips/index.html.haml @@ -26,17 +26,18 @@ = link_to tip.user.full_name, "https://github.com/#{tip.user.nickname}", target: '_blank' - unless @project %td= link_to tip.project.full_name, tip.project - %td= link_to tip.commit[0..6], "https://github.com/#{tip.project.full_name}/commit/#{tip.commit}", target: :blank + %td= link_to tip.commit[0..6], "https://github.com/#{tip.project.full_name}/commit/#{tip.commit}", target: :blank %td= btc_human tip.amount %td - if tip.sendmany.nil? - if tip.refunded_at Refunded to project's deposit + - elsif tip.user.bitcoin_address.blank? + User didn't specify withdrawal address + - elsif tip.user.balance < CONFIG["min_payout"] + User's balance is below withdrawal threshold - else - - if tip.user.bitcoin_address.blank? - User didn't specify withdrawal address - - else - User's balance is below withdrawal threshold + Waiting for withdrawal - else - = link_to tip.sendmany.txid, "https://blockchain.info/tx/#{tip.sendmany.txid}", target: :blank - = paginate @tips \ No newline at end of file + = link_to tip.sendmany.txid, "https://blockchain.info/tx/#{tip.sendmany.txid}", target: :blank + = paginate @tips From 8876ada14cd03b43944cbbc6e1e884f027ad8b6e Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Thu, 13 Feb 2014 23:44:31 +0700 Subject: [PATCH 15/19] fix --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index d7ba8dcb..4d6cc7ae 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -123,7 +123,7 @@ def next_tip_amount end def update_cache - update available_amount_cache: project.available_amount + update available_amount_cache: available_amount end def self.update_cache From 0f38bbd293ae4012a91844befcb261db3869c761 Mon Sep 17 00:00:00 2001 From: danbartram Date: Thu, 13 Feb 2014 18:38:12 +0000 Subject: [PATCH 16/19] Fixed margins in nav bar on mobile Removed the margin-bottom rule from: .nav-justified>li>a of the /assets/application-25b8d7709fc3c19033d1292decf2d537.css:3892 (line 3892) to remove the empty space at mobile resolutions. [Before](http://i.imgur.com/2egBnON.png) [After](http://i.imgur.com/YHL4TV8.png) --- app/assets/stylesheets/justified-nav.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/justified-nav.css b/app/assets/stylesheets/justified-nav.css index 35e84503..0bfb4ac9 100644 --- a/app/assets/stylesheets/justified-nav.css +++ b/app/assets/stylesheets/justified-nav.css @@ -27,6 +27,7 @@ body { border: 1px solid #ccc; } .nav-justified > li > a { + margin-bottom: 0; padding-top: 15px; padding-bottom: 15px; color: #777; @@ -85,4 +86,4 @@ body { padding-left: 0; padding-right: 0; } -} \ No newline at end of file +} From dc12ebaa076f24a7f5c4f26649fcbf51b1719d75 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sat, 15 Feb 2014 10:12:41 +0700 Subject: [PATCH 17/19] don't show old uncorfirmed deposits sendmany has_many tips --- app/assets/stylesheets/justified-nav.css | 2 +- app/helpers/application_helper.rb | 2 -- app/models/project.rb | 2 +- app/models/sendmany.rb | 2 ++ app/views/projects/show.html.haml | 10 +++---- lib/bitcoin_tipper.rb | 34 +++++++++++++----------- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/assets/stylesheets/justified-nav.css b/app/assets/stylesheets/justified-nav.css index 35e84503..7837acf4 100644 --- a/app/assets/stylesheets/justified-nav.css +++ b/app/assets/stylesheets/justified-nav.css @@ -85,4 +85,4 @@ body { padding-left: 0; padding-right: 0; } -} \ No newline at end of file +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d4b6fb29..7fa6599e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,9 +1,7 @@ module ApplicationHelper def btc_human amount, options = {} nobr = options.has_key?(:nobr) ? options[:nobr] : true - currency = options[:currency] || false btc = "%.8f Ƀ" % to_btc(amount) - btc = "#{btc}" if currency btc = "#{btc}" if nobr btc.html_safe end diff --git a/app/models/project.rb b/app/models/project.rb index 4d6cc7ae..9c34ada8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -107,7 +107,7 @@ def available_amount end def unconfirmed_amount - self.deposits.where(:confirmations => 0).map(&:available_amount).sum + self.deposits.where(:confirmations => 0).where('created_at > ?', 7.days.ago).map(&:available_amount).sum end def tips_paid_amount diff --git a/app/models/sendmany.rb b/app/models/sendmany.rb index a0f46092..64838a5c 100644 --- a/app/models/sendmany.rb +++ b/app/models/sendmany.rb @@ -1,4 +1,6 @@ class Sendmany < ActiveRecord::Base + has_many :tips + def send_transaction return if txid || is_error diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 29c8bb9a..43c890db 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -3,7 +3,7 @@ = @project.name - content_for :description do = @project.description - + %h1 = @project.full_name %small= link_to glyph(:github), @project.github_url, target: '_blank' @@ -20,7 +20,7 @@ %span(data-coingiving="title")= "[tip4commit] " + @project.full_name %span(data-coingiving="description")= @project.description %span(data-coingiving="bitcoin-address")= @project.bitcoin_address - %p #{100-(CONFIG["our_fee"]*100).round}% of deposited funds will be used to tip for new commits. + %p #{100-(CONFIG["our_fee"]*100).round}% of deposited funds will be used to tip for new commits. .col-md-8 - unless @project.description.blank? .well.well-sm= @project.description @@ -64,11 +64,11 @@ - if current_user - if current_user.bitcoin_address.blank? - Just + Just = link_to 'tell us', current_user - your bitcoin address. + your bitcoin address. - else - Just check your email or + Just check your email or %a{href: user_omniauth_authorize_path(:github)} Sign In. %h4 Promote #{@project.full_name} diff --git a/lib/bitcoin_tipper.rb b/lib/bitcoin_tipper.rb index 45bae235..73e7486b 100644 --- a/lib/bitcoin_tipper.rb +++ b/lib/bitcoin_tipper.rb @@ -5,7 +5,7 @@ def self.work_forever end end - def self.work + def self.work withdraw = true Rails.logger.info "Traversing projects..." Project.find_each do |project| if project.available_amount > 0 @@ -15,25 +15,27 @@ def self.work end Rails.logger.info "Updating projects info..." - Project.order(:updated_at => :desc).last(5).each do |project| + Project.order(:updated_at => :desc).last(10).each do |project| Rails.logger.info " Project #{project.id} #{project.full_name}" project.update_info end - Rails.logger.info "Traversing users..." - is_sendmany_needed = false - User.find_each do |user| - if user.bitcoin_address.present? && user.balance > CONFIG["min_payout"] - is_sendmany_needed = true - Rails.logger.info "Sendmany is needed" + if withdraw + Rails.logger.info "Traversing users..." + is_sendmany_needed = false + User.find_each do |user| + if user.bitcoin_address.present? && user.balance > CONFIG["min_payout"] + is_sendmany_needed = true + Rails.logger.info "Sendmany is needed" + end end - end - self.create_sendmany if is_sendmany_needed + self.create_sendmany if is_sendmany_needed - Rails.logger.info "Traversing sendmanies..." - Sendmany.where(txid: nil).each do |sendmany| - sendmany.send_transaction + Rails.logger.info "Traversing sendmanies..." + Sendmany.where(txid: nil).each do |sendmany| + sendmany.send_transaction + end end Rails.logger.info "Refunding unclaimed tips..." @@ -53,7 +55,7 @@ def self.create_sendmany outs = {} User.find_each do |user| if user.bitcoin_address.present? && user.balance > CONFIG["min_payout"] - user.tips.unpaid.each do |tip| + user.tips.unpaid.each do |tip| tip.update_attribute :sendmany_id, sendmany.id outs[user.bitcoin_address] = outs[user.bitcoin_address].to_i + tip.amount end @@ -61,7 +63,7 @@ def self.create_sendmany end sendmany.update_attribute :data, outs.to_json Rails.logger.info " #{sendmany.inspect}" - end + end end -end \ No newline at end of file +end From 5c4d061e14a1371102695effb6479d0d6a9e8d33 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sat, 15 Feb 2014 10:44:07 +0700 Subject: [PATCH 18/19] added deposit address for hot wallet --- app/controllers/home_controller.rb | 5 ++++- config/config.yml.sample | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d6f5660b..88cc00b8 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -27,7 +27,10 @@ def blockchain_info_callback return end - if project = Project.find_by_bitcoin_address(params[:input_address]) + if params[:input_address] == CONFIG['deposit_address'] + # Deposit from the cold wallet + render :text => "*ok*" + elsif project = Project.find_by_bitcoin_address(params[:input_address]) if !test deposit = Deposit.create({ project_id: project.id, diff --git a/config/config.yml.sample b/config/config.yml.sample index 992b3052..da55a320 100644 --- a/config/config.yml.sample +++ b/config/config.yml.sample @@ -1,6 +1,6 @@ github: key: "111111111111" - secret: "111111111111" + secret: "111111111111" blockchain_info: guid: "111111111111" @@ -30,4 +30,6 @@ smtp_settings: tip: 0.01 min_payout: 100000 -our_fee: 0.05 \ No newline at end of file +our_fee: 0.05 + +deposit_address: 1M4bS4gPyA6Kb8w7aXsgth9oUZWcRk73tQ From a3e0495a826ab6e5434270c35f5cc9ffedcf5c3c Mon Sep 17 00:00:00 2001 From: Michael Witrant Date: Sat, 15 Feb 2014 18:24:23 +0100 Subject: [PATCH 19/19] use nickname to link github account to user --- app/controllers/users/omniauth_callbacks_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 1faa8447..dbd06e18 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -2,7 +2,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def github # render text: "#{request.env["omniauth.auth"].to_json}" info = request.env["omniauth.auth"]["info"] - @user = User.find_by :email => info["email"] + @user = User.find_by :nickname => info["nickname"] + @user ||= User.find_by :email => info["email"] unless @user generated_password = Devise.friendly_token.first(8) @user = User.create!(