From c6dc03051a3dfdc48293d3af25bd95ca872608d6 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Fri, 26 Feb 2016 21:20:40 -0500 Subject: [PATCH] CSS for courses new and edit page, user model testcases --- app/controllers/courses_controller.rb | 2 +- app/views/courses/_form.html.erb | 53 ---------- app/views/courses/edit.html.erb | 62 ++++++++++- app/views/courses/new.html.erb | 96 +++++++++--------- app/views/courses/show.html.erb | 8 +- app/views/messages/index.html.erb | 4 +- test/models/user_test.rb | 141 +++++++++++++++++++++++++- 7 files changed, 252 insertions(+), 114 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 18d8275..b18edd4 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -62,7 +62,7 @@ def create end end else - edirect_to unauthorized_url + redirect_to unauthorized_url end end diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index e233d25..e69de29 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -1,53 +0,0 @@ -<%= form_for(@course) do |f| %> - <% if @course.errors.any? %> -
-

<%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved:

- - -
- <% end %> - -
- <%= f.label :title %>
- <%= f.text_area :title %> -
-
- <%= f.label :description %>
- <%= f.text_area :description %> -
-
- <%= f.label :start_date %>
- <%= f.date_select :start_date %> -
-
- <%= f.label :end_date %>
- <%= f.date_select :end_date %> -
-
- - <%= f.label :user_id %>
- <% users_array = User.all.map{|user| [user.name,user.id] if user.utype =="instructor"} %> - <%= f.select(:user_id) do %> - <% users_array.each do |u| -%> - <% if u!=nil %> - <%=content_tag(:option, u.first, value: u.last) %> - <% end %> - <% end %> - <% end %> - - - -
-
- <%= f.label :status %>
- <%= f.text_field :status %> -
-
- <%= f.submit %> -
-<% end %> diff --git a/app/views/courses/edit.html.erb b/app/views/courses/edit.html.erb index 4e3e3a1..9a21bf4 100644 --- a/app/views/courses/edit.html.erb +++ b/app/views/courses/edit.html.erb @@ -1,6 +1,60 @@ -

Editing Course

+<% provide(:title, 'Edit ' + @course.title + ' details') %> -<%= render 'form' %> +
+
+

Edit course

+
-<%= link_to 'Show', @course %> | -<%= link_to 'Back', courses_path %> + +
+
+ <% if @course.errors.any? %> +
+
+ The form contains <%= pluralize(@course.errors.count, "error") %>. +
    + <% @course.errors.full_messages.each do |error_msg| %> +
  • <%= error_msg %>
  • + <% end %> +
+
+
+ <% end %> + + <%= form_for(@course) do |f| %> + + <%= f.label :title, "Title" %> + <%= f.text_field :title, class:'form-control' %> + + <%= f.label :description, "Description" %> + <%= f.text_area :description, class:'form-control' %> + + <%= f.label :start_date, "Start date" %> + <%= f.date_select :start_date, { :order => [:year, :month, :day], :prompt => { year: 'Select year', day:'Select day', month:'Select month' }}, {class: "form-control"} %> + + <%= f.label :end_date, "End date" %> + <%= f.date_select :end_date, { :order => [:year, :month, :day], :prompt => { year: 'Select year', day:'Select day', month:'Select month' }}, {class: "form-control"} %> + + <%= f.label :user_id, "Instructor" %>
+ <% users_array = User.all.map{|user| [user.name, user.id] if user.utype =="instructor"} %> + + <%= f.select(:user_id, {}, {}, {class:'form-control'}) do %> + <% users_array.each do |user| %> + <% if user != nil %> + <%= content_tag(:option, user.first, value: user.last) %> + <% end %> + <% end %> + <% end %> + + <%= f.select(:status, {}, {}, {class:'form-control'}) do %> + <%=content_tag(:option, "Inactive", value: "Inactive") %> + <%=content_tag(:option, "Active", value: "Active") %> + <% end %> + + <%= f.submit "Edit course", class: "btn btn-primary" %> + + <% end %> +
+
+ +
\ No newline at end of file diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index e0a1bab..9e89de0 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -1,58 +1,60 @@ <% provide(:title, 'Add a course') %> -
-

Add a course

-
- - -
-
- <% if @course.errors.any? %> -
-
- The form contains <%= pluralize(@course.errors.count, "error") %>. -
    - <% @course.errors.full_messages.each do |error_msg| %> -
  • <%= error_msg %>
  • - <% end %> -
+
+
+

Add a course

+
+ + +
+
+ <% if @course.errors.any? %> +
+
+ The form contains <%= pluralize(@course.errors.count, "error") %>. +
    + <% @course.errors.full_messages.each do |error_msg| %> +
  • <%= error_msg %>
  • + <% end %> +
+
-
- <% end %> + <% end %> - <%= form_for(@course) do |f| %> + <%= form_for(@course) do |f| %> - <%= f.label :title, "Title" %> - <%= f.text_field :title, class:'form-control' %> + <%= f.label :title, "Title" %> + <%= f.text_field :title, class:'form-control' %> - <%= f.label :description, "Description" %> - <%= f.text_area :description, class:'form-control' %> + <%= f.label :description, "Description" %> + <%= f.text_area :description, class:'form-control' %> - <%= f.label :start_date, "Start date" %> - <%= f.date_select :start_date, { :order => [:year, :month, :day], :prompt => { year: 'Select year', day:'Select day', month:'Select month' }}, {class: "form-control"} %> + <%= f.label :start_date, "Start date" %> + <%= f.date_select :start_date, { :order => [:year, :month, :day], :prompt => { year: 'Select year', day:'Select day', month:'Select month' }}, {class: "form-control"} %> - <%= f.label :end_date, "End date" %> - <%= f.date_select :end_date, { :order => [:year, :month, :day], :prompt => { year: 'Select year', day:'Select day', month:'Select month' }}, {class: "form-control"} %> + <%= f.label :end_date, "End date" %> + <%= f.date_select :end_date, { :order => [:year, :month, :day], :prompt => { year: 'Select year', day:'Select day', month:'Select month' }}, {class: "form-control"} %> - <%= f.label :user_id, "Instructor" %>
- <% users_array = User.all.map{|user| [user.name, user.id] if user.utype =="instructor"} %> - - <%= f.select(:user_id, {}, {}, {class:'form-control'}) do %> - <% users_array.each do |user| %> - <% if user != nil %> - <%= content_tag(:option, user.first, value: user.last) %> + <%= f.label :user_id, "Instructor" %>
+ <% users_array = User.all.map{|user| [user.name, user.id] if user.utype =="instructor"} %> + + <%= f.select(:user_id, {}, {}, {class:'form-control'}) do %> + <% users_array.each do |user| %> + <% if user != nil %> + <%= content_tag(:option, user.first, value: user.last) %> + <% end %> <% end %> <% end %> - <% end %> - <%= f.label :status, "Status" %>
- - <%= f.select(:status, {}, {}, {class:'form-control'}) do %> - <%=content_tag(:option, "Inactive", value: "Inactive") %> - <%=content_tag(:option, "Active", value: "Active") %> - <% end %> - - <%= f.submit "Create course", class: "btn btn-primary" %> - <% end %> - -
-
+ <%= f.label :status, "Status" %>
+ + <%= f.select(:status, {}, {}, {class:'form-control'}) do %> + <%=content_tag(:option, "Inactive", value: "Inactive") %> + <%=content_tag(:option, "Active", value: "Active") %> + <% end %> + + <%= f.submit "Create course", class: "btn btn-primary" %> + <% end %> + +
+
+
\ No newline at end of file diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 42fafe1..adf2dfb 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,8 +1,8 @@ <% provide(:title, @course.title + ' details') %> -
-
-
+
+
+

<%= @course.title %>

@@ -75,8 +75,8 @@

<% end %> -
+
diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb index 6412098..1856ed2 100644 --- a/app/views/messages/index.html.erb +++ b/app/views/messages/index.html.erb @@ -49,8 +49,8 @@ <% end %>
diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 82f61e0..31a5474 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,7 +1,142 @@ require 'test_helper' class UserTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + + test "simple admin save" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert user.save + end + + test "simple instructor save" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert user.save + end + + test "simple student save" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert user.save + end + + test "do not save without name" do + user = User.new + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert_not user.save + end + + test "do not save without email" do + user = User.new + user.name = "User1" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert_not user.save + end + + test "do not save without password" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "" + user.password_confirmation = "" + user.utype = "admin" + assert_not user.save + end + + test "do not save with different password and password_confirmation" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password1234" + user.utype = "admin" + assert_not user.save + end + + test "do not save with too long name" do + user = User.new + user.name = "User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert_not user.save + end + + test "do not save with short password" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "pass" + user.password_confirmation = "pass" + user.utype = "admin" + assert_not user.save + end + + test "do not save with invalid utype" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password1234" + user.utype = "admin123" + assert_not user.save + end + + test "do not save with long email" do + user = User.new + user.name = "User1" + user.email = "User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1User1@sp.com" + user.password = "password" + user.password_confirmation = "password1234" + user.utype = "admin" + assert_not user.save + end + + test "do not save with invalid email" do + user = User.new + user.name = "User1" + user.email = "user1@spcom" + user.password = "password" + user.password_confirmation = "password1234" + user.utype = "admin" + assert_not user.save + end + + test "do not save duplicate email accounts" do + user = User.new + user.name = "User1" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert user.save + + user = User.new + user.name = "User2" + user.email = "user1@sp.com" + user.password = "password" + user.password_confirmation = "password" + user.utype = "admin" + assert_not user.save + end + end +