Commit 84a9b0eb by Marcos Augusto

Organize the code better/adds some tests

tagging 2.2.2
parent 0fd27ddc
......@@ -6,14 +6,16 @@ Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate_models/annotate_models.rb
lib/annotate_routes/annotate_routes.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
......@@ -26,14 +28,16 @@ Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate_models/annotate_models.rb
lib/annotate_routes/annotate_routes.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
......@@ -46,14 +50,16 @@ Rakefile
annotate.gemspec
bin/annotate
lib/annotate.rb
lib/annotate_models/annotate_models.rb
lib/annotate_routes/annotate_routes.rb
lib/annotate/annotate_models.rb
lib/annotate/annotate_routes.rb
lib/tasks/annotate_models.rake
lib/tasks/annotate_routes.rake
script/console
script/destroy
script/generate
setup.rb
spec/annotate/annotate_models_spec.rb
spec/annotate/annotate_routes_spec.rb
spec/annotate_spec.rb
spec/spec.opts
spec/spec_helper.rb
......
......@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{annotate}
s.version = "2.1.1"
s.version = "2.2.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
......@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.email = ["x@nofxx.com"]
s.executables = ["annotate"]
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc"]
s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "annotate.gemspec", "bin/annotate", "lib/annotate.rb", "lib/annotate_models/annotate_models.rb", "lib/annotate_routes/annotate_routes.rb", "lib/tasks/annotate_models.rake", "lib/tasks/annotate_routes.rake", "script/console", "script/destroy", "script/generate", "setup.rb", "spec/annotate_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "annotate.gemspec", "bin/annotate", "lib/annotate.rb", "lib/annotate/annotate_models.rb", "lib/annotate/annotate_routes.rb", "lib/tasks/annotate_models.rake", "lib/tasks/annotate_routes.rake", "script/console", "script/destroy", "script/generate", "setup.rb", "spec/annotate/annotate_models_spec.rb", "spec/annotate/annotate_routes_spec.rb", "spec/annotate_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
s.has_rdoc = true
s.homepage = %q{http://github.com/nofxx/annotate}
s.rdoc_options = ["--main", "README.rdoc"]
......
......@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module Annotate
VERSION = '2.1.1'
VERSION = '2.2.2'
end
......
module AnnotateModels
class << self
# Annotate Models plugin use this header
COMPAT_PREFIX = "== Schema Info"
PREFIX = "== Schema Information"
MODEL_DIR = "app/models"
FIXTURE_DIRS = ["test/fixtures","spec/fixtures"]
UNIT_TEST_DIR = File.join(RAILS_ROOT, "test/unit" )
SPEC_MODEL_DIR = File.join(RAILS_ROOT, "spec/models")
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
UNIT_TEST_DIR = File.join("test", "unit" )
SPEC_MODEL_DIR = File.join("spec", "models")
# Object Daddy http://github.com/flogic/object_daddy/tree/master
EXEMPLARS_DIR = File.join(RAILS_ROOT, "spec/exemplars")
PREFIX = "== Schema Information"
# Annotate Models as plugin use this header
COMPAT_PREFIX = "== Schema Info"
EXEMPLARS_DIR = File.join("spec", "exemplars")
# Simple quoting for the default column value
def quote(value)
......
......@@ -20,8 +20,8 @@ module AnnotateRoutes
PREFIX = "#== Route Info"
def self.do_annotate
routes_rb = File.join(RAILS_ROOT, "config/routes.rb")
header = PREFIX + "\n# Generated on #{Time.now}"
routes_rb = File.join("config", "routes.rb")
header = PREFIX + "\n# Generated on #{Time.now}\n#"
if File.exists? routes_rb
routes_map = `rake routes`
routes_map = routes_map.split("\n")
......
desc "Add schema information (as comments) to model and fixture files"
task :annotate_models => :environment do
require 'annotate_models/annotate_models'
require 'annotate/annotate_models'
options={}
options[:position_in_class] = ENV['position_in_class'] || ENV['position']
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position']
......
desc "Prepends the route map to the top of routes.rb"
task :annotate_routes do
require 'annotate_routes/annotate_routes'
require 'annotate/annotate_routes'
AnnotateRoutes.do_annotate
end
require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_models'
describe AnnotateModels do
def mock_klass(stubs={})
@mock_file ||= mock("Klass", stubs)
end
def mock_column(stubs={})
@mock_column ||= mock("Column", stubs)
end
it { AnnotateModels.quote(nil).should eql("NULL") }
it { AnnotateModels.quote(true).should eql("TRUE") }
it { AnnotateModels.quote(false).should eql("FALSE") }
it { AnnotateModels.quote(25).should eql("25") }
it { AnnotateModels.quote(25.6).should eql("25.6") }
it { AnnotateModels.quote(1e-20).should eql("1.0e-20") }
it "should get schema info" do
AnnotateModels.get_schema_info(mock_klass(
:table_name => "users",
:primary_key => "id",
:column_names => ["id","login"],
:columns => [
mock_column(:type => "integer", :default => nil, :null => false, :name => "id", :limit => nil),
mock_column(:type => "string", :default => nil, :null => false, :name => "name", :limit => 50)
]), "Hello").should eql("# Hello\n#\n# Table name: users\n#\n# id :integer not null, primary key\n# id :integer not null, primary key\n#\n\n")
end
end
require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_routes'
describe AnnotateRoutes do
def mock_file(stubs={})
@mock_file ||= mock(File, stubs)
end
it "should check if routes.rb exists" do
File.should_receive(:join).with("config", "routes.rb").and_return(mock_file)
File.should_receive(:exists?).with(@mock_file).and_return(false)
AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")
AnnotateRoutes.do_annotate
end
it "should annotate!" do
File.should_receive(:join).with("config", "routes.rb").and_return("config/routes.rb")
File.should_receive(:exists?).with("config/routes.rb").and_return(true)
AnnotateRoutes.should_receive(:`).with("rake routes").and_return("bad line\ngood line")
File.should_receive(:read).with("config/routes.rb").and_return("bla")
File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
@mock_file.should_receive(:puts).with(/bla\n\n#== Route Info\n# Generated on .*\n#\n# good line/)
AnnotateRoutes.do_annotate
end
end
require File.dirname(__FILE__) + '/spec_helper.rb'
# Time to add your specs!
# http://rspec.info/
describe "Place your specs here" do
describe Annotate do
it "find this spec in spec directory" do
violated "Be sure to write your specs"
it "should have a version" do
Annotate::VERSION.should be_instance_of(String)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment