Skip to content

Commit 653add9

Browse files
committed
validates presence and uniqueness of full_name and github_id
1 parent 6776e71 commit 653add9

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def github
1515
@user.name = info['name']
1616
@user.image = info['image']
1717
@user.save
18-
18+
1919
sign_in_and_redirect @user, :event => :authentication
2020
set_flash_message(:notice, :success, :kind => "GitHub") if is_navigational_format?
2121
end

app/models/project.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ class Project < ActiveRecord::Base
22
has_many :deposits # todo: only confirmed deposits that have amount > paid_out
33
has_many :tips
44

5+
validates :full_name, uniqueness: true, presence: true
6+
validates :github_id, uniqueness: true, presence: true
7+
58
def update_github_info repo
69
self.github_id = repo.id
710
self.name = repo.name
@@ -69,7 +72,8 @@ def tip_for commit
6972
user = User.create({
7073
email: email,
7174
password: generated_password,
72-
name: commit.commit.author.name
75+
name: commit.commit.author.name,
76+
nickname: (commit.author.login rescue nil)
7377
})
7478
end
7579

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class CreateIndexesForProjects < ActiveRecord::Migration
2+
def change
3+
add_index :projects, :full_name, :unique => true
4+
add_index :projects, :github_id, :unique => true
5+
end
6+
end

db/schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20140209022632) do
14+
ActiveRecord::Schema.define(version: 20140209041123) do
1515

1616
create_table "deposits", force: true do |t|
1717
t.integer "project_id"
@@ -43,6 +43,9 @@
4343
t.string "github_id"
4444
end
4545

46+
add_index "projects", ["full_name"], name: "index_projects_on_full_name", unique: true
47+
add_index "projects", ["github_id"], name: "index_projects_on_github_id", unique: true
48+
4649
create_table "sendmanies", force: true do |t|
4750
t.string "txid"
4851
t.text "data"

0 commit comments

Comments
 (0)