Skip to content

Commit 8a54678

Browse files
committed
add api keys for apps
1 parent 754ba9d commit 8a54678

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

app/models/api_key.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApiKey < ApplicationRecord
2+
belongs_to :user
3+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateApiKeys < ActiveRecord::Migration[5.2]
2+
def change
3+
create_table :api_keys do |t|
4+
t.references :user, foreign_key: true
5+
t.string :key
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

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

13-
ActiveRecord::Schema.define(version: 2018_09_10_090212) do
13+
ActiveRecord::Schema.define(version: 2018_09_17_033731) do
14+
15+
create_table "api_keys", force: :cascade do |t|
16+
t.integer "user_id"
17+
t.string "key"
18+
t.datetime "created_at", null: false
19+
t.datetime "updated_at", null: false
20+
t.index ["user_id"], name: "index_api_keys_on_user_id"
21+
end
1422

1523
create_table "archenemyships", force: :cascade do |t|
1624
t.integer "user_id"

test/fixtures/api_keys.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
user: one
5+
key: MyString
6+
7+
two:
8+
user: two
9+
key: MyString

test/models/api_key_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class ApiKeyTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)