зеркало из
1
0
Форкнуть 0

fix JSON/hashrocket syntax, named groups in regexes, Index/KeyError, include backports, json as rubygem

This commit is contained in:
Troy Howard 2012-09-27 12:59:18 -07:00
Родитель da17bf64bf
Коммит b785d386bd
32 изменённых файлов: 100 добавлений и 97 удалений

Просмотреть файл

@ -98,4 +98,4 @@ end
task :test => ["test:unit", "test:integration"]
task default: :test
task :default => :test

Просмотреть файл

@ -28,11 +28,13 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.8.7'
s.add_runtime_dependency "backports"
s.add_runtime_dependency("nokogiri", "~> 1.5")
s.add_runtime_dependency("mime-types", "~> 1.0")
s.add_runtime_dependency "libxml-ruby"
s.add_runtime_dependency "extlib_lite"
s.add_runtime_dependency "json"
s.add_development_dependency("rake")
s.add_development_dependency("minitest", "~> 3.0")
s.add_development_dependency("yard")

Просмотреть файл

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "backports"
require "azure/tables"
require "azure/blobs"
require "azure/queues"

Просмотреть файл

@ -187,7 +187,7 @@ module Azure
# Returns a Hash with the extracted metadata
def extract_metadata(hash)
new_metadata = hash.each_with_object({}) do |(k,v), hash|
if key = k[/^x-ms-meta-(?<key>.*)?/, :key]
if key = k[/^x-ms-meta-(.*)/, 1]
hash[key] = v
end
end

Просмотреть файл

@ -169,7 +169,7 @@ module Azure
# TODO: Refactor this (DRY)
def extract_metadata(hash)
new_metadata = hash.each_with_object({}) do |(k,v), hash|
if key = k[/^x-ms-meta-(?<key>.*)?/, :key]
if key = k[/^x-ms-meta-(.*)/, 1]
hash[key] = v
end
end

Просмотреть файл

@ -233,7 +233,7 @@ module Azure
#
# Returns a Azure::Core::HttpResponse
def call(container_name)
uri = Blobs::URI.container(container_name, comp: "list", include: "metadata")
uri = Blobs::URI.container(container_name, :comp => "list", :include => "metadata")
super(:get, uri)
end
end

Просмотреть файл

@ -86,7 +86,7 @@ module Azure
#
# Returns a Nokogiri::XML::Node.
def as_xml(xml=Nokogiri::XML::Builder.new)
as_xml = ->(obj, parent) do
as_xml = lambda do |obj, parent|
if obj.respond_to?(:as_xml)
obj.as_xml(parent)
else

Просмотреть файл

@ -37,7 +37,7 @@ module Azure
method.to_s.upcase,
headers.fetch("Content-MD5", ""),
headers.fetch("Content-Type", ""),
headers.fetch("Date") { raise KeyError, "Headers must include Date" },
headers.fetch("Date") { raise IndexError, "Headers must include Date" },
canonicalized_headers(uri).join("\n"),
canonicalized_resource(uri).join("\n")
].join("\n")

Просмотреть файл

@ -96,7 +96,7 @@ module Azure
# Returns an instance of the model.
# Raises ArgumentError if the model isn't found and no block is given.
def fetch(*ids, &block)
block ||= -> { raise ArgumentError, "can't find #{@model_class} identified by #{id.inspect}" }
block ||= lambda { raise ArgumentError, "can't find #{@model_class} identified by #{id.inspect}" }
model = @service.fetch(@parent, *ids)
model.valid? ? model : block.call(model.error)
end

Просмотреть файл

@ -55,23 +55,18 @@ module Azure
#
# Returns an Interval.
def self.parse(string)
re = /
P (?<d>[\d]+D)? # match days
(?:
T (?<h>[\d]+H)? # match hours
(?<m>[\d]+M)? # match minutes
(?<s>[\d\.]+S)? # match seconds
)?
/x
re = /P([\d\.\,]+Y)?([\d\.\,]+M)?([\d\.\,]+D)?(?:T([\d\.\,]+H)?([\d\.\,]+M)?([\d\.\,]+S)?)?/
match = re.match(string)
return nil if match.nil?
days = match[:d].to_i
hours = match[:h].to_i
minutes = match[:m].to_i
seconds = match[:s].to_f
#years = match[1].to_f
#months = match[2].to_f
days = match[3].to_f
hours = match[4].to_f
minutes = match[5].to_f
seconds = match[6].to_f
new(seconds + minutes * 60 + hours * 3600 + days * 86400)
end
@ -86,13 +81,13 @@ module Azure
seconds = (self % 60)
days = "%<d>s" % {
d: days.zero? ? nil : "#{days}D"
:d => days.zero? ? nil : "#{days}D"
}
time = "%<h>s%<m>s%<s>s" % {
h: hours.zero? ? nil : "#{hours}H",
m: minutes.zero? ? nil : "#{minutes}M",
s: nonzero? && seconds.zero? ? nil : "#{seconds}S"
:h => hours.zero? ? nil : "#{hours}H",
:m => minutes.zero? ? nil : "#{minutes}M",
:s => nonzero? && seconds.zero? ? nil : "#{seconds}S"
}
"P#{days}" + (time.empty? ? "" : "T#{time}")

Просмотреть файл

@ -87,8 +87,8 @@ module Azure
message = Message(message)
@service.put_message(self, message, {
visibilitytimeout: message.visibility_timeout,
messagettl: message.ttl
:visibilitytimeout => message.visibility_timeout,
:messagettl => message.ttl
})
self
@ -140,7 +140,7 @@ module Azure
#
# Returns an Array of Messages.
def look_at(num)
@service.peek_messages(self, numofmessages: num)
@service.peek_messages(self, :numofmessages => num)
end
# Public: Remove all messages from the queue.
@ -182,7 +182,7 @@ module Azure
# Returns a Hash with the extracted metadata.
def extract_metadata(hash)
new_metadata = hash.each_with_object({}) do |(k,v), hash|
if key = k[/^x-ms-meta-(?<key>.*)?/, :key]
if key = k[/^x-ms-meta-(.*)/, 1]
hash[key] = v
end
end

Просмотреть файл

@ -127,7 +127,7 @@ module Azure
#
# Returns a Azure::Core::HttpResponse.
def call(name)
uri = Queues::URI.queue(name, comp: "metadata")
uri = Queues::URI.queue(name, :comp=> "metadata")
super(:head, uri)
end
end
@ -141,7 +141,7 @@ module Azure
#
# Returns a Azure::Core::HttpResponse.
def call(name, metadata)
uri = Queues::URI.queue(name, comp: "metadata")
uri = Queues::URI.queue(name, :comp=> "metadata")
super(:put, uri) do |request|
metadata.each do |name, value|
@ -211,7 +211,7 @@ module Azure
#
# Returns a Azure::Core::HttpResponse.
def call(queue_name, options={})
options.update(peekonly: 'true')
options.update(:peekonly => 'true')
uri = Queues::URI.messages(queue_name, options)
super(:get, uri)
end
@ -228,7 +228,7 @@ module Azure
# Returns a Azure::Core::HttpResponse.
def call(queue_name, message_id, pop_receipt)
uri = Queues::URI.message(
queue_name, message_id, popreceipt: pop_receipt
queue_name, message_id, :popreceipt => pop_receipt
)
super(:delete, uri)
end
@ -260,7 +260,7 @@ module Azure
# Returns a Azure::Core::HttpResponse.
def call(queue_name, message_id, text, timeout, pop_receipt)
uri = Queues::URI.message(queue_name, message_id, {
popreceipt: pop_receipt, visibilitytimeout: timeout
:popreceipt=> pop_receipt, :visibilitytimeout=> timeout
})
body = Nokogiri::XML::Builder.new do |xml|

Просмотреть файл

@ -11,7 +11,7 @@ module Azure
#
# Returns a URI.
def self.service_properties(query={}, host=Azure.config.queue_host)
query.update(restype: 'service', comp: 'properties')
query.update(:restype=> 'service', :comp=> 'properties')
generate(host, "", query)
end
@ -22,7 +22,7 @@ module Azure
#
# Returns a URI.
def self.collection(query={}, host=Azure.config.queue_host)
query.update(comp: 'list', include: 'metadata')
query.update(:comp=> 'list', :include=> 'metadata')
generate(host, "", query)
end

Просмотреть файл

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "rubygems"
require "json"
require "time"
require "uri"

Просмотреть файл

@ -23,11 +23,11 @@ module Azure
# See http://msdn.microsoft.com/en-us/library/windowsazure/hh780763
class SubscriptionSerializer
MAPPINGS = {
LockDuration: :lock_duration,
RequiresSession: :requires_session,
DefaultMessageTimeToLive: :default_ttl,
DeadLetteringOnMessageExpiration: :keep_expired,
DeadLetteringOnFilterEvaluationExceptions: :keep_on_errors
:LockDuration=> :lock_duration,
:RequiresSession=> :requires_session,
:DefaultMessageTimeToLive=> :default_ttl,
:DeadLetteringOnMessageExpiration=> :keep_expired,
:DeadLetteringOnFilterEvaluationExceptions=> :keep_on_errors
}.freeze
# Public: Parse an AtomPub fragment and return a Subscription
@ -69,8 +69,8 @@ module Azure
#
# Returns a String
def to_xml(xml=Nokogiri::XML::Builder.new)
xml.entry(xmlns: "http://www.w3.org/2005/Atom") do |xml|
xml.content(type: "application/xml") do |xml|
xml.entry(:xmlns=> "http://www.w3.org/2005/Atom") do |xml|
xml.content(:type=> "application/xml") do |xml|
xml.SubscriptionDescription("xmlns" => "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") do |xml|
MAPPINGS.each do |tag, method|
property = @subscription.send(method)

Просмотреть файл

@ -191,7 +191,7 @@ module Azure
#
# Returns an Entity, or nil if none is found.
def self.query_entity(table, partition_key, row_key, query={}, service=Azure::Tables::Services::QueryEntities.new)
query.update(partition_key: partition_key, row_key: row_key)
query.update(:partition_key=> partition_key, :row_key=> row_key)
response = service.call(table.name, query)
if response.success?

Просмотреть файл

@ -86,7 +86,7 @@ module Azure
# Returns a Table.
# Raises ArgumentError if the table isn't found and no block is given.
def self.fetch(name, service=Azure::Tables, &block)
block ||= -> { raise ArgumentError, "Can't find Table named '#{name}'" }
block ||= lambda { raise ArgumentError, "Can't find Table named '#{name}'" }
table = service.fetch(name)
table.valid? ? table : block.call(table.error)
end

Просмотреть файл

@ -29,8 +29,8 @@ describe "Listing blobs" do
end
it "returns a list of blobs if one or more exist" do
blob_1 = create_block_blob(container: container, name: "blob_1.jpg")
blob_2 = create_block_blob(container: container, name: "blob_2.jpg")
blob_1 = create_block_blob(:container=> container, :name=> "blob_1.jpg")
blob_2 = create_block_blob(:container=> container, :name=> "blob_2.jpg")
blobs = container.blobs
blobs.must_include(blob_1)

Просмотреть файл

@ -43,7 +43,7 @@ describe "Get Messages" do
it "can reset the visibilitytimeout option for retrieved messages" do
@queue << "message 1"
message = @queue.pop(visibilitytimeout: 10)
message = @queue.pop(:visibilitytimeout=> 10)
next_visible_at = message.time_next_visible.to_i
inserted_at = message.insertion_time.to_i

Просмотреть файл

@ -47,11 +47,11 @@ describe "Update Messages" do
end
it "can't update an invisible message" do
message = @queue.pop(visibilitytimeout: 1)
message = @queue.pop(:visibilitytimeout=> 1)
# Pop the message again, and this time make it invisible for a long period
sleep 1
@queue.pop(visibilitytimeout: 100)
@queue.pop(:visibilitytimeout=> 100)
message.visibility_timeout = 10
response = message.update!

Просмотреть файл

@ -47,8 +47,8 @@ describe "Query Entities" do
@table.insert(@entity)
entity = @table.entities(
partition_key: @entity["PartitionKey"],
row_key: @entity["RowKey"]
:partition_key=> @entity["PartitionKey"],
:row_key=> @entity["RowKey"]
)
entity.must_equal @entity
@ -56,8 +56,8 @@ describe "Query Entities" do
it "returns nil if a specific entity is not in the table" do
entity = @table.entities(
partition_key: "not_there",
row_key: "not_there"
:partition_key=> "not_there",
:row_key=> "not_there"
)
entity.must_be_nil
@ -69,9 +69,9 @@ describe "Query Entities" do
@table.insert(@entity)
entity = @table.entities(
partition_key: "part1",
row_key: "row1",
select: ["FirstName", "Email"]
:partition_key=> "part1",
:row_key=> "row1",
:select=> ["FirstName", "Email"]
)
entity.wont_be_nil

Просмотреть файл

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "backports"
require "minitest/autorun"
# Attempt to load purdytest to show colorized test results

Просмотреть файл

@ -23,11 +23,11 @@ describe Azure::Blobs::SharedAccessSignature do
end
let :from do
double(iso8601: "from")
double(:iso8601=> "from")
end
let :to do
double(iso8601: "to")
double(:iso8601=> "to")
end
let :resource do

Просмотреть файл

@ -22,7 +22,7 @@ describe Azure::Blobs do
describe ".containers" do
let :successful_response do
double(success?: true, body: Fixtures[:all_containers])
double(:success? => true, :body=> Fixtures[:all_containers])
end
it "returns a list of Containers on a successful call" do
@ -35,11 +35,11 @@ describe Azure::Blobs do
describe ".create_container" do
let :successful_response do
double(success?: true)
double(:success? => true)
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "returns a valid container when successful" do
@ -62,11 +62,11 @@ describe Azure::Blobs do
describe ".delete_container" do
let :successful_response do
double(success?: true)
double(:success? => true)
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
let :container do
@ -94,11 +94,11 @@ describe Azure::Blobs do
describe ".load_container_metadata" do
let :successful_response do
double(success?: true, headers: headers)
double(:success? => true, :headers=> headers)
end
let :failed_response do
double(success?: false, headers: headers, error: Object.new)
double(:success? => false, :headers=> headers, :error=> Object.new)
end
let :headers do
@ -140,11 +140,11 @@ describe Azure::Blobs do
describe ".save_container_metadata" do
let :successful_response do
double(success?: true)
double(:success? => true)
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
let :container do

Просмотреть файл

@ -17,7 +17,7 @@ require "azure/core/auth/authorizer"
describe Azure::Core::Auth do
before do
uri = double(path: "/path")
uri = double(:path=> "/path")
@signer = MiniTest::Mock.new
@signer.stub(:name, "SharedKey")

Просмотреть файл

@ -17,7 +17,7 @@ require "azure/core/error"
describe Azure::Core::HTTPError do
let :http_response do
double(body: Fixtures[:error], status_code: 409)
double(:body=> Fixtures[:error], :status_code=> 409)
end
subject do

Просмотреть файл

@ -18,7 +18,7 @@ require "azure/service_bus/auth/wrap"
describe Azure::ServiceBus::Auth::Authorizer do
before do
uri = double(path: "/path")
uri = double(:path=> "/path")
@access_token = "THEACCESSTOKEN"

Просмотреть файл

@ -24,7 +24,7 @@ describe Azure::Tables::Auth::SharedKeyLite do
end
it "#signable_string includes the relevant bits" do
string = subject.signable_string(:get, double(path: "/path"), {
string = subject.signable_string(:get, double(:path=> "/path"), {
"Date" => "Time"
})
@ -32,9 +32,11 @@ describe Azure::Tables::Auth::SharedKeyLite do
end
it "#signable_string requires a Date or x-ms-date header" do
error_type = RUBY_VERSION > "1.9" ? KeyError : IndexError
proc {
subject.signable_string(:get, double(path: "/path"), {})
}.must_raise KeyError, "Headers must include Date"
subject.signable_string(:get, double(:path => "/path"), {})
}.must_raise error_type, "Headers must include Date"
end
it "#sign will return a Base64-encoded, HMAC/SHA256-encrypted version of the signable string" do

Просмотреть файл

@ -25,7 +25,7 @@ describe Azure::Tables::Auth::SharedKey do
end
it "#signable_string includes the relevant bits" do
string = subject.signable_string(:get, double(path: "/path"), {
string = subject.signable_string(:get, double(:path => "/path"), {
"Content-MD5" => "Foo",
"Content-Type" => "text/plain",
"Date" => "Time"
@ -35,12 +35,13 @@ describe Azure::Tables::Auth::SharedKey do
end
it "#signable_string requires a Date or x-ms-date header" do
error_type = RUBY_VERSION > "1.9" ? KeyError : IndexError
proc {
subject.signable_string(:get, double(path: "/path"), {
subject.signable_string(:get, double(:path=> "/path"), {
"Content-MD5" => "Foo",
"Content-Type" => "text/plain"
})
}.must_raise KeyError, "Headers must include Date"
}.must_raise error_type, "Headers must include Date"
end
it "#sign will return a Base64-encoded, HMAC/SHA256-encrypted version of the signable string" do

Просмотреть файл

@ -58,7 +58,7 @@ describe Azure::Tables::Table do
it "can query for a specific entity" do
table, service = table("mytable")
service.expect(:query_entity, nil, [table, "Foo", "Bar", {}])
table.entities(partition_key: "Foo", row_key: "Bar").must_be_nil
table.entities(:partition_key=> "Foo", :row_key=> "Bar").must_be_nil
service.verify
end

Просмотреть файл

@ -38,8 +38,8 @@ describe Azure::Tables::Types do
returns_type_for "Edm.String", "test"
returns_type_for "Edm.DateTime", Time.now
returns_type_for "Edm.DateTime", Time.now.to_date
returns_type_for "Edm.DateTime", Time.now.to_datetime
returns_type_for "Edm.DateTime", Date.new
returns_type_for "Edm.DateTime", DateTime.now #Time.now.to_datetime
returns_type_for "Edm.Boolean", true
returns_type_for "Edm.Boolean", false

Просмотреть файл

@ -38,7 +38,7 @@ describe Azure::Tables do
describe ".all" do
let :successful_response do
StubResponse.new(success: true, body: Fixtures[:all_tables])
StubResponse.new(:success => true, :body=> Fixtures[:all_tables])
end
it "returns a list of Tables on a successful call" do
@ -51,11 +51,11 @@ describe Azure::Tables do
describe ".create" do
let :successful_response do
double(success?: true, body: Fixtures[:create_table_response_entry])
double(:success? => true, :body=> Fixtures[:create_table_response_entry])
end
let :failed_response do
double(success?: false, body: Fixtures[:error], error: Object.new)
double(:success? => false, :body=> Fixtures[:error], :error=> Object.new)
end
it "returns a valid table when successful" do
@ -76,11 +76,11 @@ describe Azure::Tables do
describe ".delete" do
let :successful_response do
double(success?: true)
double(:success? => true)
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "returns true when successful" do
@ -104,11 +104,11 @@ describe Azure::Tables do
describe ".insert_entity" do
let :successful_response do
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry], etag: "Foo")
StubResponse.new(:success => true, :body=> Fixtures[:insert_entity_response_entry], :etag=> "Foo")
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "returns the entity when successful" do
@ -136,11 +136,11 @@ describe Azure::Tables do
describe ".update_entity" do
let :successful_response do
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry], etag: "Foo")
StubResponse.new(:success => true, :body=> Fixtures[:insert_entity_response_entry], :etag=> "Foo")
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "replaces the entity's attributes if successful" do
@ -171,11 +171,11 @@ describe Azure::Tables do
describe ".merge_entity" do
let :successful_response do
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry], etag: "Foo")
StubResponse.new(:success => true, :body=> Fixtures[:insert_entity_response_entry], :etag=> "Foo")
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "updates the entity's attributes if successful" do
@ -208,11 +208,11 @@ describe Azure::Tables do
describe ".delete_entity" do
let :successful_response do
StubResponse.new(success: true, etag: "Foo")
StubResponse.new(:success => true, :etag=> "Foo")
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "freezes the entity if successful" do
@ -241,15 +241,15 @@ describe Azure::Tables do
describe ".query_entities" do
let :successful_response do
StubResponse.new(success: true, body: Fixtures[:query_entities_response])
StubResponse.new(:success => true, :body=> Fixtures[:query_entities_response])
end
let :empty_response do
StubResponse.new(success: true, body: Fixtures[:query_entities_empty_response])
StubResponse.new(:success => true, :body=> Fixtures[:query_entities_empty_response])
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "returns a list of entities when successful" do
@ -286,11 +286,11 @@ describe Azure::Tables do
describe ".query_entity" do
let :successful_response do
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry])
StubResponse.new(:success => true, :body=> Fixtures[:insert_entity_response_entry])
end
let :failed_response do
double(success?: false, error: Object.new)
double(:success? => false, :error=> Object.new)
end
it "returns the matching entity when it's successful" do