Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User story 1 #17

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
128 changes: 64 additions & 64 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,67 +38,66 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (8.0.0)
bindex (0.7.0)
builder (3.2.3)
capybara (3.25.0)
bindex (0.8.1)
builder (3.2.4)
capybara (3.34.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
xpath (~> 3.2)
coderay (1.1.2)
coderay (1.1.3)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
database_cleaner (1.7.0)
diff-lcs (1.3)
docile (1.3.2)
erubi (1.8.0)
concurrent-ruby (1.1.7)
crass (1.0.6)
database_cleaner (1.8.5)
diff-lcs (1.4.4)
docile (1.3.3)
erubi (1.10.0)
execjs (2.7.0)
ffi (1.11.1)
ffi (1.14.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
json (2.2.0)
launchy (2.4.3)
addressable (~> 2.3)
jbuilder (2.10.1)
activesupport (>= 5.0.0)
launchy (2.5.0)
addressable (~> 2.7)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.3)
loofah (2.8.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.9.2)
mini_mime (1.0.1)
method_source (1.0.0)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
nio4r (2.3.1)
nokogiri (1.10.3)
minitest (5.14.2)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
pg (0.21.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.1.1)
puma (3.12.1)
rack (2.0.7)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.6)
puma (3.12.6)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.1.7)
Expand All @@ -116,36 +115,36 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (5.1.7)
actionpack (= 5.1.7)
activesupport (= 5.1.7)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
rake (13.0.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (1.5.1)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
regexp_parser (1.8.2)
rspec-core (3.10.0)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.1)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rspec-support (~> 3.10.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.10.0)
ruby_dep (1.5.0)
sass (3.7.4)
sass-listen (~> 4.0.0)
Expand All @@ -158,26 +157,27 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
shoulda-matchers (4.1.0)
shoulda-matchers (4.4.1)
activesupport (>= 4.2.0)
simplecov (0.17.0)
simplecov (0.20.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.3)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.9)
tzinfo (1.2.5)
tilt (2.0.10)
tzinfo (1.2.9)
thread_safe (~> 0.1)
uglifier (4.1.20)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
web-console (3.7.0)
actionview (>= 5.0)
Expand All @@ -186,7 +186,7 @@ GEM
railties (>= 5.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)

Expand All @@ -213,4 +213,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
2.0.2
2.1.4
5 changes: 5 additions & 0 deletions app/controllers/astronauts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AstronautsController < ApplicationController
def index
@astronauts = Astronaut.all
end
end
2 changes: 2 additions & 0 deletions app/models/astronaut.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Astronaut < ApplicationRecord
validates_presence_of :name, :age, :job
has_many :astronaut_missions
has_many :missions, through: :astronaut_missions
end
3 changes: 2 additions & 1 deletion app/models/astronaut_mission.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class AstronautMission < ApplicationRecord

belongs_to :astronaut
belongs_to :mission
end
2 changes: 2 additions & 0 deletions app/models/mission.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Mission < ApplicationRecord
validates_presence_of :title, :time_in_space
has_many :astronaut_missions
has_many :astronauts, through: :astronaut_missions
end
8 changes: 8 additions & 0 deletions app/views/astronauts/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Astronauts</h1>
<% @astronauts.each do |astronaut| %>
<section id="astronaut-<%= astronaut.id %>">
<h2><%= astronaut.name %></h2>
<p>Age: <%= astronaut.age %></p>
<p>Job: <%= astronaut.job %></p>
</section>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

resources :astronauts, only: [:index]
end
38 changes: 38 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180904152506) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "astronaut_missions", force: :cascade do |t|
t.bigint "astronaut_id"
t.bigint "mission_id"
t.index ["astronaut_id"], name: "index_astronaut_missions_on_astronaut_id"
t.index ["mission_id"], name: "index_astronaut_missions_on_mission_id"
end

create_table "astronauts", force: :cascade do |t|
t.string "name"
t.integer "age"
t.string "job"
end

create_table "missions", force: :cascade do |t|
t.string "title"
t.integer "time_in_space"
end

add_foreign_key "astronaut_missions", "astronauts"
add_foreign_key "astronaut_missions", "missions"
end
14 changes: 14 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

astro1 = Astronaut.create!(name: "Bob", age: 34, job: "Commander")
astro2 = Astronaut.create!(name: "Jill", age: 34, job: "Private")
astro3 = Astronaut.create!(name: "Joe", age: 34, job: "Colonel")
astro4 = Astronaut.create!(name: "Has", age: 34, job: "Lieutenant")

mission1 = Mission.create!(title: "Mission to Mars", time_in_space: 20)
mission2 = Mission.create!(title: "Mission to Moon", time_in_space: 1)
mission3 = Mission.create!(title: "Mission to Sun", time_in_space: 80)

AstronautMission.create!(astronaut: astro1, mission: mission1)
AstronautMission.create!(astronaut: astro1, mission: mission2)
AstronautMission.create!(astronaut: astro2, mission: mission3)
AstronautMission.create!(astronaut: astro3, mission: mission3)
51 changes: 51 additions & 0 deletions spec/features/astronauts/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "rails_helper"

describe "As a visitor" do
describe "When I visit '/astronauts'" do
before :each do
@astro1 = Astronaut.create!(name: "Bob", age: 34, job: "Commander")
@astro2 = Astronaut.create!(name: "Jill", age: 34, job: "Private")
@astro3 = Astronaut.create!(name: "Joe", age: 34, job: "Colonel")
@astro4 = Astronaut.create!(name: "Has", age: 34, job: "Lieutenant")

@mission1 = Mission.create!(title: "Mission to Mars", time_in_space: 20)
@mission2 = Mission.create!(title: "Mission to Moon", time_in_space: 1)
@mission3 = Mission.create!(title: "Mission to Sun", time_in_space: 80)

@w = AstronautMission.create!(astronaut: @astro1, mission: @mission1)
@x = AstronautMission.create!(astronaut: @astro1, mission: @mission2)
@y = AstronautMission.create!(astronaut: @astro2, mission: @mission3)
@z = AstronautMission.create!(astronaut: @astro3, mission: @mission3)
end

it "I see a list of astronauts with the following info:" do
visit astronauts_path

expect(page).to have_content("Astronauts")

within("#astronaut-#{@astro1.id}") do
expect(page).to have_content(@astro1.name)
expect(page).to have_content("Age: #{@astro1.age}")
expect(page).to have_content("Job: #{@astro1.job}")
end

within("#astronaut-#{@astro2.id}") do
expect(page).to have_content(@astro2.name)
expect(page).to have_content("Age: #{@astro2.age}")
expect(page).to have_content("Job: #{@astro2.job}")
end

within("#astronaut-#{@astro3.id}") do
expect(page).to have_content(@astro3.name)
expect(page).to have_content("Age: #{@astro3.age}")
expect(page).to have_content("Job: #{@astro3.job}")
end

within("#astronaut-#{@astro4.id}") do
expect(page).to have_content(@astro4.name)
expect(page).to have_content("Age: #{@astro4.age}")
expect(page).to have_content("Job: #{@astro4.job}")
end
end
end
end
11 changes: 11 additions & 0 deletions spec/models/astronaut_mission_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rails_helper'

describe AstronautMission, type: :model do
describe 'Validations' do
end

describe 'Relationships' do
it { should belong_to :astronaut}
it { should belong_to :mission}
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@
# as the one that triggered the failure.
Kernel.srand config.seed
=end

end