Skip to content

Commit a4fef0c

Browse files
committed
added tests for provided searches
1 parent 2d334b6 commit a4fef0c

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

lib/spark_api/models/saved_search.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def self.provided()
2222
def is_provided_search?
2323
true
2424
end
25+
def newsfeeds
26+
[]
27+
end
2528
SparkApi.logger.info("#{self.name}.path: #{provided.path}")
2629
end
2730
end
@@ -80,6 +83,7 @@ def is_provided_search?
8083
def can_have_newsfeed?
8184

8285
return false if is_provided_search?
86+
return true if has_active_newsfeed? || has_inactive_newsfeed?
8387

8488
# Newsfeed restriction criteria for saved searches:
8589
# http://alpha.sparkplatform.com/docs/api_services/newsfeed/restrictions#criteria
@@ -96,6 +100,8 @@ def can_have_newsfeed?
96100
end
97101

98102
def has_active_newsfeed?
103+
return false if is_provided_search?
104+
99105
if self.respond_to? "NewsFeedSubscriptionSummary"
100106
self.NewsFeedSubscriptionSummary['ActiveSubscription']
101107
else
@@ -105,6 +111,8 @@ def has_active_newsfeed?
105111
end
106112

107113
def has_inactive_newsfeed?
114+
return false if is_provided_search?
115+
108116
if self.respond_to? "NewsFeedSubscriptionSummary"
109117
!self.NewsFeedSubscriptionSummary['ActiveSubscription']
110118
else

spec/unit/spark_api/models/saved_search_spec.rb

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148
it "should return false without at least three filter parameters" do
149149
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
150150
resource = subject.class.find(id)
151+
resource.stub(:is_provided_search?) { false }
152+
resource.stub(:has_active_newsfeed?) { false }
153+
resource.stub(:has_inactive_newsfeed?) { false }
151154
resource.Filter = "City Eq 'Moorhead' And MlsStatus Eq 'Active'"
152155
resource.can_have_newsfeed?.should == false
153156
end
@@ -156,6 +159,8 @@
156159
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
157160
resource = subject.class.find(id)
158161
resource.stub(:is_provided_search?) { false }
162+
resource.stub(:has_active_newsfeed?) { false }
163+
resource.stub(:has_inactive_newsfeed?) { false }
159164
resource.can_have_newsfeed?.should == true
160165
end
161166

@@ -166,7 +171,16 @@
166171
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
167172
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_newsfeed.json',
168173
{ "_expand" => "NewsFeedSubscriptionSummary" } )
169-
subject.class.find(id).has_active_newsfeed?.should == true
174+
resource = subject.class.find(id)
175+
resource.stub(:is_provided_search?) { false }
176+
resource.has_active_newsfeed?.should == true
177+
end
178+
179+
it "should return false for a provided search" do
180+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
181+
resource = subject.class.find(id)
182+
resource.stub(:is_provided_search?) { true }
183+
resource.has_active_newsfeed?.should == false
170184
end
171185
end
172186

@@ -175,18 +189,24 @@
175189
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json')
176190
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json',
177191
{ "_expand" => "NewsFeedSubscriptionSummary" } )
178-
subject.class.find(id).has_inactive_newsfeed?.should == true
192+
resource = subject.class.find(id)
193+
resource.stub(:is_provided_search?) { false }
194+
resource.has_inactive_newsfeed?.should == true
195+
end
196+
197+
it "should return false for a provided search" do
198+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json')
199+
resource = subject.class.find(id)
200+
resource.stub(:is_provided_search?) { true }
201+
resource.has_inactive_newsfeed?.should == false
179202
end
180203
end
181204

182205
describe "newsfeed" do
183-
184206
it "should return the newsfeed for the saved search" do
185207
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
186-
187208
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_newsfeed.json',
188209
{ "_expand" => "NewsFeeds" } )
189-
190210
resource = subject.class.find(id)
191211
resource.newsfeeds.should be_an(Array)
192212
end

0 commit comments

Comments
 (0)