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

Pass Tests #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ source "https://rubygems.org"

gem 'sinatra', require: 'sinatra/base'
gem 'sinatra-reloader', require: false
gem 'shotgun'
gem 'shotgun', git: 'https://github.com/delonnewman/shotgun.git'
gem 'rack'
gem 'pry'
gem 'tux'
gem 'require_all'
Expand Down
142 changes: 86 additions & 56 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
GIT
remote: https://github.com/delonnewman/shotgun.git
revision: 600b3987db7f4774e2305247ff374327f1837857
specs:
shotgun (0.9.2)
rack (>= 1.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
backports (3.11.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
base64 (0.2.0)
bond (0.5.1)
capybara (2.17.0)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
coderay (1.1.2)
diff-lcs (1.3)
method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
multi_json (1.13.0)
mustermann (1.0.1)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.1)
rack (2.0.3)
rack-protection (2.0.0)
rack
rack-test (0.8.2)
rack (>= 1.0, < 3)
require_all (1.5.0)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
diff-lcs (1.5.1)
matrix (0.4.2)
method_source (1.1.0)
mini_mime (1.1.5)
multi_json (1.15.0)
mustermann (3.0.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.1)
racc (1.8.1)
rack (3.1.7)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
regexp_parser (2.9.2)
require_all (3.0.0)
ripl (0.7.1)
bond (~> 0.5.1)
ripl-multi_line (0.3.1)
Expand All @@ -39,57 +64,62 @@ GEM
rack (>= 1.0)
rack-test (>= 0.5)
ripl (>= 0.3.5)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (2.0.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
ruby2_keywords (0.0.5)
sinatra (4.0.0)
mustermann (~> 3.0)
rack (>= 3.0.0, < 4)
rack-protection (= 4.0.0)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
sinatra-contrib (4.0.0)
multi_json (>= 0.0.2)
mustermann (~> 3.0)
rack-protection (= 4.0.0)
sinatra (= 4.0.0)
tilt (~> 2.0)
sinatra-contrib (2.0.0)
backports (>= 2.0)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.0.0)
sinatra (= 2.0.0)
tilt (>= 1.3, < 3)
sinatra-reloader (1.0)
sinatra-contrib
tilt (2.0.8)
tilt (2.4.0)
tux (0.3.0)
ripl (>= 0.3.5)
ripl-multi_line (>= 0.2.4)
ripl-rack (>= 0.2.0)
sinatra (>= 1.2.1)
xpath (3.0.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
ruby
aarch64-linux
arm-linux
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux

DEPENDENCIES
capybara
pry
rack
rack-test
require_all
rspec
shotgun
shotgun!
sinatra
sinatra-reloader
tux

BUNDLED WITH
1.16.0
2.5.15
19 changes: 18 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
module FormsLab
class App < Sinatra::Base

# code other routes/actions here
get "/" do
erb :root
end

get "/new" do
erb :"pirates/new"
end

post "/pirates" do
@pirate = Pirate.new(params[:pirate])

params[:pirate][:ships].each do |details|
Ship.new(details)
end
@ships = Ship.all

erb :"pirates/show"
end

end
end
17 changes: 16 additions & 1 deletion app/models/pirate.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
class Pirate
end
attr_accessor :name, :weight, :height

@@pirates = []

def initialize(params)
# puts params[:name]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# puts params[:name]

@name = params[:name]
@weight = params[:weight]
@height = params[:height]
@@pirates << self
end

def self.all
@@pirates
end
end
20 changes: 19 additions & 1 deletion app/models/ship.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
class Ship
end
attr_accessor :name, :booty, :type

@@ships = []

def initialize(details)
@name = details[:name]
@booty = details[:booty]
@type = details[:type]
@@ships << self
end

def self.all
@@ships
end

def self.clear
@@ships = []
end
end
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
RSpec.configure do |config|
config.include Capybara::DSL
config.include Rack::Test::Methods
config.order = 'default'
# config.order = 'default'
end

def app
Rack::Builder.parse_file('config.ru').first
Rack::Builder.parse_file('config.ru')
end

Capybara.app = app
Capybara.app = app
46 changes: 45 additions & 1 deletion views/pirates/new.erb
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
<h1>Make your form here</h1>
<h1>Welcome to the Nested Forms Lab!</h1>
<p>Let's navigate to the <a href="/new">/new</a></p>

<form action="/pirates" method="POST">
<h3>Pirates</h3>
<div>
<label>Name</label>
<input type="text" name="pirate[name]"/>
</div>
<div>
<label>Weight</label>
<input type="text" name="pirate[weight]"/>
</div>
<div>
<label>Height</label>
<input type="text" name="pirate[height]"/>
</div>
<h3>Ship 1</h3>
<div>
<label>Ship Name</label>
<input type="text" id="ship_name_1" name="pirate[ships][][name]"/>
</div>
<div>
<label>Ship Booty</label>
<input type="text" id="ship_booty_1" name="pirate[ships][][booty]"/>
</div>
<div>
<label>Ship Type</label>
<input type="text" id="ship_type_1" name="pirate[ships][][type]"/>
</div>
<h3>Ship 2</h3>
<div>
<label>Ship Name</label>
<input type="text" id="ship_name_2" name="pirate[ships][][name]"/>
</div>
<div>
<label>Ship Booty</label>
<input type="text" id="ship_booty_2" name="pirate[ships][][booty]"/>
</div>
<div>
<label>Ship Type</label>
<input type="text" id="ship_type_2" name="pirate[ships][][type]"/>
</div>
<input type="submit" id="Submit" />
</form>
27 changes: 22 additions & 5 deletions views/pirates/show.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
<h1>Display your Pirate here</h1>
<p>
<%= @pirate.name %>
</p>
<p>
<%= @pirate.weight %>
</p>
<p>
<%= @pirate.height %>
</p>


<h2>Display your first ship here</h2>


<h2>Display your second ship here</h2>
<% @ships.each_with_index do |ship, index| %>
<% if index == 0 %>
<h2>Display your first ship here</h2>
<p>Name: <%= ship.name %></p>
<p>Booty: <%= ship.booty %></p>
<p>Type: <%= ship.type %></p>
<% elsif index == 1 %>
<h2>Display your second ship here</h2>
<p>Name: <%= ship.name %></p>
<p>Booty: <%= ship.booty %></p>
<p>Type: <%= ship.type %></p>
<% end %>
Comment on lines +13 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<% if index == 0 %>
<h2>Display your first ship here</h2>
<p>Name: <%= ship.name %></p>
<p>Booty: <%= ship.booty %></p>
<p>Type: <%= ship.type %></p>
<% elsif index == 1 %>
<h2>Display your second ship here</h2>
<p>Name: <%= ship.name %></p>
<p>Booty: <%= ship.booty %></p>
<p>Type: <%= ship.type %></p>
<% end %>
<h2>Display your <%= index == 0 ? "first" : "second" %> ship here</h2>
<p>Name: <%= ship.name %></p>
<p>Booty: <%= ship.booty %></p>
<p>Type: <%= ship.type %></p>

<% end %>