Skip to content

Commit

Permalink
StudentProfiles can be created by students with passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charlieperson committed Apr 6, 2016
1 parent 5aa384e commit 686b529
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 11 deletions.
4 changes: 0 additions & 4 deletions app/controllers/profiles_controller.rb

This file was deleted.

26 changes: 26 additions & 0 deletions app/controllers/student_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
class StudentProfilesController < ApplicationController
def show
end

def new
@student_profile = StudentProfile.new
end

def create
save_profile_and_redirect
end

private

def profile_params
params.require(:student_profile).permit(:name, :native_language, :learning_objectives)
end

def save_profile_and_redirect
@profile = StudentProfile.create(profile_params)
current_student.student_profile = @profile
if @profile.save
redirect_to student_profile_path(:id => current_student.id)
else
render 'new'
end
end
end
25 changes: 25 additions & 0 deletions app/views/student_profiles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_for(@student_profile) do |f| %>
<% if @student_profile.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@student_profile.errors.count, "error") %> prohibited this pin from being saved:</h2>

<ul>
<% @student_profile.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: "form-control" %>
<%= f.label :native_language %>
<%= f.text_field :native_language, class: "form-control" %>
<%= f.label :learning_objectives %>
<%= f.text_field :learning_objectives, class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>
5 changes: 5 additions & 0 deletions app/views/student_profiles/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>My Profile</h1>
<% if student_signed_in? %>
<%= link_to 'Back', student_profile_path(:id => current_student.id) %>
<%= render 'form' %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
<h1>You do not have a profile yet</h1>
<%= link_to 'Create Profile', new_student_profile_path %>
<% else %>
<%= current_student.student_profile.name %>
<%= current_student.student_profile.native_language %>
<%= current_student.student_profile.learning_objectives %>
<a href ="#">Edit profile</a>
<% end %>
8 changes: 8 additions & 0 deletions spec/factories/student_profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryGirl.define do
factory :student_profile do
id 1
name 'Test'
native_language 'French'
learning_objectives 'I want to speak english at restaurants'
end
end
29 changes: 22 additions & 7 deletions spec/features/student_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,37 @@
expect(page).to have_content 'You do not have a profile yet'
expect(page).to have_link 'Create Profile'
end

scenario 'A new student can fill out a new profile' do
click_link 'My profile'
click_link 'Create Profile'
fill_in 'Name', with: 'Test'
fill_in 'Native language', with: 'French'
fill_in 'Learning objectives', with: 'Learn english'
click_button 'Create Student profile'
expect(page).to have_content('Test')
expect(page).to have_content('French')
expect(page).to have_content('Learn english')
end
end

context 'Student is already signed up' do
before do
scenario 'students are directed to their specific profile page' do
sign_up
log_out_then_sign_in
end

scenario 'students are directed to their specific profile page' do
click_link 'My profile'
expect(current_path).to eq '/profiles/5'
expect(current_path).to eq '/student_profiles/6'
end

scenario 'student views their profile' do
expect(page).to have_content "I'm an amazing student from Spain"
expect(page).to have_link 'Edit Profile'
student = create(:student)
student.student_profile = create(:student_profile)
visit '/students/sign_in'
fill_in 'Email', with: '[email protected]'
fill_in 'Password', with: 'testing123'
click_button 'Log in'
click_link 'My profile'
expect(page).to have_content "I want to speak english at restaurants"
end
end

Expand Down

0 comments on commit 686b529

Please sign in to comment.