desmos 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Desmos::Utils, '.escape' do
4
+
5
+ it "should escape correctly" do
6
+ Desmos::Utils.escape("fo<o>bar").should == "fo%3Co%3Ebar"
7
+ Desmos::Utils.escape("a space").should == "a+space"
8
+ Desmos::Utils.escape("q1!2\"'w$5&7/z8)?\\").should == "q1%212%22%27w%245%267%2Fz8%29%3F%5C"
9
+ end
10
+
11
+ it "should escape correctly for multibyte characters" do
12
+ matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsumoto
13
+ matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
14
+ Desmos::Utils.escape(matz_name).should == '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8'
15
+ matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto
16
+ matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
17
+ Desmos::Utils.escape(matz_name_sep).should == '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8'
18
+ end
19
+
20
+ end
@@ -0,0 +1,203 @@
1
+ require 'spec_helper'
2
+
3
+ describe Desmos::Whiteboard, '.new' do
4
+
5
+ it 'sets the instance variables based upon the options passed into the initializer' do
6
+ tutor = Desmos::Tutor.new(:id => 1, :name => 'test')
7
+ students = [Desmos::Student.new(:id => 2, :name => 'student')]
8
+ whiteboard = Desmos::Whiteboard.new(
9
+ :hash => 'abcde',
10
+ :title => 'Title',
11
+ :tutor => tutor,
12
+ :students => students
13
+ )
14
+ whiteboard.hash.should eql('abcde')
15
+ whiteboard.title.should eql('Title')
16
+ whiteboard.tutor.should eql(tutor)
17
+ whiteboard.students.should eql(students)
18
+ end
19
+
20
+ it 'requires that the tutor option be either of type Desmos::Tutor or NilClass' do
21
+ lambda {
22
+ Desmos::Whiteboard.new(:tutor => 'tutor')
23
+ }.should raise_error(ArgumentError, ':tutor option must be either of type Desmos::Tutor or NilClass')
24
+ end
25
+
26
+ it 'requires that the students option be either an Array containing object of type Desmos::Student or NilClass' do
27
+ lambda {
28
+ Desmos::Whiteboard.new(:students => ['student'])
29
+ }.should raise_error(ArgumentError, ':students option must be either an Array containing object of type Desmos::Student or NilClass')
30
+
31
+ lambda {
32
+ Desmos::Whiteboard.new(:students => 'student')
33
+ }.should raise_error(ArgumentError, ':students option must be either an Array containing object of type Desmos::Student or NilClass')
34
+
35
+ lambda {
36
+ Desmos::Whiteboard.new(:students => 2)
37
+ }.should raise_error(ArgumentError, ':students option must be either an Array containing object of type Desmos::Student or NilClass')
38
+
39
+ lambda {
40
+ Desmos::Whiteboard.new(:students => [Desmos::Student.new(:id => 2, :name => 'student')])
41
+ }.should_not raise_error
42
+
43
+ lambda {
44
+ Desmos::Whiteboard.new(:students => nil)
45
+ }.should_not raise_error
46
+ end
47
+
48
+ end
49
+
50
+ describe Desmos::Whiteboard, '#save' do
51
+
52
+ context 'when the whiteboard does not already exist' do
53
+
54
+ before(:each) do
55
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/create/).
56
+ to_return(:status => 200, :body => "{\"success\": \"true\", \"hash\": \"abcde\"}")
57
+
58
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/add_user/).
59
+ to_return(:status => 200, :body => "{\"success\": \"true\", \"hash\": \"abcde\"}")
60
+ end
61
+
62
+ it 'calls out to the Desmos API to save the whiteboard, tutor, and students' do
63
+ tutor = Desmos::Tutor.new(:id => 1, :name => 'tutor')
64
+ student = Desmos::Student.new(:id => 2, :name => 'student')
65
+ whiteboard = Desmos::Whiteboard.new(:tutor => tutor)
66
+ whiteboard.students << student
67
+ whiteboard.save
68
+
69
+ assert_requested :get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/create/, :times => 1
70
+ assert_requested :get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/add_user/, :times => 2
71
+ end
72
+
73
+ end
74
+
75
+ context 'when the whiteboard already exists' do
76
+
77
+ before(:each) do
78
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/create/).
79
+ to_return(:status => 200, :body => "{\"success\": \"true\", \"hash\": \"abcde\"}").
80
+ to_return(:status => 200, :body => "{\"success\":\"false\",\"error_code\":1,\"error_message\":\"whiteboard already exists\"}")
81
+
82
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/add_user/).
83
+ to_return(:status => 200, :body => "{\"success\": \"true\", \"hash\": \"abcde\"}")
84
+ end
85
+
86
+ it 'calls out to the Desmos API to save the whiteboard, tutor, and students' do
87
+ whiteboard = Desmos::Whiteboard.new
88
+ whiteboard.save
89
+ whiteboard.save
90
+
91
+ assert_requested :get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/create/, :times => 2
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ describe Desmos::Whiteboard, '#request_options' do
99
+
100
+ it 'builds a hash of options used to make requests from the Desmos API' do
101
+ whiteboard = Desmos::Whiteboard.new
102
+ whiteboard.request_options.should eql({})
103
+
104
+ whiteboard = Desmos::Whiteboard.new(
105
+ :hash => 'abcde',
106
+ :title => 'Title'
107
+ )
108
+ whiteboard.request_options.should eql({
109
+ :hash => 'abcde',
110
+ :title => 'Title'
111
+ })
112
+
113
+ whiteboard = Desmos::Whiteboard.new(
114
+ :hash => 'abcde',
115
+ :title => 'Title',
116
+ :tutor => Desmos::Tutor.new(
117
+ :id => 1,
118
+ :hash => 'zyxwv',
119
+ :name => 'Mr. Tutor'
120
+ )
121
+ )
122
+ whiteboard.request_options.should eql({
123
+ :hash => 'abcde',
124
+ :title => 'Title',
125
+ :tutor_id => 1,
126
+ :tutor_hash => 'zyxwv',
127
+ :tutor_name => 'Mr. Tutor'
128
+ })
129
+ end
130
+
131
+ end
132
+
133
+ describe Desmos::Whiteboard, '.create' do
134
+
135
+ before(:each) do
136
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/create/).
137
+ to_return(:status => 200, :body => "{\"success\": \"true\", \"hash\": \"abcde\"}")
138
+ end
139
+
140
+ it 'returns a new instance of DesmosWhiteboard' do
141
+ whiteboard = Desmos::Whiteboard.create
142
+ whiteboard.should be_kind_of(Desmos::Whiteboard)
143
+ whiteboard.hash.should eql('abcde')
144
+ assert_requested :get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/create/, :times => 1
145
+ end
146
+
147
+ end
148
+
149
+ describe Desmos::Whiteboard, '.find' do
150
+
151
+ context 'when the Whiteboard exists on the Desmos API' do
152
+
153
+ before(:each) do
154
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/read/).
155
+ to_return(:status => 200, :body => "{\"title\": \"No Title\", \"hash\": \"abcde\", \"tutor\": {\"id\": null, \"name\": null, \"hash\": null}, \"students\": []}")
156
+ end
157
+
158
+ it 'requests a Whiteboard from the Desmos API using its unique hash value' do
159
+ whiteboard = Desmos::Whiteboard.find('abcde')
160
+ whiteboard.should be_instance_of(Desmos::Whiteboard)
161
+ whiteboard.hash.should eql('abcde')
162
+
163
+ assert_requested :get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/read/, :times => 1
164
+ end
165
+
166
+ end
167
+
168
+ context 'when the Whiteboard does not exist of the Desmos API' do
169
+
170
+ before(:each) do
171
+ stub_request(:get, /https\:\/\/api\.tutortrove\.com\/api_v1\/whiteboard\/read/).
172
+ to_return(:status => 200, :body => "{\"error_code\": 1, \"error_message\": \"Whiteboard not found\", \"success\": \"false\"}")
173
+ end
174
+
175
+ it 'raises an error if the Whiteboard' do
176
+ lambda { Desmos::Whiteboard.find('abcde') }.should raise_error(Desmos::WhiteboardNotFound, 'Whiteboard with HASH=abcde could not be found')
177
+ end
178
+
179
+ end
180
+
181
+ end
182
+
183
+ describe Desmos::Whiteboard, '#build_from_hash' do
184
+
185
+ it 'builds a fresh instance using the provided hash' do
186
+ whiteboard = Desmos::Whiteboard.new.build_from_hash({
187
+ :title => 'No Title',
188
+ :hash => 'abcde',
189
+ :tutor => {
190
+ :id => 1,
191
+ :hash => 'zyxwv',
192
+ :name => 'test'
193
+ },
194
+ :students => []
195
+ })
196
+ whiteboard.should be_instance_of(Desmos::Whiteboard)
197
+ whiteboard.title.should eql('No Title')
198
+ whiteboard.hash.should eql('abcde')
199
+ whiteboard.tutor.should be_instance_of(Desmos::Tutor)
200
+ whiteboard.students.should be_empty
201
+ end
202
+
203
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'desmos'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+ require 'webmock/rspec'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir["spec/support/**/*.rb"].each { |f| require f }
11
+
12
+ RSpec.configure do |config|
13
+ config.color_enabled = true
14
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.before(:each) do
3
+ Desmos::Configuration.domain = 'api.tutortrove.com'
4
+ Desmos::Configuration.version = 1
5
+ Desmos::Configuration.key = '111'
6
+ Desmos::Configuration.secret = 'abcde'
7
+ Desmos::Configuration.debug_mode = false
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: desmos
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Ryan Moran
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 59
27
+ segments:
28
+ - 0
29
+ - 8
30
+ - 2
31
+ version: 0.8.2
32
+ version_requirements: *id001
33
+ name: yajl-ruby
34
+ prerelease: false
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 5
43
+ segments:
44
+ - 0
45
+ - 4
46
+ - 5
47
+ version: 0.4.5
48
+ version_requirements: *id002
49
+ name: oauth
50
+ prerelease: false
51
+ type: :runtime
52
+ - !ruby/object:Gem::Dependency
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 7
59
+ segments:
60
+ - 3
61
+ - 0
62
+ version: "3.0"
63
+ version_requirements: *id003
64
+ name: activesupport
65
+ prerelease: false
66
+ type: :runtime
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ version_requirements: *id004
78
+ name: rspec
79
+ prerelease: false
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ version_requirements: *id005
92
+ name: jeweler
93
+ prerelease: false
94
+ type: :development
95
+ - !ruby/object:Gem::Dependency
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ version_requirements: *id006
106
+ name: autotest
107
+ prerelease: false
108
+ type: :development
109
+ - !ruby/object:Gem::Dependency
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ version_requirements: *id007
120
+ name: awesome_print
121
+ prerelease: false
122
+ type: :development
123
+ - !ruby/object:Gem::Dependency
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ version_requirements: *id008
134
+ name: webmock
135
+ prerelease: false
136
+ type: :development
137
+ - !ruby/object:Gem::Dependency
138
+ requirement: &id009 !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 13
144
+ segments:
145
+ - 1
146
+ - 2
147
+ - 9
148
+ version: 1.2.9
149
+ version_requirements: *id009
150
+ name: rspec
151
+ prerelease: false
152
+ type: :development
153
+ description: Desmos API Wrapper
154
+ email: ryan.moran@gmail.com
155
+ executables: []
156
+
157
+ extensions: []
158
+
159
+ extra_rdoc_files:
160
+ - LICENSE
161
+ - README.rdoc
162
+ files:
163
+ - .rvmrc
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - LICENSE
167
+ - README.rdoc
168
+ - Rakefile
169
+ - VERSION
170
+ - autotest/discover.rb
171
+ - desmos.gemspec
172
+ - lib/desmos.rb
173
+ - lib/desmos/configuration.rb
174
+ - lib/desmos/debug_mode.rb
175
+ - lib/desmos/errors.rb
176
+ - lib/desmos/request_support.rb
177
+ - lib/desmos/student.rb
178
+ - lib/desmos/tutor.rb
179
+ - lib/desmos/user.rb
180
+ - lib/desmos/utils.rb
181
+ - lib/desmos/whiteboard.rb
182
+ - spec/desmos/configuration_spec.rb
183
+ - spec/desmos/request_support_spec.rb
184
+ - spec/desmos/student_spec.rb
185
+ - spec/desmos/tutor_spec.rb
186
+ - spec/desmos/user_spec.rb
187
+ - spec/desmos/utils_spec.rb
188
+ - spec/desmos/whiteboard_spec.rb
189
+ - spec/spec.opts
190
+ - spec/spec_helper.rb
191
+ - spec/support/configure.rb
192
+ homepage: http://github.com/RevolutionPrep/desmos
193
+ licenses: []
194
+
195
+ post_install_message:
196
+ rdoc_options: []
197
+
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ hash: 3
206
+ segments:
207
+ - 0
208
+ version: "0"
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ none: false
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ hash: 3
215
+ segments:
216
+ - 0
217
+ version: "0"
218
+ requirements: []
219
+
220
+ rubyforge_project:
221
+ rubygems_version: 1.8.6
222
+ signing_key:
223
+ specification_version: 3
224
+ summary: Desmos API Wrapper
225
+ test_files: []
226
+