Skip to content

Commit

Permalink
fixes to test
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Jul 22, 2008
1 parent 5d6ce5e commit c99069b
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 33 deletions.
34 changes: 34 additions & 0 deletions MANIFEST.txt
@@ -0,0 +1,34 @@
CHANGELOG
LICENSE
MIT-LICENSE
MANIFEST.txt
README.txt
Rakefile
generators/sms/USAGE
generators/sms/sms_generator.rb
generators/sms/templates/fixture.rhtml
generators/sms/templates/model.rb
generators/sms/templates/unit_test.rb
init.rb
lib/activesms.rb
lib/activesms/adv_attr_accessor.rb
lib/activesms/base.rb
lib/activesms/connection_adapters/abstract_adapter.rb
lib/activesms/connection_adapters/bulk_sms_adapter.rb
lib/activesms/connection_adapters/clickatell_adapter.rb
lib/activesms/connection_adapters/simplewire_adapter.rb
lib/activesms/connections.rb
lib/activesms/exceptions.rb
lib/activesms/sms.rb
lib/activesms/validations.rb
lib/activesms/version.rb
scripts/txt2html
setup.rb
test/connection_adapters/test_simplewire_adapter.rb
test/test_activesms.rb
test/test_helper.rb
website/index.html
website/index.txt
website/javascripts/rounded_corners_lite.inc.js
website/stylesheets/screen.css
website/template.rhtml
1 change: 0 additions & 1 deletion MANIFESTO

This file was deleted.

2 changes: 1 addition & 1 deletion README → README.txt
@@ -1,6 +1,6 @@
== SMS Brasil

Baseado no ActiveSMS (http://rubyforge.org/projects/activesms/) esse projeto visa manter e adicionar gateways brasileiros.
Baseado no ActiveSMS (http://rubyforge.org/projects/activesms) esse projeto visa facilitar o envio de mensagens SMS para operadoras de telefonia celular do Brasil, utilizando serviços de gateway de envio.

== Gateways suportados

Expand Down
62 changes: 31 additions & 31 deletions Rakefile
Expand Up @@ -80,44 +80,44 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
p.clean_globs |= CLEAN #An array of file patterns to delete on clean.

# == Optional
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
p.changes = p.paragraphs_of("CHANGELOG", 0..1).join("\n\n")
p.extra_deps = [['activesupport', '>=1.3.1'], ['actionpack', '>=1.12.5']] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
end

CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
CHANGES = hoe.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')

desc 'Generate website files'
task :website_generate do
Dir['website/**/*.txt'].each do |txt|
sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
end
end

desc 'Upload website files to rubyforge'
task :website_upload do
host = "#{rubyforge_username}@rubyforge.org"
remote_dir = "/var/www/gforge-projects/#{PATH}/"
local_dir = 'website'
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
end

desc 'Generate and upload website files'
task :website => [:website_generate, :website_upload, :publish_docs]

desc 'Release the website and new gem version'
task :deploy => [:check_version, :website, :release] do
puts "Remember to create SVN tag:"
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
puts "Suggested comment:"
puts "Tagging release #{CHANGES}"
end

desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
task :local_deploy => [:website_generate, :install_gem]
# desc 'Generate website files'
# task :website_generate do
# Dir['website/**/*.txt'].each do |txt|
# sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
# end
# end

# desc 'Upload website files to rubyforge'
# task :website_upload do
# host = "#{rubyforge_username}@rubyforge.org"
# remote_dir = "/var/www/gforge-projects/#{PATH}/"
# local_dir = 'website'
# sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
# end
#
# desc 'Generate and upload website files'
# task :website => [:website_generate, :website_upload, :publish_docs]
#
# desc 'Release the website and new gem version'
# task :deploy => [:check_version, :website, :release] do
# puts "Remember to create SVN tag:"
# puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
# "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
# puts "Suggested comment:"
# puts "Tagging release #{CHANGES}"
# end

# > desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
# > task :local_deploy => [:website_generate, :install_gem]

task :check_version do
unless ENV['VERSION']
Expand Down
67 changes: 67 additions & 0 deletions scripts/txt2html
@@ -0,0 +1,67 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'redcloth'
require 'syntax/convertors/html'
require 'erb'
require File.dirname(__FILE__) + '/../lib/activesms/version.rb'

version = ActiveSms::VERSION::STRING
download = 'http://rubyforge.org/projects/activesms'

class Fixnum
def ordinal
# teens
return 'th' if (10..19).include?(self % 100)
# others
case self % 10
when 1: return 'st'
when 2: return 'nd'
when 3: return 'rd'
else return 'th'
end
end
end

class Time
def pretty
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
end
end

def convert_syntax(syntax, source)
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
end

if ARGV.length >= 1
src, template = ARGV
template ||= File.dirname(__FILE__) + '/../website/template.rhtml'

else
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
exit!
end

template = ERB.new(File.open(template).read)

title = nil
body = nil
File.open(src) do |fsrc|
title_text = fsrc.readline
body_text = fsrc.read
syntax_items = []
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
ident = syntax_items.length
element, syntax, source = $1, $2, $3
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
"syntax-temp-#{ident}"
}
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
body = RedCloth.new(body_text).to_html
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
end
stat = File.stat(src)
created = stat.ctime
modified = stat.mtime

$stdout << template.result(binding)
75 changes: 75 additions & 0 deletions test/connection_adapters/test_simplewire_adapter.rb
@@ -0,0 +1,75 @@
puts "test"

require File.dirname(__FILE__) + "/../test_helper"

# Only run this test if using jruby
if RUBY_PLATFORM =~ /java/
class SimplewireAdapterTest < Test::Unit::TestCase
def setup
@simplewire_adapter = ActiveSms::ConnectionAdapters::SimplewireAdapter.new(nil, {
:subscriber_id => 'id',
:subscriber_password => 'password'})
end

def test_instantiation
assert_raise(RuntimeError) { ActiveSms::ConnectionAdapters::SimplewireAdapter.new(nil, {}) }
assert @simplewire_adapter
end

def test_sms_size
sms = flexmock("sms")
sms.should_receive(:subscriber_id).and_return("id")
sms.should_receive(:subscriber_password).and_return("password")
sms.should_receive(:recipients).and_return("4081234567")
sms.should_receive(:from).and_return("6502435555")
long_body = ""
150.times {long_body += "x"}
sms.should_receive(:body).and_return(long_body)

assert_raise(StandardError) do
s = @simplewire_adapter.create_sms(sms)
end
end

def test_parse_sms
xmldata = create_sms('121212', '6502435555', 'blah blah')
sms = @simplewire_adapter.parse(xmldata)
assert_equal 'blah blah', sms.body
assert_equal '121212', sms.to
assert_equal '6502435555', sms.from
end

def test_create_sms
sms = flexmock("sms")
sms.should_receive(:subscriber_id).and_return("id")
sms.should_receive(:subscriber_password).and_return("password")
sms.should_receive(:recipients).and_return("4081234567")
sms.should_receive(:from).and_return("6502435555")
sms.should_receive(:body).and_return("This is the body of the sms")

s = @simplewire_adapter.create_sms(sms)

assert_equal "id", s.subscriber_id
assert_equal "password", s.subscriber_password
assert_equal "4081234567", s.destination_addr.address
assert_equal "6502435555", s.source_addr.address
assert_equal "This is the body of the sms", s.msg_text
end

protected
def create_sms(to, from, body)
xmldata =<<END
<?xml version="1.0" ?>
<request version="3.0" protocol="wmp" type="deliver">
<account id="123-456-789-12345"/>
<destination ton="3" address="#{to}"/>
<source carrier="348" ton="1" address="#{from}"/>
<option datacoding="7bit" />
<message udhi="true" data="0605040B8423F0#{body.unpack('H*')}"/>
<ticket id="12004-0923R-1845S-10M25"/>
</request>
END
xmldata
end
end
end
7 changes: 7 additions & 0 deletions test/test_activesms.rb
@@ -0,0 +1,7 @@
require 'test/unit'

class ActiveSmsTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
end
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,6 @@
$:.unshift(File.dirname(__FILE__) + "/../lib")

require 'rubygems'
require 'test/unit'
require 'activesms'
require 'flexmock/test_unit'

0 comments on commit c99069b

Please sign in to comment.