Skip to content

Commit 0b85da9

Browse files
committed
Merge pull request #18 from twingly/fix/17
Do not allow empty search pattern
2 parents 15715e4 + 1e49975 commit 0b85da9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/twingly-analytics/query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def url_parameters
2525
end
2626

2727
def request_parameters
28-
fail("Missing pattern") unless pattern
28+
fail("Missing pattern") if pattern.to_s.empty?
2929

3030
{
3131
:key => client.api_key,

spec/query_spec.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
context "without client" do
1313
subject { Query.new }
14+
1415
it "should not work" do
1516
expect { subject }.to raise_error(ArgumentError)
1617
end
@@ -34,8 +35,9 @@
3435
let(:query) { Query.new(@client) }
3536

3637
context "with valid pattern" do
37-
before { allow_any_instance_of(Query).to receive(:pattern).and_return('') }
38+
before { query.pattern = "christmas" }
3839
subject { query.url }
40+
3941
it { should include("xmloutputversion=2") }
4042
end
4143

@@ -44,10 +46,19 @@
4446
expect { query.url }.to raise_error(RuntimeError, "Missing pattern")
4547
end
4648
end
49+
50+
context "with empty pattern" do
51+
before { query.pattern = "" }
52+
53+
it "raises an error" do
54+
expect { query.url }.to raise_error(RuntimeError, "Missing pattern")
55+
end
56+
end
4757
end
4858

4959
context "with valid pattern" do
50-
before { allow_any_instance_of(Query).to receive(:pattern).and_return('') }
60+
before { subject.pattern = "christmas" }
61+
5162
it "should add language" do
5263
subject.language = "en"
5364
expect(subject.request_parameters).to include(documentlang: 'en')
@@ -70,8 +81,9 @@
7081
end
7182

7283
describe "#pattern" do
84+
before { subject.pattern = "spotify" }
85+
7386
it "should add searchpattern" do
74-
subject.pattern = 'spotify'
7587
expect(subject.url_parameters).to include("searchpattern=spotify")
7688
end
7789
end

0 commit comments

Comments
 (0)