codefumes 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,23 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
- include CodeFumesServiceStubs
4
-
5
3
  describe "Commit" do
4
+ include CodeFumesServiceHelpers::Commit
5
+
6
6
  before(:all) do
7
- @identifier = "f3badd5624dfbcf5176f0471261731e1b92ce957"
8
7
  FakeWeb.allow_net_connect = false
8
+
9
+ @project_name = "Project_Name(tm)"
10
+ @pub_key = 'public_key_value'
11
+ @priv_key = 'private_key_value'
12
+ @anonymous_base_uri = "http://codefumes.com/api/v1/xml"
13
+ @authenticated_base_uri = "http://#{@pub_key}:#{@priv_key}@codefumes.com/api/v1/xml/projects"
14
+ @project = Project.new(:public_key => @pub_key,
15
+ :private_key => @priv_key,
16
+ :name => @project_name)
17
+ @authd_project_api_uri = "#{@authenticated_base_uri}/projects/#{@pub_key}"
18
+ @anon_project_api_uri = "#{@anonymous_base_uri}/projects/#{@pub_key}"
19
+ @basic_auth_params = {:username => @pub_key, :password => @priv_key}
20
+ @identifier = "f3badd5624dfbcf5176f0471261731e1b92ce957"
9
21
  end
10
22
 
11
23
  after(:all) do
@@ -15,7 +27,7 @@ describe "Commit" do
15
27
  describe "find" do
16
28
  context "with a valid commit identifier" do
17
29
  before(:each) do
18
- stub_codefumes_uri("commits/#{@identifier}", ["200", "Ok"], single_commit)
30
+ register_find_uri
19
31
  @commit = Commit.find(@identifier)
20
32
  end
21
33
 
@@ -44,8 +56,7 @@ describe "Commit" do
44
56
 
45
57
  context "with a non-existant commit identifier" do
46
58
  before(:each) do
47
- @identifier = "non_existant_commit_identifier"
48
- stub_codefumes_uri("commits/#{@identifier}", ["404", "Not Found"], "")
59
+ register_find_uri(["404", "Not Found"], "")
49
60
  end
50
61
 
51
62
  it "returns nil" do
@@ -55,85 +66,65 @@ describe "Commit" do
55
66
  end
56
67
 
57
68
  describe "calling 'latest'" do
58
- before(:each) do
59
- @project_public_key = "apk"
60
- @request_uri = "projects/#{@project_public_key}/commits/latest"
61
- end
62
-
63
69
  context "with valid parameters" do
64
- before(:each) do
65
- stub_codefumes_uri(@request_uri, ["200", "Ok"], single_commit)
66
- end
67
-
68
70
  it "returns a commit object for the latest commit" do
69
- Commit.latest(@project_public_key).identifier.should == @identifier
71
+ register_latest_uri
72
+ Commit.latest(@pub_key).identifier.should == @identifier
70
73
  end
71
74
  end
72
75
 
73
76
  context "with invalid parameters" do
74
- before(:each) do
75
- stub_codefumes_uri(@request_uri, ["404", "Not Found"], single_commit)
76
- end
77
-
78
77
  it "returns nil" do
79
- Commit.latest(@project_public_key).should == nil
78
+ register_latest_uri(["404", "Not Found"], "")
79
+ Commit.latest(@pub_key).should == nil
80
80
  end
81
81
  end
82
82
  end
83
83
 
84
84
  describe "calling 'latest_identifier'" do
85
- before(:each) do
86
- @project_public_key = "apk"
87
- @request_uri = "projects/#{@project_public_key}/commits/latest"
88
- end
89
-
90
85
  context "with valid parameters" do
91
86
  context "when the specified project has commits stored" do
92
87
  it "returns the commit identifier of the latest commit" do
93
- stub_codefumes_uri(@request_uri, ["200", "Ok"], single_commit)
94
- Commit.latest_identifier(@project_public_key).should == @identifier
88
+ register_latest_uri
89
+ Commit.latest_identifier(@pub_key).should == @identifier
95
90
  end
96
91
  end
97
92
 
98
93
  context "when the specified project does not have any commits stored" do
99
94
  it "returns nil" do
100
- stub_codefumes_uri(@request_uri, ["404", "Not Found"], single_commit)
101
- Commit.latest_identifier(@project_public_key).should == nil
95
+ register_latest_uri(["404", "Not Found"], "")
96
+ Commit.latest_identifier(@pub_key).should == nil
102
97
  end
103
98
  end
104
99
  end
105
100
 
106
101
  context "with invalid parameters" do
107
102
  it "returns nil" do
108
- stub_codefumes_uri(@request_uri, ["404", "Not Found"], single_commit)
109
- Commit.latest(@project_public_key).should == nil
103
+ register_latest_uri(["404", "Not Found"], "")
104
+ Commit.latest(@pub_key).should == nil
110
105
  end
111
106
  end
112
107
  end
113
108
 
114
109
  describe "calling 'all'" do
115
- before(:each) do
116
- @project_public_key = "apk"
117
- end
118
-
119
110
  context "with valid parameters" do
120
111
  it "returns an array of commits" do
121
112
  register_index_uri
122
- Commit.all(@project_public_key).should have(3).items
113
+ Commit.all(@pub_key).should have(3).items
123
114
  end
124
115
  end
125
116
 
126
117
  context "with invalid parameters" do
127
118
  it "returns nil" do
128
- stub_codefumes_uri("projects/apk/commits", ["404", "Not Found"], single_commit)
129
- Commit.all(@project_public_key).should == nil
119
+ register_index_uri(["404", "Not Found"], "")
120
+ Commit.all(@pub_key).should == nil
130
121
  end
131
122
  end
132
123
  end
133
124
 
134
125
  describe "the convenience method" do
135
126
  before(:each) do
136
- stub_codefumes_uri("commits/f3badd5624dfbcf5176f0471261731e1b92ce957", ["200", "Ok"], single_commit)
127
+ register_find_uri
137
128
  @email = "jdoe@example.com"
138
129
  @name = "John Doe"
139
130
  @commit = Commit.find(@identifier)
@@ -155,31 +146,27 @@ describe "Commit" do
155
146
  end
156
147
 
157
148
  describe "accessing custom metrics" do
158
- before(:each) do
159
- @project_public_key = "apk"
160
- end
161
-
162
149
  context "when the commit does not have any custom attributes" do
163
150
  before(:each) do
164
- stub_codefumes_uri("projects/#{@project_public_key}/commits/latest", ["200", "Ok"], single_commit)
151
+ register_latest_uri
165
152
  end
166
153
 
167
154
  it "returns an empty Hash" do
168
- Commit.latest(@project_public_key).custom_attributes.should == {}
155
+ Commit.latest(@pub_key).custom_attributes.should == {}
169
156
  end
170
157
  end
171
158
 
172
159
  context "when the commit has defined custom attributes" do
173
160
  before(:each) do
174
- commit_content = single_commit(:include_custom_attributes => true)
175
- stub_codefumes_uri("projects/#{@project_public_key}/commits/latest", ["200", "Ok"], commit_content)
161
+ register_latest_uri(["200", "Ok"], fixtures[:commit_with_custom_attrs])
162
+ @commit = Commit.latest(@pub_key)
176
163
  end
177
164
 
178
165
  it "returns a Hash of key-value pairs (attribute_name -> attribute_value)" do
179
- Commit.latest(@project_public_key).custom_attributes.should be_instance_of(Hash)
180
- Commit.latest(@project_public_key).custom_attributes[:coverage].should == "83"
181
- Commit.latest(@project_public_key).custom_attributes[:random_attribute].should == "1"
182
- Commit.latest(@project_public_key).custom_attributes.size.should == 2
166
+ @commit.custom_attributes.should be_instance_of(Hash)
167
+ @commit.custom_attributes[:coverage].should == "83"
168
+ @commit.custom_attributes[:random_attribute].should == "1"
169
+ @commit.custom_attributes.size.should == 2
183
170
  end
184
171
  end
185
172
  end
@@ -226,4 +226,20 @@ describe "ConfigFile" do
226
226
  end
227
227
  end
228
228
  end
229
+
230
+ describe "calling 'api_key'" do
231
+ context "when credentials exist in the file" do
232
+ it "returns the API key stored in the file" do
233
+ api_key_value = "API_KEY"
234
+ ConfigFile.save_credentials(api_key_value)
235
+ ConfigFile.api_key.should == api_key_value
236
+ end
237
+ end
238
+
239
+ context "when no credentials exist in the file" do
240
+ it "returns an empty Hash" do
241
+ ConfigFile.api_key.should == nil
242
+ end
243
+ end
244
+ end
229
245
  end
@@ -1,57 +1,54 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
+ module PayloadSpecHelper
4
+ end
5
+
3
6
  describe "Payload" do
7
+ include CodeFumesServiceHelpers::Payload
8
+
4
9
  after(:all) do
5
10
  FakeWeb.allow_net_connect = false
6
11
  FakeWeb.clean_registry
7
12
  end
8
13
 
14
+ before(:each) do
15
+ setup_fixture_base
16
+ @payload = Payload.new(:public_key => @pub_key, :private_key => @priv_key, :content => {:commits => @commit_data})
17
+ @payload_query = {:payload => {:commits => @commit_data}}
18
+ @basic_auth_params = {:username => @pub_key, :password => @priv_key}
19
+ end
20
+
9
21
  describe "save" do
10
- before(:each) do
11
- @project = Project.new(:public_key => "apk", :private_key => 'private_key_value')
22
+ it "sets basic auth with the public and private key" do
23
+ register_create_uri(["401", "Unauthorized"], "")
24
+ Payload.should_receive(:post).with("/projects/#{@project.public_key}/payloads", :query => @payload_query, :basic_auth => @basic_auth_params).and_return(mock("response", :code => 401))
25
+ @payload.save
12
26
  end
13
27
 
14
28
  context "with valid parameters" do
15
29
  before(:each) do
16
- FakeWeb.register_uri( :post, "http://www.codefumes.com:80/api/v1/xml/projects/apk/payloads?payload[commits]=data_to_send_up",
17
- :status => ["201", "Created"],
18
- :string => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<payload>\n <created_at>Creation Date</created_at>\n </payload>\n")
30
+ register_create_uri(["201", "Created"])
19
31
  end
20
32
 
21
- it "sets basic auth with the public and private key" do
22
- payload = Payload.new(:public_key => @project.public_key, :private_key => @project.private_key, :content => {:commits => "data_to_send_up"})
23
- Payload.should_receive(:post).with("/projects/#{@project.public_key}/payloads", :query => {:payload => {:commits => "data_to_send_up"}}, :basic_auth => {:username => @project.public_key, :password => @project.private_key}).and_return(mock("response", :code => 401))
24
- payload.save
33
+ it "sets a value for 'created_at'" do
34
+ @payload.created_at.should == nil
35
+ @payload.save.should == true
36
+ @payload.created_at.should_not == nil
25
37
  end
38
+ end
26
39
 
27
- context "with Created response" do
28
- [:created_at].each do |method_name|
29
- it "sets the '#{method_name.to_s}'" do
30
- payload = Payload.new(:public_key => @project.public_key, :content => {:commits => "data_to_send_up"})
31
- payload.send(method_name).should == nil
32
- payload.save.should == true
33
- payload.send(method_name).should_not == nil
34
- end
35
- end
40
+ context "with Unauthorized response" do
41
+ before(:each) do
42
+ register_create_uri(["401", "Unauthorized"], "")
36
43
  end
37
44
 
38
- context "with Unauthorized response" do
39
- before(:each) do
40
- @project = Project.new(:public_key => "apk")
41
- FakeWeb.register_uri( :post, "http://www.codefumes.com:80/api/v1/xml/projects/apk/payloads?payload[commits]=data_to_send_up",
42
- :status => ["401", "Unauthorized"])
43
- end
44
-
45
- [:created_at].each do |method_name|
46
- it "sets the '#{method_name.to_s}'" do
47
- payload = Payload.new(:public_key => @project.public_key, :content => {:commits => "data_to_send_up"})
48
- payload.send(method_name).should == nil
49
- payload.save.should == false
50
- payload.send(method_name).should == nil
51
- end
45
+ [:created_at].each do |method_name|
46
+ it "sets the '#{method_name.to_s}'" do
47
+ @payload.send(method_name).should == nil
48
+ @payload.save.should == false
49
+ @payload.send(method_name).should == nil
52
50
  end
53
51
  end
54
-
55
52
  end
56
53
 
57
54
  context "when the payload does not have any content" do
@@ -60,6 +57,7 @@ describe "Payload" do
60
57
  end
61
58
 
62
59
  it "returns true without attempting to save to the site" do
60
+ Payload.should_not_receive(:post)
63
61
  @payload.save.should == true
64
62
  end
65
63
 
@@ -71,16 +69,12 @@ describe "Payload" do
71
69
 
72
70
  context "with invalid parameters" do
73
71
  before(:each) do
74
- FakeWeb.register_uri( :post, "http://www.codefumes.com:80/api/v1/xml/projects/apk/payloads?payload[commits]=invalid_data",
75
- :status => ["422", "Unprocessable Entity"])
72
+ register_create_uri
76
73
  end
77
74
 
78
- [:created_at].each do |method_name|
79
- it "does not set a value for '#{method_name.to_s}'" do
80
- payload = Payload.new(:public_key => @project.public_key, :content => {:commits => "invalid_data"})
81
- payload.save.should == false
82
- payload.send(method_name).should == nil
83
- end
75
+ it "does not set a value for 'created_at'" do
76
+ @payload.save.should == false
77
+ @payload.created_at.should == nil
84
78
  end
85
79
  end
86
80
  end
@@ -1,29 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
- def register_create_uri
4
- FakeWeb.register_uri( :post, "http://www.codefumes.com:80/api/v1/xml/projects?project[name]=&project[public_key]=",
5
- :status => ["201", "Created"],
6
- :string => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n <access-secret nil=\"true\"></access-secret>\n <created-at type=\"datetime\">2009-04-29T23:18:03Z</created-at>\n <public-key>foofoolerue</public-key>\n <private-key>foobarbaz</private-key>\n <updated-at type=\"datetime\">2009-04-29T23:18:03Z</updated-at>\n <short_uri>http://www.codefumes.com/p/foofoolerue</short_uri>\n <community_uri>http://www.codefumes.com/community/projects/1</community_uri>\n <api-uri>http://www.codefumes.com/api/v1/xml/projects/1.xml</api-uri>\n</project>")
7
- end
8
-
9
- def register_update_uri(public_key = "public_key_value", project_name = "The Project Name(tm)")
10
- response = {:status => ["200", "Ok"], :string => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n <access-secret nil=\"true\"></access-secret>\n <created-at type=\"datetime\">2009-04-29T23:18:03Z</created-at>\n <public-key>existing_public_key</public-key>\n <private-key>private_key_value</private-key>\n <updated-at type=\"datetime\">2009-04-29T23:18:03Z</updated-at>\n <short_uri>http://www.codefumes.com/p/#{public_key}</short_uri>\n <community_uri>http://www.codefumes.com/community/projects/#{public_key}</community_uri>\n <api-uri>http://www.codefumes.com/api/v1/xml/projects/#{public_key}.xml</api-uri>\n <name>#{project_name}</name>\n</project>\n"}
11
- FakeWeb.register_uri(:put, "http://www.codefumes.com/api/v1/xml/projects/existing_public_key?project[name]=#{project_name}",
12
- response)
13
- end
14
-
15
- def register_show_uri(public_key = "public_key_value", project_name = "The Project Name(tm)", status_code = ["200", "Ok"])
16
- FakeWeb.register_uri(:get, "http://www.codefumes.com/api/v1/xml/projects/#{public_key}",
17
- :status => status_code,
18
- :string => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n <access-secret nil=\"true\"></access-secret>\n <created-at type=\"datetime\">2009-04-29T23:18:03Z</created-at>\n <public-key>#{public_key}</public-key>\n <private-key>private_key_value</private-key>\n <updated-at type=\"datetime\">2009-04-29T23:18:03Z</updated-at>\n <short_uri>http://www.codefumes.com/p/#{public_key}</short_uri>\n <community_uri>http://www.codefumes.com/community/projects/#{public_key}</community_uri>\n <api-uri>http://www.codefumes.com/api/v1/xml/projects/#{public_key}.xml</api-uri>\n <name>original_name</name>\n</project>\n")
19
-
20
- end
21
-
22
-
23
3
  describe "Project" do
4
+ include CodeFumesServiceHelpers::Project
5
+
24
6
  before(:each) do
7
+ setup_fixture_base
25
8
  end
26
-
9
+
27
10
  after(:all) do
28
11
  FakeWeb.allow_net_connect = false
29
12
  FakeWeb.clean_registry
@@ -33,7 +16,7 @@ describe "Project" do
33
16
  context "with valid parameters" do
34
17
  context "when the public key has not been taken yet (or no key provided)" do
35
18
  before(:each) do
36
- register_create_uri
19
+ register_no_param_create_uri
37
20
  end
38
21
 
39
22
  [ :public_key,
@@ -44,30 +27,31 @@ describe "Project" do
44
27
  it "sets the '#{method_name.to_s}'" do
45
28
  project = CodeFumes::Project.new
46
29
  project.send(method_name).should be_nil
47
- #project.save
48
- #project.send(method_name).should_not be_nil
30
+ project.save
31
+ project.send(method_name).should_not be_nil
49
32
  end
50
33
  end
51
34
  end
52
35
 
53
36
  context "when the public key has already been taken" do
54
-
55
37
  context "when response is success" do
56
38
  before(:each) do
57
- @updated_name = "different_name"
58
- @project = CodeFumes::Project.new(:public_key => "existing_public_key", :private_key => 'private_key_value', :name => @updated_name)
59
- register_show_uri(@project.public_key, @updated_name)
60
- register_update_uri(@project.public_key, @updated_name)
39
+ @project.name = @updated_name
40
+ register_show_uri
41
+ register_update_uri
61
42
  @project.stub!(:exists?).and_return(true)
62
43
  @project.save.should be_true
63
44
  end
64
-
45
+
65
46
  it "sets basic auth with the public and private key" do
66
47
  Project.should_receive(:put).with("/projects/#{@project.public_key}", :query => {:project => {:name => @updated_name}}, :basic_auth => {:username => @project.public_key, :password => @project.private_key}).and_return(mock("response", :code => 401))
67
48
  @project.save
68
49
  end
69
-
50
+
70
51
  it "updates the value of 'name' for the project associated with the supplied public key" do
52
+ # This seems like a pointless assertion, since it's being set in the before block, but it
53
+ # wouldn't be true if request was not successful, as #name is updated w/ the content
54
+ # returned in the response
71
55
  @project.name.should == @updated_name
72
56
  end
73
57
 
@@ -82,43 +66,41 @@ describe "Project" do
82
66
  end
83
67
  end
84
68
  end
69
+
85
70
  context "respons is Unauthorized" do
86
71
  before(:each) do
87
72
  @updated_name = "different_name"
88
- @project = CodeFumes::Project.new(:public_key => "existing_public_key", :private_key => 'bad_key', :name => @updated_name)
89
- FakeWeb.register_uri(:put, "http://www.codefumes.com/api/v1/xml/projects/existing_public_key?project[name]=#{@project.name}",
73
+ @project = CodeFumes::Project.new(:public_key => 'existing_public_key', :private_key => 'bad_key', :name => @updated_name)
74
+ FakeWeb.register_uri(:put, "http://#{@project.public_key}:#{@project.private_key}@codefumes.com/api/v1/xml/projects/existing_public_key?project[name]=#{@project.name}",
90
75
  :status => ["401", "Unauthorized"])
91
76
  @project.stub!(:exists?).and_return(true)
92
77
  end
93
78
  it "returns false" do
94
79
  @project.save.should be_false
95
- end
80
+ end
96
81
  end
97
82
  end
98
83
  end
99
84
 
100
85
  context "with invalid parameters" do
101
86
  before(:each) do
102
- FakeWeb.register_uri( :post, "http://www.codefumes.com/api/v1/xml/projects?project[public_key]=&project[name]=",
103
- :status => ["422", "Unprocessable Entity"])
87
+ register_show_uri(["404", "Not found"], "")
88
+ register_no_param_create_uri(["422", "Unprocessable Entity"], "")
104
89
  end
105
90
 
106
- [:private_key].each do |method_name|
107
- it "does not set the '#{method_name.to_s}'" do
108
- project = CodeFumes::Project.new
109
- project.save.should be_false
110
- project.send(method_name).should be_nil
111
- end
91
+ it "does not set the 'private_key'" do
92
+ project = Project.new
93
+ project.save.should be_false
94
+ project.private_key.should be_nil
112
95
  end
113
96
  end
114
97
  end
115
98
 
116
99
  context "delete" do
117
100
  before(:each) do
118
- @project = Project.new(:public_key => 'public_key_value', :private_key => 'private_key_value')
119
- FakeWeb.register_uri( :delete, "http://www.codefumes.com/api/v1/xml/projects/#{@project.public_key}",
101
+ FakeWeb.register_uri( :delete, @authd_project_api_uri,
120
102
  :status => ["200", "Successful"],
121
- :string => "")
103
+ :body => "")
122
104
  end
123
105
 
124
106
  it "sets basic auth with the public and private key" do
@@ -133,33 +115,18 @@ describe "Project" do
133
115
  end
134
116
 
135
117
  context "with Unauthorized response" do
136
- before(:each) do
137
- @project = Project.new(:public_key => 'public_key_value')
138
- FakeWeb.register_uri( :delete, "http://www.codefumes.com/api/v1/xml/projects/#{@project.public_key}",
139
- :status => ["401", "Unauthorized"],
140
- :string => "")
141
- end
142
-
143
118
  it "returns false when invalid Unauthorized response is received" do
119
+ register_delete_uri(["401", "Unauthorized"], "")
144
120
  @project.delete.should be_false
145
121
  end
146
122
  end
147
123
  end
148
124
 
149
125
  describe "exists?" do
150
- before(:each) do
151
- @public_key = "some_public_key"
152
- end
153
-
154
126
  context "when the specified public_key has been reserved already" do
155
- before(:each) do
156
- FakeWeb.register_uri(:get, "http://www.codefumes.com/api/v1/xml/projects/#{@public_key}",
157
- :status => ["200", "Ok"],
158
- :string => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n <access-secret nil=\"true\"></access-secret>\n <created-at type=\"datetime\">2009-04-29T23:18:03Z</created-at>\n <public-key>foofoolerue</public-key>\n <private-key>foobarbaz</private-key>\n <updated-at type=\"datetime\">2009-04-29T23:18:03Z</updated-at>\n <short_uri>http://www.codefumes.com/p/foofoolerue</short_uri>\n <community_uri>http://www.codefumes.com/community/projects/1</community_uri>\n <api-uri>http://www.codefumes.com/api/v1/xml/projects/1.xml</api-uri>\n <name>original_name</name>\n")
159
- end
160
-
161
127
  it "returns true" do
162
- Project.new(:public_key => @public_key).exists?.should be_true
128
+ register_show_uri
129
+ Project.new(:public_key => @pub_key).exists?.should be_true
163
130
  end
164
131
  end
165
132
 
@@ -175,25 +142,19 @@ describe "Project" do
175
142
 
176
143
  context "when the specified public_key is available" do
177
144
  before(:each) do
178
- FakeWeb.register_uri(:get, "http://www.codefumes.com/api/v1/xml/projects/#{@public_key}",
179
- :status => ["404", "Not Found"],
180
- :string => "")
181
-
145
+ register_show_uri(["404", "Not Found"], "")
182
146
  end
183
147
 
184
148
  it "returns false" do
185
- Project.new(:public_key => @public_key).exists?.should be_false
149
+ Project.new(:public_key => @pub_key).exists?.should be_false
186
150
  end
187
151
  end
188
152
  end
189
153
 
190
154
  describe "to_config" do
191
155
  before(:each) do
156
+ register_show_uri(["404", "Not Found"], "")
192
157
  register_create_uri
193
- FakeWeb.register_uri( :post, "http://www.codefumes.com:80/api/v1/xml/projects?project[name]=&project[public_key]=",
194
- :status => ["201", "Created"],
195
- :string => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n <access-secret nil=\"true\"></access-secret>\n <created-at type=\"datetime\">2009-04-29T23:18:03Z</created-at>\n <public-key>foofoolerue</public-key>\n <private-key>foobarbaz</private-key>\n <updated-at type=\"datetime\">2009-04-29T23:18:03Z</updated-at>\n <short_uri>http://www.codefumes.com/p/foofoolerue</short_uri>\n <community_uri>http://www.codefumes.com/community/projects/1</community_uri>\n <api-uri>http://www.codefumes.com/api/v1/xml/projects/1.xml</api-uri>\n</project>")
196
- @project = Project.new
197
158
  @project.save
198
159
  end
199
160
 
@@ -209,7 +170,7 @@ describe "Project" do
209
170
  end
210
171
  end
211
172
  end
212
-
173
+
213
174
  it "doesn't include the private_key in the hash if it is nil" do
214
175
  public_key = "key_to_happiness"
215
176
  Project.new(:public_key => public_key).to_config[public_key.to_sym].should_not have_key(:private_key)
@@ -259,32 +220,27 @@ describe "Project" do
259
220
  describe "calling the class method" do
260
221
  describe "'find'" do
261
222
  context "and specifying a public_key which is already associated to a project on the site" do
262
- before(:each) do
263
- @public_key = "an_existing_public_key"
264
- register_show_uri(@public_key)
265
- end
266
-
267
223
  it "returns an initialized instance of the Project class" do
224
+ register_show_uri
268
225
  expected_config = {
269
- :an_existing_public_key =>
226
+ @pub_key.to_sym =>
270
227
  {
271
228
  :private_key=>"private_key_value",
272
- :api_uri=>"http://www.codefumes.com/api/v1/xml/projects/an_existing_public_key.xml",
273
- :short_uri=>"http://www.codefumes.com/p/an_existing_public_key"
229
+ :api_uri=>"http://codefumes.com/api/v1/xml/projects/#{@pub_key}.xml",
230
+ :short_uri=>"http://codefumes.com/p/#{@pub_key}"
274
231
  }
275
232
  }
276
- Project.find(@public_key).to_config.should == expected_config
233
+ Project.find(@pub_key).to_config.should == expected_config
277
234
  end
278
235
  end
279
236
 
280
237
  context "and specifying a public_key which is not associated to any project on the site yet" do
281
238
  before(:each) do
282
- @public_key = "non_existant_public_key"
283
- register_show_uri(@public_key, "Some Name", ["404", "Not Found"])
239
+ register_show_uri(["404", "Not Found"], "")
284
240
  end
285
241
 
286
242
  it "returns nil" do
287
- Project.find(@public_key).should == nil
243
+ Project.find(@pub_key).should == nil
288
244
  end
289
245
  end
290
246
  end