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

Commit 94b92fb

Browse files
Merge pull request #74 from mena-devs/post-release-1.2.4
Refactor twitter method on Job class
2 parents b183a16 + ea0f4c6 commit 94b92fb

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

app/models/job.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def to_text_for_social_media
215215
return text
216216
end
217217

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

230230
unless self.twitter_handle.blank?
231-
job_twitter_account = clean_twitter_handle
231+
job_twitter_account = "&via=" + clean_twitter_handle
232232
end
233233

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

237237
private
@@ -252,10 +252,6 @@ def strip_whitespace
252252
end
253253

254254
def clean_twitter_handle
255-
if self.twitter_handle.start_with?('@')
256-
return (" " + self.twitter_handle)
257-
else
258-
return (" @" + self.twitter_handle)
259-
end
255+
self.twitter_handle.start_with?('@') ? self.twitter_handle.slice!(0) : self.twitter_handle
260256
end
261257
end

app/views/jobs/_job_info_sidebar.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<%= fa_icon("envelope 2x") %>
3939
<% end %>
4040
&nbsp;
41-
<%= link_to("https://twitter.com/intent/tweet?" + @job.to_text_for_twitter, target: "_blank") do %>
41+
<%= link_to("https://twitter.com/intent/tweet?" + @job.text_for_twitter, target: "_blank") do %>
4242
<%= fa_icon("twitter 2x") %>
4343
<% end %>
4444
<% end %>

spec/models/job_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,32 @@
154154
expect(Job.approved.count).to eq(1)
155155
end
156156
end
157+
158+
describe "#text_for_twitter" do
159+
let(:new_job) { create(:job, aasm_state: :approved, twitter_handle: 'menadevs', title: 'Engineering Manager') }
160+
let(:twitter_text) { new_job.text_for_twitter }
161+
162+
it "should include text tag" do
163+
tweet_text = "text=" + new_job.company_name.titleize
164+
165+
expect(twitter_text).to match(tweet_text)
166+
end
167+
168+
it "should include URL tag" do
169+
tweet_text = "url=" + new_job.external_link
170+
171+
expect(twitter_text).to match(/https/)
172+
expect(twitter_text).to match(new_job.title)
173+
end
174+
175+
it "should include Hashtags tag" do
176+
tweet_text = "hashtags=" + new_job.location_name
177+
178+
expect(twitter_text).to match(tweet_text)
179+
end
180+
181+
it "should include Twitter handle tag" do
182+
expect(twitter_text).to match(new_job.twitter_handle)
183+
end
184+
end
157185
end

spec/requests/jobs_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
fill_in 'Description', with: 'Lorem ipsum'
9696

9797
click_on 'Save and continue'
98+
9899
expect(page).to have_content('Please review the problems below:')
99100
expect(page).to have_content('Company name can\'t be blank')
100101
expect(page).to have_content('Employment type can\'t be blank')

0 commit comments

Comments
 (0)