Skip to content

Commit

Permalink
Merge pull request #20 from rubyforgood/view-targets
Browse files Browse the repository at this point in the history
View targets
  • Loading branch information
gxespino committed Jun 8, 2018
2 parents 9ccd464 + 79e7c8c commit cbe3afd
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ gem 'rails', '~> 5.2.0'

group :development, :test do
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'capybara'
gem 'rspec-rails'
gem 'rubocop', require: false
gem 'shoulda-matchers', '~> 3.1'
Expand All @@ -23,3 +22,7 @@ group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'web-console', '>= 3.3.0'
end

group :test do
gem 'capybara'
end
4 changes: 4 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ class ProjectsController < ApplicationController
def index
@projects = Project.all
end

def show
@project = Project.find(params[:id])
end
end
8 changes: 8 additions & 0 deletions app/controllers/targets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class TargetsController < ApplicationController
def index
@project = Project.find(params[:project_id])
@targets = @project.targets
end
end
1 change: 1 addition & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to 'View all targets', project_targets_url(@project) %>
7 changes: 7 additions & 0 deletions app/views/targets/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1><%= @project.name %></h1>

<ul>
<%= @targets.each do |target| %>
<li><h2><%= target.name %></h2></li>
<% end %>
</ul>
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Rails.application.routes.draw do
root 'projects#index'
resources :projects
resources :projects do
resources :targets
end

devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
22 changes: 22 additions & 0 deletions spec/features/user_views_targets_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rails_helper'

feature 'Target management' do
scenario 'User can view all targets for a Project' do
project_name = 'TEST PROJECT'
target_one_name = 'TEST TARGET ONE'
target_two_name = 'TEST TARGET TWO'

project = Project.create(name: project_name)
Target.create(name: target_one_name, project: project)
Target.create(name: target_two_name, project: project)
Target.create(name: 'NOT MY TARGET', project: Project.create)

visit "/projects/#{project.id}"
click_link 'View all targets'

expect(page).to have_text(project_name)
expect(page).to have_text(target_one_name)
expect(page).to have_text(target_two_name)
expect(page).not_to have_text('NOT MY TARGET')
end
end
5 changes: 2 additions & 3 deletions spec/features/user_visits_projects_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'rails_helper'

RSpec.feature 'Projects', type: :feature do

feature 'Projects' do
scenario 'user visits projects index' do
visit root_path
expect(page).to have_content "Projects"
end
end
end

0 comments on commit cbe3afd

Please sign in to comment.