Skip to content

Commit 2d334b6

Browse files
committed
added newsfeed update method and tests
1 parent 4ad9bd0 commit 2d334b6

File tree

8 files changed

+137
-32
lines changed

8 files changed

+137
-32
lines changed

lib/spark_api/models/newsfeed.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ module Models
33
class Newsfeed < Base
44

55
extend Finders
6-
include Concerns::Savable
76

87
self.element_name = 'newsfeeds'
98

9+
def update!(arguments={})
10+
connection.put( "/newsfeeds/#{self.Id}", arguments ).first
11+
end
12+
1013
end
1114
end
1215
end

spec/fixtures/newsfeeds/get.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"D": {
3+
"Success": true,
4+
"Results": [
5+
{
6+
"Id": "20130625195235039712000000",
7+
"ResourceUri": "/vX/newsfeeds/20130625195235039712000000",
8+
"Active": true,
9+
"NotificationsActive": true,
10+
"Curated": false,
11+
"Name": "My Newsfeed Subscription",
12+
"Type": "SavedSearch",
13+
"NotificationMethods": ["Email"],
14+
"CreatedTimestamp": "2013-06-27T10:01:06-05:00",
15+
"ModificationTimestamp": "2013-06-27T10:01:06-05:00",
16+
"LastEventTimestamp": "2013-07-07T12:12:06-05:00",
17+
"ExpirationDate": "2014-10-10",
18+
"Subscription": {
19+
"ResourceUri": "/vX/savedsearches/20100815220615294367000000",
20+
"Id": "20100815220615294367000000",
21+
"OwnerId": "20090815223215294334000000",
22+
"Name": "Search name here",
23+
"Description": "A longer description of the search",
24+
"Filter": null,
25+
"ModificationTimestamp": "2011-03-14T08:39:38-05:00"
26+
}
27+
}
28+
]
29+
}
30+
}

spec/fixtures/newsfeeds/inactive.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"D": {
3+
"Success": true,
4+
"Results": [
5+
{
6+
"Id": "20130625195235039712000000",
7+
"ResourceUri": "/vX/newsfeeds/20130625195235039712000000",
8+
"Active": false,
9+
"NotificationsActive": true,
10+
"Curated": false,
11+
"Name": "My Newsfeed Subscription",
12+
"Type": "SavedSearch",
13+
"NotificationMethods": ["Email"],
14+
"CreatedTimestamp": "2013-06-27T10:01:06-05:00",
15+
"ModificationTimestamp": "2013-06-27T10:01:06-05:00",
16+
"LastEventTimestamp": "2013-07-07T12:12:06-05:00",
17+
"ExpirationDate": "2014-10-10",
18+
"Subscription": {
19+
"ResourceUri": "/vX/savedsearches/20100815220615294367000000",
20+
"Id": "20100815220615294367000000",
21+
"OwnerId": "20090815223215294334000000",
22+
"Name": "Search name here",
23+
"Description": "A longer description of the search",
24+
"Filter": null,
25+
"ModificationTimestamp": "2011-03-14T08:39:38-05:00"
26+
}
27+
}
28+
]
29+
}
30+
}

spec/fixtures/saved_searches/get.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"ResourceUri": "/v1/savedsearches/20100815220615294367000000",
77
"Id": "20100815220615294367000000",
88
"Name": "Search name here",
9+
"Filter": "City Eq 'Moorhead' And MlsStatus Eq 'Active' And PropertyType Eq 'A'",
910
"ContactIds": [
1011
"20100815220615294367000000"
1112
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"D": {
3+
"Success": true,
4+
"Results": [
5+
{
6+
"ResourceUri": "/v1/savedsearches/20100815220615294367000000",
7+
"Id": "20100815220615294367000000",
8+
"Name": "Search name here",
9+
"ContactIds": [
10+
"20100815220615294367000000"
11+
],
12+
"NewsFeedSubscriptionSummary": {
13+
"ActiveSubscription": false
14+
},
15+
"NewsFeeds": [
16+
{
17+
"ResourceUri": "/v1/newsfeeds/20141203082619076323088319",
18+
"Name": "My Very Special Newsfeed",
19+
"OwnerId": "20000426143505724628000000",
20+
"ProspectLinkId": "",
21+
"CreatedTimestamp": "2014-12-03T08:26:19Z",
22+
"Id": "20141203082619076323088319",
23+
"Active": "false",
24+
"ModificationTimestamp": "2014-12-03T08:26:19Z",
25+
"ExpirationDate": "2015-03-03",
26+
"Curated": "false",
27+
"NotificationMethods": ["Email"],
28+
"LastEventTimestamp": "",
29+
"Type": "SavedSearch"
30+
}
31+
]
32+
}
33+
]
34+
}
35+
}

spec/fixtures/saved_searches/without_newsfeed.json

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require './spec/spec_helper'
2+
3+
4+
describe Newsfeed do
5+
6+
before do
7+
stub_auth_request
8+
end
9+
10+
describe "update!" do
11+
it "should update the attributes" do
12+
stub_api_get("/newsfeeds/20130625195235039712000000", "newsfeeds/get.json")
13+
stub_api_put("/newsfeeds/20130625195235039712000000", {:Active => false}, "newsfeeds/inactive.json")
14+
@newsfeed = Newsfeed.find("20130625195235039712000000")
15+
@newsfeed.update!(:Active => false)
16+
expect(@newsfeed.Active) == false
17+
end
18+
19+
end
20+
21+
end

spec/unit/spark_api/models/saved_search_spec.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,42 +138,45 @@
138138

139139
describe "can_have_newsfeed?" do
140140

141+
it "should return false for a provided search" do
142+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
143+
resource = subject.class.find(id)
144+
resource.stub(:is_provided_search?) { true }
145+
resource.can_have_newsfeed?.should == false
146+
end
147+
141148
it "should return false without at least three filter parameters" do
142149
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
143150
resource = subject.class.find(id)
144151
resource.Filter = "City Eq 'Moorhead' And MlsStatus Eq 'Active'"
145152
resource.can_have_newsfeed?.should == false
146-
147153
end
148154

149155
it "should return true with three filter parameters" do
150156
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
151157
resource = subject.class.find(id)
152-
resource.Filter = "City Eq 'Moorhead' And MlsStatus Eq 'Active' And PropertyType Eq 'A'"
158+
resource.stub(:is_provided_search?) { false }
153159
resource.can_have_newsfeed?.should == true
154160
end
155161

156162
end
157163

158-
describe "has_newsfeed?" do
159-
164+
describe "has_active_newsfeed?" do
160165
it "should return true if the search already has a newsfeed" do
161166
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
162167
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_newsfeed.json',
163168
{ "_expand" => "NewsFeedSubscriptionSummary" } )
164-
resource = subject.class.find(id)
165-
resource.has_newsfeed?.should == true
166-
169+
subject.class.find(id).has_active_newsfeed?.should == true
167170
end
171+
end
168172

169-
it "should return false if the search doesn't already has a newsfeed" do
170-
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/get.json')
171-
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/without_newsfeed.json',
173+
describe "has_inactive_newsfeed?" do
174+
it "should return true if the search has an inactive newsfeed" do
175+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json')
176+
stub_api_get("/#{subject.class.element_name}/#{id}", 'saved_searches/with_inactive_newsfeed.json',
172177
{ "_expand" => "NewsFeedSubscriptionSummary" } )
173-
resource = subject.class.find(id)
174-
resource.has_newsfeed?.should == false
178+
subject.class.find(id).has_inactive_newsfeed?.should == true
175179
end
176-
177180
end
178181

179182
describe "newsfeed" do

0 commit comments

Comments
 (0)