-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StudentProfiles can be created by students with passing tests
- Loading branch information
1 parent
5aa384e
commit 686b529
Showing
7 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|