Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #74 from mena-devs/post-release-1.2.4
Browse files Browse the repository at this point in the history
Refactor twitter method on Job class
  • Loading branch information
constantine-nikolaou authored Dec 28, 2020
2 parents b183a16 + ea0f4c6 commit 94b92fb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
12 changes: 4 additions & 8 deletions app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def to_text_for_social_media
return text
end

def to_text_for_twitter
def text_for_twitter
job_location, job_hashtags = "", ""
job_company_name = self.company_name.titleize
job_title = self.title
Expand All @@ -228,10 +228,10 @@ def to_text_for_twitter
job_link = "&url=https://#{AppSettings.application_host}/jobs/#{self.to_param}"

unless self.twitter_handle.blank?
job_twitter_account = clean_twitter_handle
job_twitter_account = "&via=" + clean_twitter_handle
end

return "text=#{job_company_name} is looking to hire a #{job_title} #{job_location}. More information here#{job_link}#{job_twitter_account}"
return "text=#{job_company_name} is looking to hire a #{job_title} #{job_location}. More information here#{job_link}#{job_hashtags}#{job_twitter_account}"
end

private
Expand All @@ -252,10 +252,6 @@ def strip_whitespace
end

def clean_twitter_handle
if self.twitter_handle.start_with?('@')
return (" " + self.twitter_handle)
else
return (" @" + self.twitter_handle)
end
self.twitter_handle.start_with?('@') ? self.twitter_handle.slice!(0) : self.twitter_handle
end
end
2 changes: 1 addition & 1 deletion app/views/jobs/_job_info_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<%= fa_icon("envelope 2x") %>
<% end %>
&nbsp;
<%= link_to("https://twitter.com/intent/tweet?" + @job.to_text_for_twitter, target: "_blank") do %>
<%= link_to("https://twitter.com/intent/tweet?" + @job.text_for_twitter, target: "_blank") do %>
<%= fa_icon("twitter 2x") %>
<% end %>
<% end %>
Expand Down
28 changes: 28 additions & 0 deletions spec/models/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,32 @@
expect(Job.approved.count).to eq(1)
end
end

describe "#text_for_twitter" do
let(:new_job) { create(:job, aasm_state: :approved, twitter_handle: 'menadevs', title: 'Engineering Manager') }
let(:twitter_text) { new_job.text_for_twitter }

it "should include text tag" do
tweet_text = "text=" + new_job.company_name.titleize

expect(twitter_text).to match(tweet_text)
end

it "should include URL tag" do
tweet_text = "url=" + new_job.external_link

expect(twitter_text).to match(/https/)
expect(twitter_text).to match(new_job.title)
end

it "should include Hashtags tag" do
tweet_text = "hashtags=" + new_job.location_name

expect(twitter_text).to match(tweet_text)
end

it "should include Twitter handle tag" do
expect(twitter_text).to match(new_job.twitter_handle)
end
end
end
1 change: 1 addition & 0 deletions spec/requests/jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
fill_in 'Description', with: 'Lorem ipsum'

click_on 'Save and continue'

expect(page).to have_content('Please review the problems below:')
expect(page).to have_content('Company name can\'t be blank')
expect(page).to have_content('Employment type can\'t be blank')
Expand Down

0 comments on commit 94b92fb

Please sign in to comment.