-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ monster commit (sry): moved to specs, added a wrapping pure ruby
class to handle charset issues, more specs, ...
- Loading branch information
Showing
14 changed files
with
311 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
$LOAD_PATH << File.expand_path(File.dirname(__FILE__)) | |||
require 'shout_ext' | |||
require 'shout/string_extension_rb_18' | |||
|
|||
class Shout | |||
attr_accessor :charset | |||
|
|||
INT_ACCESSORS = :port, :format | |||
STRING_ACCESSORS = :host, :user, :username, :pass, :password, :protocol, :mount, :dumpfile, | |||
:agent, :user_agent, :public, :name, :url, :genre, :description | |||
|
|||
STRING_ACCESSORS.each do |accessor| | |||
attr_accessor :"original_#{accessor}" | |||
|
|||
alias :"raw_#{accessor}" :"#{accessor}" | |||
define_method accessor do | |||
return nil unless orig_acc = self.__send__("original_#{accessor}") | |||
|
|||
decode self.__send__(:"raw_#{accessor}"), orig_acc.encoding.name | |||
end | |||
|
|||
alias :"raw_#{accessor}=" :"#{accessor}=" | |||
define_method :"#{accessor}=" do |value| | |||
self.__send__ "original_#{accessor}=", value | |||
|
|||
self.__send__ :"raw_#{accessor}=", encode(value) | |||
end | |||
end | |||
|
|||
alias :ext_initialize :initialize | |||
def initialize(opts={}) | |||
ext_initialize | |||
|
|||
self.charset = opts[:charset] || 'ISO-8859-1' | |||
|
|||
accessors = STRING_ACCESSORS + INT_ACCESSORS + [:charset] | |||
a_opts = opts.select{ |k,v| accessors.include? k } | |||
|
|||
a_opts.each{ |k,v| self.__send__ :"#{k}=", v } | |||
end | |||
|
|||
private | |||
def encode(s) | |||
s.encode(charset, :invalid => :replace, :undef => :replace, :replace => '') | |||
end | |||
def decode(s, orig_charset) | |||
s.encode(orig_charset, charset, :invalid => :replace, :undef => :replace, :replace => '') | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
class String | |||
|
|||
def encode(*) | |||
self | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
# -*- encoding : utf-8 -*- | |||
|
|||
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') | |||
|
|||
describe "Accessors" do | |||
before(:each) do | |||
@shout = Shout.new | |||
@description = 'çaffé düdeldø' | |||
@genre = 'foobar'.encode('ISO-8859-1') | |||
@shout.genre = @genre | |||
@shout.description = @description | |||
end | |||
it "should not change the original encoding" do | |||
@shout.description.encoding.should == @description.encoding | |||
@shout.genre.encoding.should == @genre.encoding | |||
end | |||
describe "#original_..." do | |||
it "should store the original value" do | |||
@shout.original_description.should == @description | |||
@shout.original_genre.should == @genre | |||
end | |||
end | |||
end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
require 'spec' | |||
|
|||
BASE_DIR = File.expand_path File.join(File.dirname(__FILE__), '..') | |||
VERSION = File.open(File.join(BASE_DIR, 'VERSION')).readline.strip | |||
|
|||
describe "Build process" do | |||
def remove_pkg | |||
command = %Q{ | |||
cd #{BASE_DIR} | |||
rm -rf pkg | |||
} | |||
c = `#{command}` | |||
puts c | |||
return c | |||
end | |||
|
|||
def clean_test_gem | |||
command = %Q{ | |||
cd #{BASE_DIR} | |||
rm -rf spec/test_gem_installation | |||
} | |||
c = `#{command}` | |||
puts c | |||
return c | |||
end | |||
|
|||
def install_gem | |||
command = %Q{ | |||
cd #{BASE_DIR} | |||
rake build | |||
gem install --no-test --no-rdoc --no-ri --install-dir spec/test_gem_installation --bindir spec/test_gem_installation pkg/ruby-shout-#{VERSION}.gem | |||
} | |||
c = `#{command}` | |||
puts c | |||
return c | |||
end | |||
|
|||
it "should build" do | |||
clean_test_gem.should be_true | |||
install_gem.should be_true | |||
remove_pkg.should be_true | |||
end | |||
|
|||
end |
Oops, something went wrong.