Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 6 files changed
  • 0 commit comments
  • 2 contributors
11 app/models/contact.rb
View
@@ -6,6 +6,17 @@ class Contact < ActiveRecord::Base
attr_accessible :data, :details, :contact_type_id, :is_primary, :is_emergency
validates_presence_of :data, :details, :contact_type_id
+
+ before_save :ensure_first_primary, :on => :create
+
+ private
+
+ def ensure_first_primary
+ if self.student_id
+ user_contacts = Contact.where(:student_id => self.student_id)
+ user_contacts.blank? && (self.is_primary == false) ? self.is_primary=true : nil
+ end
+ end
end
# == Schema Information
6 app/views/students/_student_address.html.slim
View
@@ -6,6 +6,6 @@
td= address.zipcode
td= address.state_name
td= address.country
- td= link_to t("show"), student_address_path(@student, address)
- td= link_to t("edit"), edit_student_address_path(@student, address), :remote => true
- td= link_to t("delete"), student_address_path(@student, address), :method => :delete, :confirm => 'Are you sure?', :class => 'delete_link delete_address', :remote => true
+ td= link_to t("Show"), student_address_path(@student, address)
+ td= link_to t("Edit"), edit_student_address_path(@student, address), :remote => true
+ td= link_to t("Delete"), student_address_path(@student, address), :method => :delete, :confirm => 'Are you sure?', :class => 'delete_link delete_address', :remote => true
1  config/locales/en.yml
View
@@ -4,6 +4,7 @@ en:
Show: "Show"
Edit: "Edit"
Destroy: "Destroy"
+ Delete: "Delete"
Back: "Back"
cancel: "Cancel"
required:
1  config/locales/ja.yml
View
@@ -7,6 +7,7 @@ ja:
Edit: "編集"
Update: "更新"
Destroy: "削除"
+ Delete: "Delete"
Back: "戻る"
cancel: "キャンセル"
required: "必須"
18 spec/models/contact_spec.rb
View
@@ -2,6 +2,8 @@
describe Contact do
+ let(:student) {Factory(:student)}
+
context "validations" do
it { should have_valid_factory(:contact) }
it { should belong_to(:contact_type) }
@@ -9,4 +11,20 @@
it { should belong_to(:guardian) }
end
+
+ context 'make first student contact primary on create' do
+ it "should first student address be primary" do
+ contact = FactoryGirl.build(:contact, :student_id => student.id)
+ contact.save
+ contact.should be_is_primary
+ end
+
+ it "should next student address not be primary on create" do
+ contact = Factory.create(:contact, :student_id => student.id)
+ contact2 = FactoryGirl.build(:contact, :student_id => student.id)
+ contact2.save
+ contact2.should_not be_is_primary
+ end
+ end
+
end
21 spec/requests/students_spec.rb
View
@@ -37,6 +37,27 @@
visit student_path(@student1)
page.should have_link "Enroll to course"
end
+
+ it "should exist edit link on student nested address" do
+ @student1.addresses << Factory(:address)
+ visit student_path(@student1)
+ @student1.addresses.size.should == 1
+ page.should have_selector('a', href: "/students/1/addresses/1/edit")
+ end
+
+ it "should exist edit link on student nested guardian" do
+ @student1.guardians << Factory(:guardian)
+ visit student_path(@student1)
+ @student1.guardians.size.should == 1
+ page.should have_selector('a', href: "/students/1/guardians/1/edit")
+ end
+
+ it "should exist edit link on student nested note" do
+ @student1.notes << Factory(:note)
+ visit student_path(@student1)
+ @student1.notes.size.should == 1
+ page.should have_selector('a', href: "/students/1/notes/1/edit")
+ end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.