diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
deleted file mode 100644
index cc9d429..0000000
--- a/app/controllers/profiles_controller.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class ProfilesController < ApplicationController
- def show
- end
-end
diff --git a/app/controllers/student_profiles_controller.rb b/app/controllers/student_profiles_controller.rb
index 0739965..a0afccb 100644
--- a/app/controllers/student_profiles_controller.rb
+++ b/app/controllers/student_profiles_controller.rb
@@ -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
diff --git a/app/views/student_profiles/_form.html.erb b/app/views/student_profiles/_form.html.erb
new file mode 100644
index 0000000..3736a04
--- /dev/null
+++ b/app/views/student_profiles/_form.html.erb
@@ -0,0 +1,25 @@
+<%= form_for(@student_profile) do |f| %>
+ <% if @student_profile.errors.any? %>
+
+
<%= pluralize(@student_profile.errors.count, "error") %> prohibited this pin from being saved:
+
+
+ <% @student_profile.errors.full_messages.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= 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" %>
+
+
+ <%= f.submit class: "btn btn-primary" %>
+
+<% end %>
diff --git a/app/views/student_profiles/new.html.erb b/app/views/student_profiles/new.html.erb
new file mode 100644
index 0000000..cc62bbf
--- /dev/null
+++ b/app/views/student_profiles/new.html.erb
@@ -0,0 +1,5 @@
+My Profile
+<% if student_signed_in? %>
+ <%= link_to 'Back', student_profile_path(:id => current_student.id) %>
+ <%= render 'form' %>
+<% end %>
diff --git a/app/views/profiles/show.html.erb b/app/views/student_profiles/show.html.erb
similarity index 60%
rename from app/views/profiles/show.html.erb
rename to app/views/student_profiles/show.html.erb
index 9d1ee4b..35db47d 100644
--- a/app/views/profiles/show.html.erb
+++ b/app/views/student_profiles/show.html.erb
@@ -3,5 +3,8 @@
You do not have a profile yet
<%= 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 %>
Edit profile
<% end %>
diff --git a/spec/factories/student_profile.rb b/spec/factories/student_profile.rb
new file mode 100644
index 0000000..180fc58
--- /dev/null
+++ b/spec/factories/student_profile.rb
@@ -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
diff --git a/spec/features/student_profile_spec.rb b/spec/features/student_profile_spec.rb
index 8264b94..06a94e9 100644
--- a/spec/features/student_profile_spec.rb
+++ b/spec/features/student_profile_spec.rb
@@ -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: 'student@factory.com'
+ 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