Permalink
Browse files

added experiences

  • Loading branch information...
1 parent ec4c8f9 commit 46a48d52ea2fb465f16a8d31ed4aa2a53f81adf2 @Systho committed Sep 7, 2012
@@ -5,4 +5,16 @@ h1{
h2 {
font-weight: 100;
font-size: xx-large;
+}
+
+.experience .title {
+ font-weight: 100;
+}
+
+.experience .location {
+ font-weight: bolder;
+}
+
+.experience .timespan {
+ font-weight: 100;
}
@@ -48,6 +48,6 @@ def destroy
protected
def resume_params
- params.require(:resume).permit(:first_name, :last_name, :intro, :projects_attributes)
+ params.require(:resume).permit(:first_name, :last_name, :intro, :projects_attributes, :experiences_attributes)
end
end
@@ -0,0 +1,13 @@
+class ExperienceDecorator < SimpleDelegator
+
+ def location
+ "#{company} - #{place}"
+ end
+
+ def timespan
+ formatted_from_date = I18n.localize(from_date, :format => "%B %Y" )
+ return formatted_from_date if from_date == until_date
+ formatted_until_date = until_date.nil? ? I18n.t('today') : I18n.localize(until_date, :format => "%B %Y" )
+ "#{formatted_from_date} - #{formatted_until_date}"
+ end
+end
@@ -0,0 +1,26 @@
+class Experience < ActiveRecord::Base
+ belongs_to :resume
+
+ validates :title, :presence => true
+ validates :company, :presence => true
+ validates :place, :presence => true
+ validates :from_date, :presence => true
+
+ validate :from_date_must_be_past
+ validate :from_date_must_be_before_until_date
+
+
+ acts_as_taggable_on :technologies
+
+
+ def from_date_must_be_past
+ errors.add(:from_date, "must be a past date") if self.from_date.present? && self.from_date > Date.today
+ end
+
+ def from_date_must_be_before_until_date
+ return unless self.from_date.present? && self.until_date.present? && self.until_date < self.from_date
+ errors.add(:from_date, "must be before until_date")
+ errors.add(:until_date, "must be after from date")
+ end
+
+end
@@ -1,4 +1,6 @@
class Project < ActiveRecord::Base
+ belongs_to :resume
+
acts_as_taggable_on :technologies
end
@@ -2,6 +2,9 @@ class Resume < ActiveRecord::Base
has_many :projects, :dependent => :destroy
accepts_nested_attributes_for :projects, :allow_destroy => true
+ has_many :experiences, :dependent => :destroy
+ accepts_nested_attributes_for :experiences, :allow_destroy => true
+
validates :first_name, :presence => true
validates :last_name, :presence => true
end
@@ -0,0 +1,9 @@
+= field_set_tag "Experience Details" do
+ = f.input :title
+ = f.input :company
+ = f.input :place
+ = f.input :from_date, :start_year => Date.today.year - 50, :end_year => Date.today.year , :discard_day => true, :order => [:month, :year]
+ = f.input :until_date, :start_year => Date.today.year - 50, :end_year => Date.today.year , :discard_day => true, :order => [:month, :year], :include_blank => true
+ = f.input :description
+ = f.input :technology_list, :url => autocomplete_technology_name_projects_path, :as => :autocomplete, :input_html => {:"data-delimiter" => ', '}
+ = f.link_to_remove "Remove this experience"
@@ -3,7 +3,12 @@
= f.input :last_name
= f.input :intro
- = f.fields_for :projects, :class => "project_fields"
+ = f.fields_for :projects
p
= f.link_to_add "Add Project", :projects
+
+ = f.fields_for :experiences
+ p
+ = f.link_to_add "Add Experience", :experiences
+
= f.button :submit
@@ -1,4 +1,4 @@
-= field_set_tag "Project Details", :class => "project_fields" do
+= field_set_tag "Project Details" do
= f.input :title
= f.input :description
= f.input :duration
@@ -27,4 +27,20 @@ html
span Technologies :&nbsp;
= project.technology_list
+ section.experiences
+ h2 Expérience professionnelle
+
+ - @resume.experiences.map{|e|ExperienceDecorator.new(e)}.each do |experience|
+ section.experience
+ h3.title = experience.title
+ h3.location = experience.location
+ h3.timespan = experience.timespan
+ - if experience.description.present?
+ p
+ = simple_format experience.description
+ - if experience.technologies.any?
+ p
+ span Technologies :&nbsp;
+ = experience.technology_list
+
@@ -2,4 +2,4 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
- hello: "Hello world"
+ today: "Today"
@@ -0,0 +1,16 @@
+class CreateExperiences < ActiveRecord::Migration
+ def change
+ create_table :experiences do |t|
+ t.references :resume
+ t.string :title
+ t.string :company
+ t.string :place
+ t.date :from_date
+ t.date :until_date
+ t.text :description
+
+ t.timestamps
+ end
+ add_index :experiences, :resume_id
+ end
+end
@@ -0,0 +1,13 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :experience do
+ resume nil
+ title { Faker::Lorem.words(3)}
+ company{ Faker::Company.name}
+ place{ Faker::Address.city}
+ from_date "2012-01-01"
+ until_date "2012-02-01"
+ description { Faker::Lorem.paragraph(1)}
+ end
+end
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe Experience do
+ subject {FactoryGirl.build(:experience)}
+
+ describe "validity" do
+
+ it "should not be valid without a title" do
+ subject.title = nil
+ subject.should_not be_valid
+ end
+
+ it "should not be valid without a company" do
+ subject.company = nil
+ subject.should_not be_valid
+ end
+
+ it "should not be valid without a place" do
+ subject.place = nil
+ subject.should_not be_valid
+ end
+
+ it "should not be valid without a starting date" do
+ subject.from_date = nil
+ subject.should_not be_valid
+ end
+
+ it "should not be valid with a starting date in the future" do
+ subject.from_date = Date.today + 1.day
+ subject.should_not be_valid
+ end
+
+ it "should not be valid with a starting date after the ending date" do
+ subject.from_date = Date.today
+ subject.until_date = 1.day.ago
+ subject.should_not be_valid
+ end
+
+ it "should be valid without an ending date" do
+ subject.until_date = nil
+ subject.should be_valid
+ end
+
+ it "should be valid without a description" do
+ subject.description = nil
+ subject.should be_valid
+ end
+
+ end
+end
View
@@ -12,6 +12,7 @@
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
+ config.include SelectDate
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
@@ -0,0 +1,24 @@
+module SelectDate
+ def get_base_dom_id_from_label_tag(field)
+ find(:xpath, ".//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
+ end
+
+ def select_month(date, options)
+ date = Date.parse(date)
+ base_dom_id = get_base_dom_id_from_label_tag(options[:from])
+
+ find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
+ find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l date, :format => '%B')
+
+ end
+
+ def select_date(date, options)
+ date = Date.parse(date)
+ base_dom_id = get_base_dom_id_from_label_tag(options[:from])
+
+ find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
+ find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l date, :format => '%B')
+ find(:xpath, ".//select[@id='#{base_dom_id}_3i']").select(date.day.to_s)
+ end
+end
+

0 comments on commit 46a48d5

Please sign in to comment.