koala 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,21 +17,21 @@ describe 'Koala::Facebook::GraphAPIMethods' do
17
17
  # and the other methods which do some post-processing locally
18
18
  context '#get_object' do
19
19
  it 'returns result of block' do
20
- @api.stub(:api).and_return(double("other results"))
21
- @api.get_object('koppel', &post_processing)["result"].should == result
20
+ allow(@api).to receive(:api).and_return(double("other results"))
21
+ expect(@api.get_object('koppel', &post_processing)["result"]).to eq(result)
22
22
  end
23
23
  end
24
24
 
25
25
  context '#get_picture' do
26
26
  it 'returns result of block' do
27
- @api.stub(:api).and_return("Location" => double("other result"))
28
- @api.get_picture('lukeshepard', &post_processing)["result"].should == result
27
+ allow(@api).to receive(:api).and_return("Location" => double("other result"))
28
+ expect(@api.get_picture('lukeshepard', &post_processing)["result"]).to eq(result)
29
29
  end
30
30
  end
31
31
 
32
32
  context '#fql_multiquery' do
33
33
  before do
34
- @api.should_receive(:get_object).and_return([
34
+ expect(@api).to receive(:get_object).and_return([
35
35
  {"name" => "query1", "fql_result_set" => [{"id" => 123}]},
36
36
  {"name" => "query2", "fql_result_set" => ["id" => 456]}
37
37
  ])
@@ -43,18 +43,41 @@ describe 'Koala::Facebook::GraphAPIMethods' do
43
43
  'query2' => [{'id' => 456}]
44
44
  }
45
45
  response = @api.fql_multiquery({}, &post_processing)
46
- response["args"].should == resolved_result
47
- response["result"].should == result
46
+ expect(response["args"]).to eq(resolved_result)
47
+ expect(response["result"]).to eq(result)
48
48
  end
49
49
  end
50
50
 
51
51
  context '#get_page_access_token' do
52
52
  it 'returns result of block' do
53
53
  token = Koala::MockHTTPService::APP_ACCESS_TOKEN
54
- @api.stub(:api).and_return("access_token" => token)
54
+ allow(@api).to receive(:api).and_return("access_token" => token)
55
55
  response = @api.get_page_access_token('facebook', &post_processing)
56
- response["args"].should == token
57
- response["result"].should == result
56
+ expect(response["args"]).to eq(token)
57
+ expect(response["result"]).to eq(result)
58
+ end
59
+ end
60
+ end
61
+
62
+ context '#graph_call' do
63
+ describe "the appsecret_proof option" do
64
+ let(:path) { '/path' }
65
+
66
+ it "is enabled by default if an app secret is present" do
67
+ api = Koala::Facebook::API.new(@token, "mysecret")
68
+ expect(api).to receive(:api).with(path, {}, 'get', :appsecret_proof => true)
69
+ api.graph_call(path)
70
+ end
71
+
72
+ it "can be disabled manually" do
73
+ api = Koala::Facebook::API.new(@token, "mysecret")
74
+ expect(api).to receive(:api).with(path, {}, 'get', hash_not_including(appsecret_proof: true))
75
+ api.graph_call(path, {}, "get", appsecret_proof: false)
76
+ end
77
+
78
+ it "isn't included if no app secret is present" do
79
+ expect(@api).to receive(:api).with(path, {}, 'get', {})
80
+ @api.graph_call(path)
58
81
  end
59
82
  end
60
83
  end
@@ -13,32 +13,32 @@ describe Koala::Facebook::GraphCollection do
13
13
  end
14
14
 
15
15
  it "subclasses Array" do
16
- Koala::Facebook::GraphCollection.ancestors.should include(Array)
16
+ expect(Koala::Facebook::GraphCollection.ancestors).to include(Array)
17
17
  end
18
18
 
19
19
  it "creates an array-like object" do
20
- Koala::Facebook::GraphCollection.new(@result, @api).should be_an(Array)
20
+ expect(Koala::Facebook::GraphCollection.new(@result, @api)).to be_an(Array)
21
21
  end
22
22
 
23
23
  it "contains the result data" do
24
- @result["data"].each_with_index {|r, i| @collection[i].should == r}
24
+ @result["data"].each_with_index {|r, i| expect(@collection[i]).to eq(r)}
25
25
  end
26
26
 
27
27
  it "has a read-only paging attribute" do
28
- @collection.methods.map(&:to_sym).should include(:paging)
29
- @collection.methods.map(&:to_sym).should_not include(:paging=)
28
+ expect(@collection.methods.map(&:to_sym)).to include(:paging)
29
+ expect(@collection.methods.map(&:to_sym)).not_to include(:paging=)
30
30
  end
31
31
 
32
32
  it "sets paging to results['paging']" do
33
- @collection.paging.should == @result["paging"]
33
+ expect(@collection.paging).to eq(@result["paging"])
34
34
  end
35
35
 
36
36
  it "sets raw_response to the original results" do
37
- @collection.raw_response.should == @result
37
+ expect(@collection.raw_response).to eq(@result)
38
38
  end
39
39
 
40
40
  it "sets the API to the provided API" do
41
- @collection.api.should == @api
41
+ expect(@collection.api).to eq(@api)
42
42
  end
43
43
 
44
44
  describe "when getting a whole page" do
@@ -53,24 +53,24 @@ describe Koala::Facebook::GraphCollection do
53
53
  end
54
54
 
55
55
  it "should return the previous page of results" do
56
- @collection.should_receive(:previous_page_params).and_return([@base, @args])
57
- @api.should_receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
58
- Koala::Facebook::GraphCollection.should_receive(:new).with(@second_page, @api).and_return(@page_of_results)
59
- @collection.previous_page.should == @page_of_results
56
+ expect(@collection).to receive(:previous_page_params).and_return([@base, @args])
57
+ expect(@api).to receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
58
+ expect(Koala::Facebook::GraphCollection).to receive(:new).with(@second_page, @api).and_return(@page_of_results)
59
+ expect(@collection.previous_page).to eq(@page_of_results)
60
60
  end
61
61
 
62
62
  it "should return the next page of results" do
63
- @collection.should_receive(:next_page_params).and_return([@base, @args])
64
- @api.should_receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
65
- Koala::Facebook::GraphCollection.should_receive(:new).with(@second_page, @api).and_return(@page_of_results)
63
+ expect(@collection).to receive(:next_page_params).and_return([@base, @args])
64
+ expect(@api).to receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
65
+ expect(Koala::Facebook::GraphCollection).to receive(:new).with(@second_page, @api).and_return(@page_of_results)
66
66
 
67
- @collection.next_page.should == @page_of_results
67
+ expect(@collection.next_page).to eq(@page_of_results)
68
68
  end
69
69
 
70
70
  it "should return nil it there are no other pages" do
71
71
  %w{next previous}.each do |this|
72
- @collection.should_receive("#{this}_page_params".to_sym).and_return(nil)
73
- @collection.send("#{this}_page").should == nil
72
+ expect(@collection).to receive("#{this}_page_params".to_sym).and_return(nil)
73
+ expect(@collection.send("#{this}_page")).to eq(nil)
74
74
  end
75
75
  end
76
76
  end
@@ -79,38 +79,38 @@ describe Koala::Facebook::GraphCollection do
79
79
  describe "#parse_page_url" do
80
80
  it "should pass the url to the class method" do
81
81
  url = double("url")
82
- Koala::Facebook::GraphCollection.should_receive(:parse_page_url).with(url)
82
+ expect(Koala::Facebook::GraphCollection).to receive(:parse_page_url).with(url)
83
83
  @collection.parse_page_url(url)
84
84
  end
85
85
 
86
86
  it "should return the result of the class method" do
87
87
  parsed_content = double("parsed_content")
88
- Koala::Facebook::GraphCollection.stub(:parse_page_url).and_return(parsed_content)
89
- @collection.parse_page_url(double("url")).should == parsed_content
88
+ allow(Koala::Facebook::GraphCollection).to receive(:parse_page_url).and_return(parsed_content)
89
+ expect(@collection.parse_page_url(double("url"))).to eq(parsed_content)
90
90
  end
91
91
  end
92
92
 
93
93
  describe ".parse_page_url" do
94
94
  it "should return the base as the first array entry" do
95
95
  base = "url_path"
96
- Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?anything").first.should == base
96
+ expect(Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?anything").first).to eq(base)
97
97
  end
98
98
 
99
99
  it "should return the arguments as a hash as the last array entry" do
100
100
  args_hash = {"one" => "val_one", "two" => "val_two"}
101
- Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
101
+ expect(Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last).to eq(args_hash)
102
102
  end
103
103
 
104
104
  it "works with non-.com addresses" do
105
105
  base = "url_path"
106
106
  args_hash = {"one" => "val_one", "two" => "val_two"}
107
- Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").should == [base, args_hash]
107
+ expect(Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}")).to eq([base, args_hash])
108
108
  end
109
109
 
110
110
  it "works with addresses with irregular characters" do
111
111
  access_token = "appid123a|fdcba"
112
112
  base, args_hash = Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/foo?token=#{access_token}")
113
- args_hash["token"].should == access_token
113
+ expect(args_hash["token"]).to eq(access_token)
114
114
  end
115
115
  end
116
116
  end
@@ -118,29 +118,29 @@ describe Koala::Facebook::GraphCollection do
118
118
  describe ".evaluate" do
119
119
  it "returns the original result if it's provided a non-hash result" do
120
120
  result = []
121
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
121
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
122
122
  end
123
123
 
124
124
  it "returns the original result if it's provided a nil result" do
125
125
  result = nil
126
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
126
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
127
127
  end
128
128
 
129
129
  it "returns the original result if the result doesn't have a data key" do
130
130
  result = {"paging" => {}}
131
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
131
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
132
132
  end
133
133
 
134
134
  it "returns the original result if the result's data key isn't an array" do
135
135
  result = {"data" => {}, "paging" => {}}
136
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
136
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
137
137
  end
138
138
 
139
139
  it "returns a new GraphCollection of the result if it has an array data key and a paging key" do
140
140
  result = {"data" => [], "paging" => {}}
141
141
  expected = :foo
142
- Koala::Facebook::GraphCollection.should_receive(:new).with(result, @api).and_return(expected)
143
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == expected
142
+ expect(Koala::Facebook::GraphCollection).to receive(:new).with(result, @api).and_return(expected)
143
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(expected)
144
144
  end
145
145
  end
146
146
 
@@ -148,12 +148,12 @@ describe Koala::Facebook::GraphCollection do
148
148
  let(:paging){ {"next" => "http://example.com/?a=2&b=3"} }
149
149
 
150
150
  it "should get next page" do
151
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
151
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
152
152
  @collection.next_page
153
153
  end
154
154
 
155
155
  it "should get next page with extra parameters" do
156
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
156
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
157
157
  @collection.next_page("c" => "4")
158
158
  end
159
159
  end
@@ -162,12 +162,12 @@ describe Koala::Facebook::GraphCollection do
162
162
  let(:paging){ {"previous" => "http://example.com/?a=2&b=3"} }
163
163
 
164
164
  it "should get previous page" do
165
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
165
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
166
166
  @collection.previous_page
167
167
  end
168
168
 
169
169
  it "should get previous page with extra parameters" do
170
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
170
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
171
171
  @collection.previous_page("c" => "4")
172
172
  end
173
173
  end