From 51533d565550a217027c11b9b015b14831882237 Mon Sep 17 00:00:00 2001 From: Jan Schwenzien Date: Mon, 18 Apr 2011 20:08:02 +0200 Subject: [PATCH] added autocomplete_bank_name method, added gemspec --- Rakefile | 4 +- kontoapi-rails.gemspec | 75 +++++++++++++++++++ lib/kontoapi-rails.rb | 1 + .../orm/active_record_extension.rb | 18 ++++- .../validators/bank_account_validator.rb | 2 +- spec/kontoapi-rails_spec.rb | 6 +- 6 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 kontoapi-rails.gemspec diff --git a/Rakefile b/Rakefile index 5ff48b2..8b987f1 100644 --- a/Rakefile +++ b/Rakefile @@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem| gem.name = "kontoapi-rails" gem.homepage = "http://github.com/GeneralScripting/kontoapi-rails" gem.license = "MIT" - gem.summary = %Q{TODO: one-line summary of your gem} - gem.description = %Q{TODO: longer description of your gem} + gem.summary = %Q{A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.} + gem.description = %Q{This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.} gem.email = "jan@schwenzien.org" gem.authors = ["Jan Schwenzien"] # Include your dependencies below. Runtime dependencies are required when using your gem, diff --git a/kontoapi-rails.gemspec b/kontoapi-rails.gemspec new file mode 100644 index 0000000..161c689 --- /dev/null +++ b/kontoapi-rails.gemspec @@ -0,0 +1,75 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{kontoapi-rails} + s.version = "0.0.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Jan Schwenzien"] + s.date = %q{2011-04-18} + s.description = %q{This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.} + s.email = %q{jan@schwenzien.org} + s.extra_rdoc_files = [ + "LICENSE", + "README.markdown" + ] + s.files = [ + ".document", + ".rspec", + "Gemfile", + "Gemfile.lock", + "LICENSE", + "README.markdown", + "Rakefile", + "VERSION", + "init.rb", + "lib/kontoapi-rails.rb", + "lib/kontoapi-rails/config.rb", + "lib/kontoapi-rails/orm/active_record_extension.rb", + "lib/kontoapi-rails/orm/mongoid_extension.rb", + "lib/kontoapi-rails/railtie.rb", + "lib/kontoapi-rails/validators/bank_account_validator.rb", + "spec/kontoapi-rails_spec.rb", + "spec/spec_helper.rb" + ] + s.homepage = %q{http://github.com/GeneralScripting/kontoapi-rails} + s.licenses = ["MIT"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.7.2} + s.summary = %q{A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.} + s.test_files = [ + "spec/kontoapi-rails_spec.rb", + "spec/spec_helper.rb" + ] + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, ["~> 3.0.0"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, ["~> 2.3.0"]) + s.add_development_dependency(%q, ["~> 1.0.0"]) + s.add_development_dependency(%q, ["~> 1.5.2"]) + s.add_development_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, ["~> 3.0.0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["~> 2.3.0"]) + s.add_dependency(%q, ["~> 1.0.0"]) + s.add_dependency(%q, ["~> 1.5.2"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, ["~> 3.0.0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["~> 2.3.0"]) + s.add_dependency(%q, ["~> 1.0.0"]) + s.add_dependency(%q, ["~> 1.5.2"]) + s.add_dependency(%q, [">= 0"]) + end +end + diff --git a/lib/kontoapi-rails.rb b/lib/kontoapi-rails.rb index f1c49fb..609bd88 100644 --- a/lib/kontoapi-rails.rb +++ b/lib/kontoapi-rails.rb @@ -1,2 +1,3 @@ +require 'kontoapi-ruby' require 'kontoapi-rails/config' require 'kontoapi-rails/railtie' \ No newline at end of file diff --git a/lib/kontoapi-rails/orm/active_record_extension.rb b/lib/kontoapi-rails/orm/active_record_extension.rb index 5fd5b0b..8bd44b6 100644 --- a/lib/kontoapi-rails/orm/active_record_extension.rb +++ b/lib/kontoapi-rails/orm/active_record_extension.rb @@ -8,10 +8,22 @@ def self.included(base) module ClassMethods def validates_bank_account(options={}) options.symbolize_keys! - class_eval do - validates_with KontoAPI::BankAccountValidator, options + validates_with KontoAPI::BankAccountValidator, options + end + + def autocomplete_bank_name(options={}) + options.symbolize_keys! + options.reverse_merge!( + :bank_code_field => :bank_code, + :bank_name_field => :bank_name + ) + #write_inheritable_attribute(:autocomplete_bank_name_options, options) + define_method :autocomplete_bank_name do + current_value = send(:"#{options[:bank_name_field]}") + blz = send(:"#{options[:bank_code_field]}") + self.send(:"#{options[:bank_name_field]}=", KontoAPI::bank_name(blz)) if current_value.blank? && blz.present? end - nil + before_save :autocomplete_bank_name end end diff --git a/lib/kontoapi-rails/validators/bank_account_validator.rb b/lib/kontoapi-rails/validators/bank_account_validator.rb index ad078c8..f25227b 100644 --- a/lib/kontoapi-rails/validators/bank_account_validator.rb +++ b/lib/kontoapi-rails/validators/bank_account_validator.rb @@ -13,7 +13,7 @@ class BankAccountValidator < ActiveModel::Validator def validate(record) record_options = options.reverse_merge(DEFAULTS) account_number = record.send(:"#{record_options[:account_number_field]}") - bank_code = record.send(:"#{record_options[:bank_code_field]}")) + bank_code = record.send(:"#{record_options[:bank_code_field]}") record.errors[:"#{record_options[:account_number_field]}"] << :invalid unless KontoAPI::valid?(account_number, bank_code) rescue Timeout::Error => ex case record_options[:on_timeout] diff --git a/spec/kontoapi-rails_spec.rb b/spec/kontoapi-rails_spec.rb index bd5a3ce..b9fda70 100644 --- a/spec/kontoapi-rails_spec.rb +++ b/spec/kontoapi-rails_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -describe "KontoapiRails" do - it "fails" do - fail "hey buddy, you should probably rename this file and start specing for real" +describe "KontoAPI Rails" do + it "should be tested" do + fail "TEST ME!" end end