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

Commit 774527c

Browse files
Add specs to test concerns
1 parent ffbfff9 commit 774527c

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

app/models/concerns/text_helpers.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ module TextHelpers
22
include ActiveSupport::Concern
33

44
def boolean_to_string(value)
5-
return "No" if value.nil?
5+
yes_values = [true, 1, "1"]
6+
no_values = [nil, false, 0, "0"]
67

7-
if (value == true || value == 1 || value == "1")
8-
"Yes"
9-
elsif (value == false || value == 0 || value == "0")
10-
"No"
8+
if yes_values.include?(value)
9+
return "Yes"
10+
elsif no_values.include?(value)
11+
return "No"
1112
end
1213
end
1314
end

spec/concerns/country_name_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe CountryName do
4+
let(:job) { create(:job, remote: nil) }
5+
6+
describe "#country_name" do
7+
it "returns the full country name when abbreviation is passed" do
8+
expect(job.country_name("NL")).to eq "Netherlands"
9+
end
10+
11+
it "returns `Not set` if the country abbreviation does not match" do
12+
expect(job.country_name("")).to eq "Not set"
13+
end
14+
end
15+
end

spec/concerns/text_helpers_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe TextHelpers do
4+
let(:job) { create(:job, remote: nil) }
5+
6+
describe "#boolean_to_string" do
7+
describe "returning No" do
8+
it "returns No if value is not set" do
9+
expect(job.boolean_to_string(nil)).to eq "No"
10+
end
11+
12+
it "returns No if value is false" do
13+
expect(job.boolean_to_string(false)).to eq "No"
14+
end
15+
16+
it "returns No if value is 0" do
17+
expect(job.boolean_to_string(0)).to eq "No"
18+
end
19+
20+
it "returns No if value is a text of value 0" do
21+
expect(job.boolean_to_string("0")).to eq "No"
22+
end
23+
end
24+
25+
describe "returning Yes" do
26+
it "returns Yes if value is set to true" do
27+
expect(job.boolean_to_string(true)).to eq "Yes"
28+
end
29+
30+
it "returns Yes if value is 1" do
31+
expect(job.boolean_to_string(1)).to eq "Yes"
32+
end
33+
34+
it "returns Yes if value is a text of value 1" do
35+
expect(job.boolean_to_string("1")).to eq "Yes"
36+
end
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)