trumpet-trumpet 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 3
3
+ :patch: 4
4
4
  :major: 0
@@ -11,11 +11,9 @@ module Trumpet
11
11
  :radius , :channel,
12
12
  :public , :authorized_receiver_owners,
13
13
  :content , :id,
14
- :created_at , :updated_at
14
+ :source
15
15
  ]
16
16
 
17
- #TODO: created_at and updated_at maybe not writable
18
-
19
17
  attr_accessor *@@attributes
20
18
 
21
19
  def initialize(options)
@@ -1,14 +1,19 @@
1
1
  module Trumpet
2
2
  class Resource
3
+ alias :old_inspect :inspect
3
4
 
4
5
  def to_h(excludes=[])
5
6
  excludes << '@credentials'
6
7
  instance_variables.inject({}) do |hash, value|
7
- hash[value.gsub('@', '')] = instance_variable_get(value) unless excludes.include?(value)
8
+ hash[value.gsub('@', '').to_sym] = instance_variable_get(value) unless excludes.include?(value)
8
9
  hash
9
10
  end
10
11
  end
11
12
 
13
+ def inspect
14
+ old_inspect.gsub(/ @credentials=.*\},/, '')
15
+ end
16
+
12
17
  protected
13
18
 
14
19
  def initialize(attributes)
@@ -50,8 +50,4 @@ describe "Listener" do
50
50
  twitter_listener.delivery_method.should == 'Twitter'
51
51
  twitter_listener.delivery_address.should == 'twitterdude'
52
52
  end
53
-
54
- it "should be able to describe it's delivery address" do
55
-
56
- end
57
53
  end
data/spec/request_spec.rb CHANGED
@@ -3,6 +3,9 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Request" do
4
4
 
5
5
  before(:all) do
6
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/fakerequest", :string => ['Unauthorized Fake Request'].to_json
7
+ FakeWeb.register_uri :get, "#{AUTHENTICATED_URI}/fakerequest", :string => ['Authorized Fake Request'].to_json
8
+
6
9
  FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/badrequest", :status => ["400", "Bad Request"], :string => ['Bad Request'].to_json
7
10
  FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/unauthorized", :status => ["401", "Unauthorized"], :string => ['Unauthorized'].to_json
8
11
  FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/forbidden", :status => ["403", "Forbidden"], :string => ['Forbidden'].to_json
@@ -13,6 +16,20 @@ describe "Request" do
13
16
  FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/notimplemented", :status => ["501", "Not Implemented"], :string => ['Not Implemented'].to_json
14
17
  end
15
18
 
19
+ it "should not parse the response if asked not to" do
20
+ response = Trumpet::Request.get('/fakerequest', :parse_response => false)
21
+ response.body.should == "[\"Unauthorized Fake Request\"]"
22
+ end
23
+
24
+ it "should parse the response if no options are passed in" do
25
+ Trumpet::Request.get('/fakerequest').should.to_s == 'Unauthorized Fake Request'
26
+ end
27
+
28
+ it "should attach http_auth credentials to request is given" do
29
+ response = Trumpet::Request.get('/fakerequest', :credentials => {:username => 'somedude', :password => 'somepassword'}, :parse_response => false)
30
+ response.body.should == "[\"Authorized Fake Request\"]"
31
+ end
32
+
16
33
  context "when handling errors" do
17
34
  it "should throw a BadRequest exception when it receives a 400 code" do
18
35
  lambda { Trumpet::Request.get('/badrequest', :parse_response => false) }.should raise_error(Trumpet::BadRequest)
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Resource" do
4
+
5
+ before(:all) do
6
+ @trumpet = Trumpet::Base.new :username => 'somedude', :password => 'somepassword'
7
+
8
+ FakeWeb.register_uri :get, "#{AUTHENTICATED_URI}/channels/radical", :file => "#{File.dirname(__FILE__)}/fixtures/channels/show"
9
+
10
+ @channel_attributes = {
11
+ :receiver_id => 2, :name => "radical",
12
+ :updated_at => nil, :description => nil,
13
+ :owner_id => 1, :transmitter_id => 2,
14
+ :created_at => nil
15
+ }
16
+ end
17
+
18
+ it "should build up attr_readers from all passed in attributes" do
19
+ channel = @trumpet.channels.find 'radical'
20
+
21
+ # Verify that all methods are there and all values are set properly
22
+ @channel_attributes.keys.each do |attribute|
23
+ channel.send(attribute).should == @channel_attributes[attribute]
24
+ end
25
+ end
26
+
27
+ it "should properly convert itself into a hash" do
28
+ channel = @trumpet.channels.find 'radical'
29
+ channel.to_h.should == @channel_attributes
30
+ end
31
+
32
+ it "should exclude credentials from inspect" do
33
+ channel = @trumpet.channels.find 'radical'
34
+ channel.inspect.should_not include('@credentials')
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trumpet-trumpet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Taras
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -07:00
12
+ date: 2009-05-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,7 @@ files:
86
86
  - spec/message_spec.rb
87
87
  - spec/receiver_spec.rb
88
88
  - spec/request_spec.rb
89
+ - spec/resource_spec.rb
89
90
  - spec/spec_helper.rb
90
91
  - spec/transmitter_spec.rb
91
92
  - spec/user_spec.rb
@@ -121,6 +122,7 @@ test_files:
121
122
  - spec/message_spec.rb
122
123
  - spec/receiver_spec.rb
123
124
  - spec/request_spec.rb
125
+ - spec/resource_spec.rb
124
126
  - spec/spec_helper.rb
125
127
  - spec/transmitter_spec.rb
126
128
  - spec/user_spec.rb