grouper-rest-client 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,6 @@
1
+ 2011-06-01 v0.2.7
2
+ - "G::R::C::R#subjects()" now returns [] if no subjects found.
3
+
1
4
  2011-05-31 v0.2.6
2
5
  - "G::R::C::R::Group#members()" now returns [] if no members found.
3
6
 
data/Rakefile CHANGED
@@ -1,10 +1,16 @@
1
1
  require 'bundler'
2
+ require 'rake/testtask'
2
3
  require 'rdoc-readme/rake_task'
3
- require 'rspec/core/rake_task'
4
4
 
5
5
  Bundler::GemHelper.install_tasks
6
6
  RDoc::Readme::RakeTask.new 'lib/grouper-rest-client.rb', 'README.rdoc'
7
- RSpec::Core::RakeTask.new(:spec)
8
7
 
9
- task :default => :spec
8
+ task :default => :test
9
+
10
+ Rake::TestTask.new { |t|
11
+ t.libs = [ 'test' ]
12
+ t.pattern = 'test/*_test.rb'
13
+ t.verbose = true
14
+ t.warning = true
15
+ }
10
16
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency( %q<json>, [ ">=1.5.1" ] )
23
23
  s.add_dependency( %q<rest-client>, [ ">=1.6.1" ] )
24
24
 
25
- s.add_development_dependency( %q<rspec>, [ ">=2.5.0" ] )
25
+ s.add_development_dependency( %q<fakeweb>, [ ">=1.3.0" ] )
26
+ s.add_development_dependency( %q<shoulda>, [ ">=2.11.3" ] )
26
27
  end
27
28
 
@@ -127,12 +127,15 @@ module Grouper # :nodoc:
127
127
  # +subjects+:: Get subject(s) matching this identifier.
128
128
  def subjects(subject)
129
129
  raise ArgumentError if subject.nil? || subject.empty?
130
- k1, k2 = 'WsGetSubjectsResults', 'wsSubjects'
131
- result = call("subjects/#{subject}")
130
+ k1, k2 = 'WsGetSubjectsResults', 'wsSubjects'
131
+
132
+ result = call("subjects/#{subject}")
132
133
  if result.key?(k1) && result[k1].key?(k2)
133
- return result[k1][k2].collect { |r| Grouper::Rest::Client::Resource::Subject.new(self, r) }
134
+ return result[k1][k2].select { |tmp| tmp['success'] == 'T' }.collect do |r|
135
+ Grouper::Rest::Client::Resource::Subject.new(self, r)
136
+ end
134
137
  end
135
- return result # TODO Probably wrong
138
+ result
136
139
  end
137
140
 
138
141
 
@@ -1,7 +1,7 @@
1
1
  module Grouper # :nodoc:
2
2
  module Rest # :nodoc:
3
3
  module Client
4
- VERSION = '0.2.6'
4
+ VERSION = '0.2.7'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,90 @@
1
+ require 'test_helper'
2
+
3
+ class SubjectsTest < Test::Unit::TestCase
4
+
5
+ context '#subjects()' do
6
+ setup do
7
+ FakeWeb.allow_net_connect = false
8
+ @url = 'http://grouper.example.org'
9
+ @grouper = Grouper::Rest::Client::Resource.new @url
10
+ end
11
+
12
+ context 'invalid argument' do
13
+ should 'raise ArgumentError when query string is nil' do
14
+ assert_raise(ArgumentError) { @grouper.subjects(nil) }
15
+ end
16
+ should 'raise ArgumentError when query string is empty' do
17
+ assert_raise(ArgumentError) { @grouper.subjects('') }
18
+ end
19
+ end
20
+
21
+ context 'when subject not found' do
22
+ setup do
23
+ query = 'no_such_subject'
24
+ mock = JSON.generate(
25
+ {
26
+ 'WsGetSubjectsResults' =>
27
+ {
28
+ 'wsSubjects' =>
29
+ [
30
+ {
31
+ 'id' => 'no_such_subject',
32
+ 'resultCode' => 'SUBJECT_NOT_FOUND',
33
+ 'success' => 'F'
34
+ }
35
+ ]
36
+ }
37
+ }
38
+ )
39
+ FakeWeb.register_uri( :get, "#{@url}/subjects/#{query}", :body => mock )
40
+ @result = @grouper.subjects(query)
41
+ @response = @grouper.response
42
+ end # setup
43
+
44
+ should 'return an empty array' do
45
+ assert @result.instance_of? Array
46
+ assert_equal 0, @result.size
47
+ end
48
+
49
+ end # context 'when subject not found'
50
+
51
+ context 'when subject found' do
52
+ setup do
53
+ query = 'blair'
54
+ mock = JSON.generate(
55
+ {
56
+ 'WsGetSubjectsResults' =>
57
+ {
58
+ 'wsSubjects' =>
59
+ [
60
+ {
61
+ 'id' => '12345678A',
62
+ 'name' => 'Blair Christensen',
63
+ 'resultCode' => 'SUCCESS',
64
+ 'sourceId' => 'mcdb',
65
+ 'success' => 'T'
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ )
71
+ FakeWeb.register_uri( :get, "#{@url}/subjects/#{query}", :body => mock )
72
+ @result = @grouper.subjects(query)
73
+ @response = @grouper.response
74
+ end # setup
75
+
76
+ should 'return an array with one expected entry' do
77
+ assert @result.instance_of? Array
78
+ assert_equal 1, @result.size
79
+ s = @result.first
80
+ assert s.instance_of? Grouper::Rest::Client::Resource::Subject
81
+ assert_equal '12345678A', s['id']
82
+ assert_equal 'Blair Christensen', s['name']
83
+ end
84
+
85
+ end # context 'when successful'
86
+
87
+ end # context '#subjects()'
88
+
89
+ end # class SubjectsTest
90
+
@@ -1,2 +1,6 @@
1
+ require 'rubygems'
2
+ require 'fakeweb'
3
+ require 'shoulda'
4
+ require 'test/unit'
1
5
  require File.join( File.dirname(__FILE__), '..', 'lib', 'grouper-rest-client' )
2
6
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grouper-rest-client
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 25
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 6
9
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Blair Christensen
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-05-31 00:00:00 -05:00
18
+ date: 2011-06-01 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 1
28
30
  segments:
29
31
  - 1
30
32
  - 5
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 13
43
46
  segments:
44
47
  - 1
45
48
  - 6
@@ -48,20 +51,37 @@ dependencies:
48
51
  type: :runtime
49
52
  version_requirements: *id002
50
53
  - !ruby/object:Gem::Dependency
51
- name: rspec
54
+ name: fakeweb
52
55
  prerelease: false
53
56
  requirement: &id003 !ruby/object:Gem::Requirement
54
57
  none: false
55
58
  requirements:
56
59
  - - ">="
57
60
  - !ruby/object:Gem::Version
61
+ hash: 27
58
62
  segments:
59
- - 2
60
- - 5
63
+ - 1
64
+ - 3
61
65
  - 0
62
- version: 2.5.0
66
+ version: 1.3.0
63
67
  type: :development
64
68
  version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 37
78
+ segments:
79
+ - 2
80
+ - 11
81
+ - 3
82
+ version: 2.11.3
83
+ type: :development
84
+ version_requirements: *id004
65
85
  description: REST client for accessing the Grouper WS API
66
86
  email:
67
87
  - blair.christensen@gmail.com
@@ -81,8 +101,8 @@ files:
81
101
  - lib/grouper-rest-client.rb
82
102
  - lib/grouper-rest-client/resource.rb
83
103
  - lib/grouper-rest-client/version.rb
84
- - spec/resource_spec.rb
85
- - spec/spec_helper.rb
104
+ - test/subjects_test.rb
105
+ - test/test_helper.rb
86
106
  has_rdoc: true
87
107
  homepage: https://github.com/blairc/
88
108
  licenses: []
@@ -97,6 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
117
  requirements:
98
118
  - - ">="
99
119
  - !ruby/object:Gem::Version
120
+ hash: 3
100
121
  segments:
101
122
  - 0
102
123
  version: "0"
@@ -105,16 +126,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
126
  requirements:
106
127
  - - ">="
107
128
  - !ruby/object:Gem::Version
129
+ hash: 3
108
130
  segments:
109
131
  - 0
110
132
  version: "0"
111
133
  requirements: []
112
134
 
113
135
  rubyforge_project: grouper-rest-client
114
- rubygems_version: 1.3.7
136
+ rubygems_version: 1.6.2
115
137
  signing_key:
116
138
  specification_version: 3
117
139
  summary: REST client for accessing the Grouper WS API
118
140
  test_files:
119
- - spec/resource_spec.rb
120
- - spec/spec_helper.rb
141
+ - test/subjects_test.rb
142
+ - test/test_helper.rb
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Grouper::Rest::Client::Resource initialization" do
4
-
5
- context "with no arguments" do
6
- it "should raise ArgumentError" do
7
- lambda { Grouper::Rest::Client::Resource.new }.should raise_error(ArgumentError)
8
- end
9
- end
10
-
11
- context "with one argument" do
12
-
13
- context "that is invalid" do
14
- it "should raise ArgumentError when nil" do
15
- lambda { Grouper::Rest::Client::Resource.new(nil) }.should raise_error(ArgumentError)
16
- end
17
- it "should raise ArgumentError when blank" do
18
- lambda { Grouper::Rest::Client::Resource.new('') }.should raise_error(ArgumentError)
19
- end
20
- end
21
-
22
- context "that is valid" do
23
- it "should return Grouper::Rest::Client::Resource object" do
24
- Grouper::Rest::Client::Resource.new('foo').should be_an_instance_of(Grouper::Rest::Client::Resource)
25
- end
26
- end
27
-
28
- end
29
-
30
- end # describe initialization
31
-
32
-
33
- describe "Grouper::Rest::Client::Resource#groups()" do
34
-
35
- before(:each) do
36
- @grouper = Grouper::Rest::Client::Resource.new('foo')
37
- end
38
-
39
- context "with no arguments" do
40
- it "should raise ArgumentError" do
41
- lambda { @grouper.groups }.should raise_error(ArgumentError)
42
- end
43
- end
44
-
45
- context "with one argument" do
46
- context "that is invalid" do
47
- it "should raise ArgumentError when nil" do
48
- lambda { @grouper.groups(nil) }.should raise_error(ArgumentError)
49
- end
50
- it "should raise ArgumentError when blank" do
51
- lambda { @grouper.groups('') }.should raise_error(ArgumentError)
52
- end
53
- end
54
- end
55
-
56
- end # describe #groups()
57
-
58
-
59
- describe "Grouper::Rest::Client::Resource#error?()" do
60
- context "before any WS calls have been made" do
61
- it "should be false" do
62
- Grouper::Rest::Client::Resource.new('foo').error?.should be_false
63
- end
64
- end
65
- end # describe #error?()
66
-
67
-
68
- describe "Grouper::Rest::Client::Resource#ok?()" do
69
- context "before any WS calls have been made" do
70
- it "should be true" do
71
- Grouper::Rest::Client::Resource.new('foo').ok?.should be_true
72
- end
73
- end
74
- end # describe #ok?()
75
-
76
-
77
- describe "Grouper::Rest::Client::Resource#response" do
78
- context "before any WS calls have been made" do
79
- it "should be nil" do
80
- Grouper::Rest::Client::Resource.new('foo').response.should be_nil
81
- end
82
- end
83
- end # describe #response
84
-
85
-
86
- describe "Grouper::Rest::Client::Resource#subjects()" do
87
-
88
- before(:each) do
89
- @grouper = Grouper::Rest::Client::Resource.new('foo')
90
- end
91
-
92
- context "with no arguments" do
93
- it "should raise ArgumentError" do
94
- lambda { @grouper.subjects }.should raise_error(ArgumentError)
95
- end
96
- end
97
-
98
- context "with one argument" do
99
- context "that is invalid" do
100
- it "should raise ArgumentError when nil" do
101
- lambda { @grouper.subjects(nil) }.should raise_error(ArgumentError)
102
- end
103
- it "should raise ArgumentError when blank" do
104
- lambda { @grouper.subjects('') }.should raise_error(ArgumentError)
105
- end
106
- end
107
- end
108
-
109
- end # describe #subjects()
110
-