Skip to content

Commit 6afd641

Browse files
committed
Creating the basic score model
1 parent 8a180fe commit 6afd641

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ group :production do
2828
end
2929

3030
group :development do
31-
gem 'pry-rails'
3231
gem 'better_errors'
3332
end
3433

3534
group :development, :test do
35+
gem 'pry-rails'
3636
gem "rspec-rails", "~> 2.0"
3737
end
3838
# To use ActiveModel has_secure_password

app/models/score.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Score < ActiveRecord::Base
2+
belongs_to :warrior
3+
validates_presence_of :warrior
4+
attr_accessible :clear_bonus, :level_number, :level_score, :time_bonus, :total_score
5+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CreateScores < ActiveRecord::Migration
2+
def change
3+
create_table :scores do |t|
4+
t.references :warrior, null: false
5+
t.integer :level_number, null: false
6+
t.integer :level_score, null: false
7+
t.integer :time_bonus, null: false
8+
t.integer :clear_bonus
9+
t.integer :total_score
10+
11+
t.timestamps
12+
end
13+
end
14+
end

db/schema.rb

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

14-
ActiveRecord::Schema.define(:version => 20141115000801) do
14+
ActiveRecord::Schema.define(:version => 20141115001645) do
15+
16+
create_table "scores", :force => true do |t|
17+
t.integer "warrior_id", :null => false
18+
t.integer "level_number", :null => false
19+
t.integer "level_score", :null => false
20+
t.integer "time_bonus", :null => false
21+
t.integer "clear_bonus"
22+
t.integer "total_score"
23+
t.datetime "created_at", :null => false
24+
t.datetime "updated_at", :null => false
25+
end
1526

1627
create_table "warriors", :force => true do |t|
1728
t.string "name"

spec/models/score_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'spec_helper'
2+
3+
describe Score do
4+
let(:score) { Score.new }
5+
6+
it "must have a warrior" do
7+
score.valid?
8+
expect(score.errors[:warrior].size).to eq(1)
9+
end
10+
end

0 commit comments

Comments
 (0)