Skip to content

Commit

Permalink
RSpec for Supervisor Course View for edit course feature 49733
Browse files Browse the repository at this point in the history
  • Loading branch information
aamehedi committed Dec 28, 2015
1 parent 8683f18 commit 68af5a3
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 19 deletions.
6 changes: 6 additions & 0 deletions app/controllers/supervisor/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ def edit
def update
if course_params.has_key? :update_status
@course.update_status!
if @course.created?
flash[:success] = t ".success", action: "Started"
else
flash[:success] = t ".success", action: "Finished"
end
redirect_to supervisor_course_path @course
elsif @course.update_attributes course_params
flash[:success] = t ".success", action: "Updated"
redirect_to supervisor_course_path @course
else
render :edit
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/_supervisor.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<li><%= link_to t('view_all_trainee'), supervisor_users_path(supervisor: User::TYPES[:trainee]) %></li>
<li><%= link_to t('view_all_supervisors'), supervisor_users_path(supervisor: User::TYPES[:supervisor]) %></li>
<li><%= link_to t("view_all_trainee"), supervisor_users_path(
supervisor: User.roles[:trainee]) %></li>
<li><%= link_to t("view_all_supervisors"), supervisor_users_path(supervisor:
User.roles[:supervisor]) %></li>
<li><%= link_to t(:log_out), :destroy_user_session, method: :delete %></li>
6 changes: 4 additions & 2 deletions app/views/supervisor/courses/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
</div>
<div class="form-group">
<%= f.label :start_date %>
<%= f.date_field :start_date, class: "datepicker", id: "sd", readonly: true %>
<%= f.date_field :start_date, id: "sd", readonly: true, value:
@course.start_date.strftime("%d/%m/%Y") %>
</div>
<div class="form-group">
<%= f.label :end_date %>
<%= f.date_field :end_date, class: "datepicker", id: "ed", readonly: true %>
<%= f.date_field :end_date, id: "ed", readonly: true, value:
@course.end_date.strftime("%d/%m/%Y") %>
</div>
<div class="form-group">
<%= collection_check_boxes :course, :subject_ids,Subject.all, :id, :name do |b| %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ en:
start: Start Course
update:
danger: Cannot edit course now.
success: Course Successfully %{action}
courses_subjects:
edit:
danger: Cannot edit subjcet now.
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20151201040850_add_supervisor_to_users.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AddSupervisorToUsers < ActiveRecord::Migration
def change
add_column :users, :role, :boolean, default: false
add_column :users, :role, :integer, limit: 1, default: 0
end
end
12 changes: 6 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@
create_table "users", force: :cascade do |t|
t.string "first_name", limit: 255
t.string "last_name", limit: 255
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", limit: 4, default: 0, null: false
t.integer "sign_in_count", limit: 4, default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "role", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "role", limit: 1, default: 0
t.datetime "deleted_at"
end

Expand Down
24 changes: 20 additions & 4 deletions spec/controllers/supervisor/courses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,28 @@

context "when request is to start or finish the course" do
before do
allow(course).to receive(:update_status!)
put :update, {id: english, course: {name: "bengali", update_status:
""}}
allow(course).to receive :update_status!
allow(course).to receive(:created?).and_return true
end
context "when course start" do
before {put :update, {id: english, course: {name: "bengali",
update_status: ""}}}
it {expect(flash[:success]).to eq I18n.t(
"supervisor.courses.update.success", action: "Started")}
it {expect(response).to redirect_to supervisor_course_path course}
end
context "when course finish" do
before do
allow(course).to receive(:created?).and_return false
put :update, {id: english, course: {name: "bengali", update_status:
""}}
end
it {expect(flash[:success]).to eq I18n.t(
"supervisor.courses.update.success", action: "Finished")}
it {expect(response).to redirect_to supervisor_course_path course}
end

it {expect(response).to redirect_to supervisor_course_path course}

end
end
context "while course failed .check_course" do
Expand Down
7 changes: 4 additions & 3 deletions spec/features/add_course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
subject {page}
let(:supervisor) {FactoryGirl.create :supervisor}
let!(:demo_subject){FactoryGirl.create :subject}
before :each do
before :each do
login_as supervisor, scope: :user
visit new_supervisor_course_path
end
Expand All @@ -25,8 +25,9 @@
is_expected.to have_field "course[end_date]", type: "date"
end
scenario "has subject field" do
is_expected.to have_field "course_subject_ids_#{demo_subject.id}", type: "checkbox"
is_expected.to have_field "course[subject_ids][]", type: "checkbox"
Subject.ids.each do |id|
is_expected.to have_unchecked_field "course_subject_ids_#{id}"
end
end
scenario "has submit button" do
is_expected.to have_button I18n.t "supervisor.courses.new.bt_new_course"
Expand Down
53 changes: 53 additions & 0 deletions spec/features/edit_course_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require "rails_helper"

feature "Edit course" do
subject {page}
let(:supervisor) {FactoryGirl.create :supervisor}
let!(:demo_subject){FactoryGirl.create :subject}
let!(:course){FactoryGirl.create :course, subject_ids: [demo_subject.id],
user_ids: [supervisor.id]}
before :each do
login_as supervisor, scope: :user
visit edit_supervisor_course_path course
end

scenario "has title" do
is_expected.to have_css "h1", text: I18n.t("supervisor.courses.edit.title")
end
scenario "has name field" do
is_expected.to have_field "course[name]", type: "text", with: course.name
end
scenario "has description field" do
is_expected.to have_field "course[description]", text: course.description
end
scenario "has start date field" do
is_expected.to have_field "course[start_date]", type: "date", with:
course.start_date.strftime("%d/%m/%Y")
end
scenario "has end date field" do
is_expected.to have_field "course[end_date]", type: "date", with:
course.end_date.strftime("%d/%m/%Y")
end
scenario "has subject field" do
subject_ids = course.subject_ids
Subject.ids.each do |id|
if subject_ids.include? id
is_expected.to have_checked_field "course_subject_ids_#{id}"
else
is_expected.to have_unchecked_field "course_subject_ids_#{id}"
end
end
end
scenario "has submit button" do
is_expected.to have_button I18n.t "supervisor.courses.edit.submit"
end
scenario "edit course feature", js: true do
fill_in "course[name]", with: Faker::Lorem.word
fill_in "course[description]", with: Faker::Lorem.paragraph
select_date Date.tomorrow, from: "sd", datepicker: :bootstrap
uncheck demo_subject.name
click_button I18n.t "supervisor.courses.edit.submit"
is_expected.to have_text I18n.t("supervisor.courses.update.success", action:
"Updated")
end
end
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@
config.before :suite do
Warden.test_mode!
end
end
end

0 comments on commit 68af5a3

Please sign in to comment.