Permalink
Browse files

Converting this to a Gem. Requiring Rails 3+ and Ruby 1.9.2+

  • Loading branch information...
1 parent 30a920b commit 2d61110e4bd8df6af6aefb3743f23a239ca11953 @russ committed Jan 25, 2012
View
7 .gitignore
@@ -1,2 +1,5 @@
-coverage
-rdoc
+*.gem
+.bundle
+.DS_Store
+Gemfile.lock
+pkg/*
View
3 Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
View
126 Gemfile.lock
@@ -0,0 +1,126 @@
+PATH
+ remote: .
+ specs:
+ country_code_select (1.0.0)
+ activesupport (>= 3.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
+ mail (~> 2.3.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ builder (3.0.0)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ json (1.6.5)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ metaclass (0.0.1)
+ mime-types (1.17.2)
+ mocha (0.10.3)
+ metaclass (~> 0.0.1)
+ multi_json (1.0.4)
+ nokogiri (1.5.0)
+ polyglot (0.3.3)
+ r3_plugin_toolbox (0.4.1)
+ rails (~> 3.0)
+ require_all (~> 1.2.0)
+ sugar-high (~> 0.3.0)
+ rack (1.3.6)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
+ bundler (~> 1.0)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ require_all (1.2.1)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-action_view (0.3.5)
+ r3_plugin_toolbox (>= 0.4.0)
+ rspec (>= 2.0.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-html-matchers (0.2.3)
+ nokogiri (>= 1.4.4)
+ rspec (>= 2.0.0)
+ rspec-mocks (2.8.0)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sugar-high (0.3.7)
+ mocha (>= 0.9.8)
+ require_all (~> 1.2.0)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ yard (0.7.4)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ country_code_select!
+ rake
+ rspec (~> 2.8)
+ rspec-action_view
+ rspec-html-matchers
+ yard
View
7 README
@@ -2,7 +2,12 @@
A simple country code select helper. Works exactly the same as country_select but uses country codes instead.
- country_code_select(:user, :country, [[ 'US', 'United States' ], [ 'CA', 'Canada' ]])
+ country_code_select(:user, :country, [[ 'United States', 'US' ], [ 'Canada', 'CA' ]])
+
+== Requirements
+
+Rails 3+
+Ruby 1.9.2+
== Copyright/License
View
44 Rakefile
@@ -1,31 +1,15 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-require 'spec/rake/spectask'
-
-desc 'Default: run specs'
-task :default => :spec
-
-spec_files = Rake::FileList["spec/**/*_spec.rb"]
-
-desc "Run specs"
-Spec::Rake::SpecTask.new do |t|
- t.spec_files = spec_files
- t.spec_opts = ["-c"]
-end
-
-desc "Generate code coverage"
-Spec::Rake::SpecTask.new(:coverage) do |t|
- t.spec_files = spec_files
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec,/var/lib/gems']
-end
-
-desc 'Generate documentation for the country_code_select plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'CountryCodeSelect'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
+require "bundler/gem_tasks"
+require "rake"
+require "rspec/core/rake_task"
+
+namespace :spec do
+ RSpec::Core::RakeTask.new(:normal) do |t|
+ t.pattern = "spec/**/*_spec.rb"
+ t.rcov = false
+ end
end
+
+desc "RSpec tests"
+task "spec" => "spec:normal"
+
+task "default" => "spec"
View
24 country_code_select.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "country_code_select/version"
+
+Gem::Specification.new do |s|
+ s.name = "country_code_select"
+ s.version = CountryCodeSelect::VERSION
+ s.authors = ["Russ Smith (russ@bashme.org)"]
+ s.email = "russ@bashme.org"
+ s.homepage = "http://github.com/russ/country_code_select"
+ s.summary = "A simple country code select helper. Works exactly the same as country_select but uses country codes instead."
+ s.description = "A simple country code select helper. Works exactly the same as country_select but uses country codes instead."
+ s.rubyforge_project = "country_code_select"
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+ s.add_dependency("activesupport", ">= 3.0")
+ s.add_development_dependency("rake")
+ s.add_development_dependency("rspec", "~> 2.8")
+ s.add_development_dependency("rspec-html-matchers")
+ s.add_development_dependency("rspec-action_view")
+ s.add_development_dependency("yard")
+end
View
2 init.rb
@@ -1 +1 @@
-require 'country_code_select'
+require File.join(File.dirname(__FILE__), "lib", "country_code_select")
View
8 lib/country_code_select.rb
@@ -1,7 +1,7 @@
-require 'country_code_select/countries'
-require 'country_code_select/form_builder'
-require 'country_code_select/form_helpers'
-require 'country_code_select/instance_tag'
+require "country_code_select/countries"
+require "country_code_select/form_builder"
+require "country_code_select/form_helpers"
+require "country_code_select/instance_tag"
ActionView::Base.send(:include, CountryCodeSelect::FormHelpers)
ActionView::Helpers::InstanceTag.send(:include, CountryCodeSelect::InstanceTag)
View
4 lib/country_code_select/form_builder.rb
@@ -1,7 +1,7 @@
module CountryCodeSelect
module FormBuilder
- def country_code_select(method, priority_countries = nil, options= {})
- @template.country_code_select(@object_name, method, priority_countries, options.merge(:object => @object))
+ def country_code_select(method, priority_countries = nil, options = {})
+ @template.country_code_select(@object_name, method, priority_countries, options.merge(object: @object))
end
end
end
View
8 lib/country_code_select/instance_tag.rb
@@ -10,7 +10,7 @@ def to_country_code_select_tag(priority_countries, options = {})
def country_code_select(priority_countries, options)
selected = object.send(@method_name)
- countries = ''
+ countries = ""
if priority_countries
countries += options_for_select(priority_countries, selected)
countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
@@ -20,11 +20,7 @@ def country_code_select(priority_countries, options)
end
countries = countries + options_for_select(COUNTRIES, selected)
- if Rails::VERSION::STRING.to_f < 3
- content_tag(:select, countries, options.merge(:id => "#{@object_name}_#{@method_name}", :name => "#{@object_name}[#{@method_name}]"))
- else
- content_tag(:select, countries, options.merge(:id => "#{@object_name}_#{@method_name}", :name => "#{@object_name}[#{@method_name}]"), false)
- end
+ content_tag(:select, countries, options.merge(id: "#{@object_name}_#{@method_name}", :name => "#{@object_name}[#{@method_name}]"), false)
end
end
end
View
3 lib/country_code_select/version.rb
@@ -0,0 +1,3 @@
+module CountryCodeSelect
+ VERSION = "1.0.0"
+end
View
4 spec/form_builder_spec.rb
@@ -1,7 +1,7 @@
-require File.dirname(__FILE__) + '/spec_helper'
+require "spec_helper"
describe CountryCodeSelect::FormHelpers do
it "should include country_code_select method" do
- ActionView::Helpers::FormBuilder.instance_methods.should include('country_code_select')
+ ActionView::Helpers::FormBuilder.instance_methods.should include(:country_code_select)
end
end
View
14 spec/form_helpers_spec.rb
@@ -1,26 +1,26 @@
-require File.dirname(__FILE__) + '/spec_helper'
+require "spec_helper"
describe CountryCodeSelect::FormHelpers do
describe "country_code_select" do
include CountryCodeSelect::FormHelpers
before(:each) do
- @user = mock('User', :country => nil)
+ @user = mock("User", :country => nil)
end
it "should output a select field with countries" do
output = country_code_select(:user, :country)
- output.should have_tag('select[id=user_country]')
+ output.should match(/select id="user_country"/)
end
it "should output a select field with priority countries" do
- output = country_code_select(:user, :country, [ 'US', 'United States' ])
- output.should have_tag('option[value=US]')
+ output = country_code_select(:user, :country, [ "US", 'United States' ])
+ output.should match(/option value="US"/)
end
it "should output a select field with passed attributes" do
- output = country_code_select(:user, :country, [ 'US', 'United States' ], :class => 'custom_class')
- output.should have_tag('select[class=custom_class]')
+ output = country_code_select(:user, :country, [ "US", "United States" ], class: "custom_class")
+ output.should match(/select class="custom_class"/)
end
end
end
View
31 spec/rspec-rails/MIT-LICENSE
@@ -1,31 +0,0 @@
-====================================================================
-== RSpec
-Copyright (c) 2005-2007 The RSpec Development Team
-====================================================================
-== ARTS
-Copyright (c) 2006 Kevin Clark, Jake Howerton
-====================================================================
-== ZenTest
-Copyright (c) 2001-2006 Ryan Davis, Eric Hodel, Zen Spider Software
-====================================================================
-== AssertSelect
-Copyright (c) 2006 Assaf Arkin
-====================================================================
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
View
130 spec/rspec-rails/assert_select.rb
@@ -1,130 +0,0 @@
-# This is a wrapper of assert_select for rspec.
-
-module Spec # :nodoc:
- module Rails
- module Matchers
-
- class AssertSelect #:nodoc:
-
- def initialize(assertion, spec_scope, *args, &block)
- @assertion = assertion
- @spec_scope = spec_scope
- @args = args
- @block = block
- end
-
- def matches?(response_or_text, &block)
- if ActionController::TestResponse === response_or_text and
- response_or_text.headers.key?('Content-Type') and
- response_or_text.headers['Content-Type'].to_sym == :xml
- @args.unshift(HTML::Document.new(response_or_text.body, false, true).root)
- elsif String === response_or_text
- @args.unshift(HTML::Document.new(response_or_text).root)
- end
- @block = block if block
- begin
- @spec_scope.send(@assertion, *@args, &@block)
- rescue ::Test::Unit::AssertionFailedError => @error
- end
-
- @error.nil?
- end
-
- def failure_message; @error.message; end
- def negative_failure_message; "should not #{description}, but did"; end
-
- def description
- {
- :assert_select => "have tag#{format_args(*@args)}",
- :assert_select_email => "send email#{format_args(*@args)}",
- }[@assertion]
- end
-
- private
-
- def format_args(*args)
- return "" if args.empty?
- return "(#{arg_list(*args)})"
- end
-
- def arg_list(*args)
- args.collect do |arg|
- arg.respond_to?(:description) ? arg.description : arg.inspect
- end.join(", ")
- end
-
- end
-
- # :call-seq:
- # response.should have_tag(*args, &block)
- # string.should have_tag(*args, &block)
- #
- # wrapper for assert_select with additional support for using
- # css selectors to set expectation on Strings. Use this in
- # helper specs, for example, to set expectations on the results
- # of helper methods.
- #
- # == Examples
- #
- # # in a controller spec
- # response.should have_tag("div", "some text")
- #
- # # in a helper spec (person_address_tag is a method in the helper)
- # person_address_tag.should have_tag("input#person_address")
- #
- # see documentation for assert_select at http://api.rubyonrails.org/
- def have_tag(*args, &block)
- AssertSelect.new(:assert_select, self, *args, &block)
- end
-
- # wrapper for a nested assert_select
- #
- # response.should have_tag("div#form") do
- # with_tag("input#person_name[name=?]", "person[name]")
- # end
- #
- # see documentation for assert_select at http://api.rubyonrails.org/
- def with_tag(*args, &block)
- should have_tag(*args, &block)
- end
-
- # wrapper for a nested assert_select with false
- #
- # response.should have_tag("div#1") do
- # without_tag("span", "some text that shouldn't be there")
- # end
- #
- # see documentation for assert_select at http://api.rubyonrails.org/
- def without_tag(*args, &block)
- should_not have_tag(*args, &block)
- end
-
- # :call-seq:
- # response.should have_rjs(*args, &block)
- #
- # wrapper for assert_select_rjs
- #
- # see documentation for assert_select_rjs at http://api.rubyonrails.org/
- def have_rjs(*args, &block)
- AssertSelect.new(:assert_select_rjs, self, *args, &block)
- end
-
- # :call-seq:
- # response.should send_email(*args, &block)
- #
- # wrapper for assert_select_email
- #
- # see documentation for assert_select_email at http://api.rubyonrails.org/
- def send_email(*args, &block)
- AssertSelect.new(:assert_select_email, self, *args, &block)
- end
-
- # wrapper for assert_select_encoded
- #
- # see documentation for assert_select_encoded at http://api.rubyonrails.org/
- def with_encoded(*args, &block)
- should AssertSelect.new(:assert_select_encoded, self, *args, &block)
- end
- end
- end
-end
View
1 spec/rspec-rails/rspec-rails.rb
@@ -1 +0,0 @@
-require 'rspec-rails/assert_select'
View
6 spec/spec.opts
@@ -1,6 +0,0 @@
---colour
---format
-progress
---loadby
-mtime
---reverse
View
24 spec/spec_helper.rb
@@ -1,16 +1,8 @@
-$: << File.dirname(__FILE__) + '/../lib' << File.dirname(__FILE__)
-require 'rubygems'
-require 'spec'
-require 'spec/interop/test'
-
-require 'active_support'
-require 'action_controller'
-require 'action_controller/test_process'
-require 'action_view'
-
-require 'rspec-rails/rspec-rails'
-require 'country_code_select'
-
-Spec::Runner.configure do |config|
- config.include Spec::Rails::Matchers
-end
+$: << File.dirname(__FILE__) + "/../lib" << File.dirname(__FILE__)
+
+require "rubygems"
+require "active_support"
+require "action_view"
+require "rspec"
+
+require "country_code_select"

0 comments on commit 2d61110

Please sign in to comment.