jakewendt-simply_trackable 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +55 -0
- data/app/models/track.rb +32 -0
- data/config/routes.rb +2 -0
- data/generators/simply_trackable/USAGE +8 -0
- data/generators/simply_trackable/simply_trackable_generator.rb +26 -0
- data/generators/simply_trackable/templates/autotest_simply_trackable.rb +2 -0
- data/generators/simply_trackable/templates/migration.rb +21 -0
- data/generators/simply_trackable/templates/simply_trackable.rake +5 -0
- data/generators/track_migration/USAGE +8 -0
- data/generators/track_migration/templates/migration.rb +21 -0
- data/generators/track_migration/track_migration_generator.rb +19 -0
- data/generators/trackable_migration/USAGE +8 -0
- data/generators/trackable_migration/templates/migration.rb +12 -0
- data/generators/trackable_migration/trackable_migration_generator.rb +29 -0
- data/lib/jakewendt-simply_trackable.rb +1 -0
- data/lib/simply_trackable.rb +41 -0
- data/lib/simply_trackable/autotest.rb +26 -0
- data/lib/simply_trackable/factories.rb +9 -0
- data/lib/simply_trackable/simply_trackable.rb +33 -0
- data/lib/simply_trackable/tasks.rb +1 -0
- data/lib/simply_trackable/test_tasks.rb +61 -0
- data/lib/tasks/simply_trackable_tasks.rake +4 -0
- data/rails/init.rb +1 -0
- data/test/app/controllers/application_controller.rb +8 -0
- data/test/app/controllers/home_controller.rb +8 -0
- data/test/app/models/book.rb +3 -0
- data/test/app/models/package.rb +4 -0
- data/test/config/routes.rb +2 -0
- data/test/unit/acts_as_trackable_test.rb +80 -0
- data/test/unit/trackable/track_test.rb +82 -0
- metadata +157 -0
data/README.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= SimplyTrackable
|
2
|
+
|
3
|
+
The initial purpose of this plugin is to remove some of the duplicity I had acquired when multiple models were being "tracked." Whether it be a package shipped via FedEx or a book loaned from a library. This plugin simply separates this trackability.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
Generate the migration for holding all of the tracks.
|
8
|
+
|
9
|
+
script/generate track_migration
|
10
|
+
rake db:migrate
|
11
|
+
|
12
|
+
Generate a migration for something trackable. I don't know how bad this is needed, but I put a "tracking_number" in all things trackable.
|
13
|
+
|
14
|
+
script/generate trackable_migration Transfer
|
15
|
+
script/generate trackable_migration Book
|
16
|
+
script/generate trackable_migration Package
|
17
|
+
rake db:migrate
|
18
|
+
|
19
|
+
config.gem 'jakewendt-simply_trackable',
|
20
|
+
:source => 'http://rubygems.org'
|
21
|
+
|
22
|
+
script/generate simply_trackable
|
23
|
+
|
24
|
+
== To Do
|
25
|
+
|
26
|
+
* Add tests to ensure that it does what it should
|
27
|
+
* More tests
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
== Testing (as an app)
|
33
|
+
|
34
|
+
rake db:migrate
|
35
|
+
rake db:fixtures:load
|
36
|
+
rake test
|
37
|
+
script/server
|
38
|
+
|
39
|
+
== Gemified with Jeweler
|
40
|
+
|
41
|
+
vi Rakefile
|
42
|
+
rake version:write
|
43
|
+
|
44
|
+
rake version:bump:patch
|
45
|
+
rake version:bump:minor
|
46
|
+
rake version:bump:major
|
47
|
+
|
48
|
+
rake gemspec
|
49
|
+
|
50
|
+
rake install
|
51
|
+
rake release
|
52
|
+
|
53
|
+
----
|
54
|
+
|
55
|
+
Copyright (c) 2010 [George Wendt], released under the MIT license
|
data/app/models/track.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class Track < ActiveRecord::Base
|
2
|
+
default_scope :order => :time
|
3
|
+
belongs_to :trackable,
|
4
|
+
:polymorphic => true,
|
5
|
+
:touch => true,
|
6
|
+
:counter_cache => true
|
7
|
+
|
8
|
+
validates_presence_of :trackable_id
|
9
|
+
validates_presence_of :trackable_type
|
10
|
+
validates_presence_of :name
|
11
|
+
validates_presence_of :time
|
12
|
+
validates_uniqueness_of :time, :scope => [:trackable_id, :trackable_type]
|
13
|
+
|
14
|
+
validates_length_of :name, :city, :state, :zip, :location,
|
15
|
+
:maximum => 250, :allow_blank => true
|
16
|
+
attr_accessible :name, :time, :city, :state, :zip, :location
|
17
|
+
|
18
|
+
before_save :combine_city_and_state
|
19
|
+
|
20
|
+
def combine_city_and_state
|
21
|
+
if location.blank?
|
22
|
+
self.location = if city.blank? && state.blank?
|
23
|
+
# city and state can be blank for events like
|
24
|
+
# 'Shipment information sent to FedEx'
|
25
|
+
"None"
|
26
|
+
else
|
27
|
+
[city,state].delete_if{|a|a.blank?}.join(', ')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class SimplyTrackableGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
m.directory('config/autotest')
|
6
|
+
m.file('autotest_simply_trackable.rb', 'config/autotest/simply_trackable.rb')
|
7
|
+
m.directory('lib/tasks')
|
8
|
+
m.file('simply_trackable.rake', 'lib/tasks/simply_trackable.rake')
|
9
|
+
|
10
|
+
# File.open('Rakefile','a'){|f|
|
11
|
+
# f.puts "# From `script/generate simply_trackable` ..."
|
12
|
+
# f.puts "require 'simply_trackable/test_tasks'"
|
13
|
+
# }
|
14
|
+
#
|
15
|
+
# File.open('.autotest','a'){|f|
|
16
|
+
# f.puts "# From `script/generate simply_trackable` ..."
|
17
|
+
# f.puts "require 'simply_trackable/autotest'"
|
18
|
+
# }
|
19
|
+
|
20
|
+
# m.directory "lib"
|
21
|
+
# m.template 'README', "README"
|
22
|
+
# m.migration_template 'migration.rb', 'db/migrate'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreateTracksTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :tracks do |t|
|
4
|
+
t.references :trackable, :polymorphic => true
|
5
|
+
t.string :name
|
6
|
+
t.string :location
|
7
|
+
t.string :city
|
8
|
+
t.string :state
|
9
|
+
t.string :zip
|
10
|
+
t.datetime :time
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
# Can't be two places at once!
|
14
|
+
add_index :tracks, [:trackable_id, :trackable_type, :time],
|
15
|
+
:unique => true
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :tracks
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreateTracksTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :tracks do |t|
|
4
|
+
t.references :trackable, :polymorphic => true
|
5
|
+
t.string :name
|
6
|
+
t.string :location
|
7
|
+
t.string :city
|
8
|
+
t.string :state
|
9
|
+
t.string :zip
|
10
|
+
t.datetime :time
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
# Can't be two places at once!
|
14
|
+
add_index :tracks, [:trackable_id, :trackable_type, :time],
|
15
|
+
:unique => true
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :tracks
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TrackMigrationGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def initialize(runtime_args, runtime_options = {})
|
4
|
+
# Rails::Generator::NamedBase apparently requires
|
5
|
+
# at least 1 argumnet. The first will be used
|
6
|
+
# for things like migration class name
|
7
|
+
runtime_args.unshift 'CreateTracksTable'
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def manifest
|
12
|
+
record do |m|
|
13
|
+
# m.directory "lib"
|
14
|
+
# m.template 'README', "README"
|
15
|
+
m.migration_template 'migration.rb', 'db/migrate'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class AddTrackingInfoTo<%= class_name.pluralize.gsub(/::/, '') -%> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :<%= file_path.gsub(/\//, '_').pluralize -%>, :tracks_count, :integer, :default => 0
|
4
|
+
add_column :<%= file_path.gsub(/\//, '_').pluralize -%>, :tracking_number, :string
|
5
|
+
add_index :<%= file_path.gsub(/\//, '_').pluralize -%>, :tracking_number, :unique => true
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
remove_column :<%= file_path.gsub(/\//, '_').pluralize -%>, :tracks_count
|
10
|
+
remove_column :<%= file_path.gsub(/\//, '_').pluralize -%>, :tracking_number
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class TrackableMigrationGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def initialize(runtime_args, runtime_options = {})
|
4
|
+
# # Rails::Generator::NamedBase apparently requires
|
5
|
+
# # at least 1 argumnet. The first will be used
|
6
|
+
# # for things like migration class name
|
7
|
+
# runtime_args.unshift 'CreateTracksTable'
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def manifest
|
13
|
+
record do |m|
|
14
|
+
m.migration_template 'migration.rb', 'db/migrate',
|
15
|
+
:migration_file_name => "add_tracking_info_to_#{file_path.gsub(/\//, '_').pluralize}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# I have no idea what I'm doing. Monkey see, monkey do.
|
20
|
+
# This does seem to work though.
|
21
|
+
# class_name = the first argument passed to the generator
|
22
|
+
# file_path = class_name.underscore
|
23
|
+
# tableize would have been good
|
24
|
+
# AddTrackingNumberTo
|
25
|
+
# :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" },
|
26
|
+
#
|
27
|
+
# where does "file_path" come from?
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'simply_trackable'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_support'
|
3
|
+
require 'ruby_extension'
|
4
|
+
require 'simply_helpful'
|
5
|
+
require 'acts_as_list'
|
6
|
+
module SimplyTrackable
|
7
|
+
# predefine namespace
|
8
|
+
end
|
9
|
+
|
10
|
+
# This doesn't seem necessary
|
11
|
+
%w{models controllers}.each do |dir|
|
12
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), '../app', dir))
|
13
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
14
|
+
ActiveSupport::Dependencies.autoload_once_paths << path
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'action_controller' # loads HTML
|
18
|
+
HTML::WhiteListSanitizer.allowed_attributes.merge(%w(
|
19
|
+
id class style
|
20
|
+
))
|
21
|
+
|
22
|
+
require 'simply_trackable/simply_trackable'
|
23
|
+
|
24
|
+
if defined?(Rails) && Rails.env == 'test' && Rails.class_variable_defined?("@@configuration")
|
25
|
+
require 'active_support/test_case'
|
26
|
+
require 'factory_girl'
|
27
|
+
require 'simply_trackable/factories'
|
28
|
+
# else
|
29
|
+
# running a rake task
|
30
|
+
end
|
31
|
+
|
32
|
+
#ActionController::Routing::Routes.add_configuration_file(
|
33
|
+
# File.expand_path(
|
34
|
+
# File.join(
|
35
|
+
# File.dirname(__FILE__), '../config/routes.rb')))
|
36
|
+
#
|
37
|
+
#ActionController::Base.view_paths <<
|
38
|
+
# File.expand_path(
|
39
|
+
# File.join(
|
40
|
+
# File.dirname(__FILE__), '../app/views'))
|
41
|
+
#
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Autotest::Rails
|
2
|
+
|
3
|
+
#
|
4
|
+
# Need both the mapping and the extra files
|
5
|
+
#
|
6
|
+
def run_with_simply_trackable
|
7
|
+
add_exception %r%config/%
|
8
|
+
add_exception %r%versions/%
|
9
|
+
add_exception %r%\.git/%
|
10
|
+
self.extra_files << File.expand_path(File.join(
|
11
|
+
File.dirname(__FILE__),'/../../test/unit/trackable/'))
|
12
|
+
|
13
|
+
self.extra_files << File.expand_path(File.join(
|
14
|
+
File.dirname(__FILE__),'/../../test/functional/trackable/'))
|
15
|
+
|
16
|
+
add_mapping(
|
17
|
+
%r{^#{File.expand_path(File.join(File.dirname(__FILE__),'/../../test/'))}/(unit|functional)/trackable/.*_test\.rb$}
|
18
|
+
) do |filename, _|
|
19
|
+
filename
|
20
|
+
end
|
21
|
+
run_without_simply_trackable
|
22
|
+
end
|
23
|
+
alias_method_chain :run, :simply_trackable
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SimplyTrackable #:nodoc:
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ARMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
module ARMethods
|
7
|
+
def acts_as_trackable(options = {})
|
8
|
+
has_many :tracks, :as => :trackable, :dependent => :destroy
|
9
|
+
# validates_length_of :tracking_number, :minimum => 3
|
10
|
+
validates_uniqueness_of :tracking_number,
|
11
|
+
:allow_blank => true
|
12
|
+
|
13
|
+
if self.accessible_attributes
|
14
|
+
attr_accessible :tracking_number
|
15
|
+
end
|
16
|
+
|
17
|
+
include SimplyTrackable::InstanceMethods
|
18
|
+
|
19
|
+
before_validation :nullify_blank_tracking_number
|
20
|
+
|
21
|
+
end
|
22
|
+
alias_method :simply_trackable, :acts_as_trackable
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
def nullify_blank_tracking_number
|
27
|
+
# An empty form field is not NULL to MySQL so ...
|
28
|
+
self.tracking_number = nil if tracking_number.blank?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
ActiveRecord::Base.send( :include, SimplyTrackable )
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/../tasks/**/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module SimplyTrackable;end
|
2
|
+
namespace :test do
|
3
|
+
namespace :units do
|
4
|
+
Rake::TestTask.new(:simply_trackable => "db:test:prepare") do |t|
|
5
|
+
t.pattern = File.expand_path(File.join(
|
6
|
+
File.dirname(__FILE__),'/../../test/unit/trackable/*_test.rb'))
|
7
|
+
t.libs << "test"
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
namespace :functionals do
|
12
|
+
Rake::TestTask.new(:simply_trackable => "db:test:prepare") do |t|
|
13
|
+
t.pattern = File.expand_path(File.join(
|
14
|
+
File.dirname(__FILE__),'/../../test/functional/trackable/*_test.rb'))
|
15
|
+
t.libs << "test"
|
16
|
+
t.verbose = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
Rake::Task['test:functionals'].prerequisites.unshift(
|
21
|
+
"test:functionals:simply_trackable" )
|
22
|
+
Rake::Task['test:units'].prerequisites.unshift(
|
23
|
+
"test:units:simply_trackable" )
|
24
|
+
|
25
|
+
# I thought of possibly just including this file
|
26
|
+
# but that would make __FILE__ different.
|
27
|
+
# Hmmm
|
28
|
+
|
29
|
+
#
|
30
|
+
# used in simply_helpful's rake test:coverage to run gem's
|
31
|
+
# tests in the context of the application
|
32
|
+
#
|
33
|
+
@gem_test_dirs ||= []
|
34
|
+
#@gem_test_dirs << File.expand_path(File.join(File.dirname(__FILE__),
|
35
|
+
# '/../../test/unit/trackable/'))
|
36
|
+
|
37
|
+
#
|
38
|
+
# No functional tests so...
|
39
|
+
#
|
40
|
+
#/Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516:in `load': no such file to load -- /Library/Ruby/Gems/1.8/gems/jakewendt-simply_trackable-1.3.5/test/functional/trackable/*_test.rb (LoadError)
|
41
|
+
# from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516
|
42
|
+
# from /usr/bin/rcov:19:in `load'
|
43
|
+
# from /usr/bin/rcov:19
|
44
|
+
#
|
45
|
+
# Actually, I think the error is because the directory isn't there
|
46
|
+
# because there aren't any files in the gem in that directory.
|
47
|
+
# Perhaps I could try to force it. Until then, comment this line out.
|
48
|
+
#
|
49
|
+
#@gem_test_dirs << File.expand_path(File.join(File.dirname(__FILE__),
|
50
|
+
# '/../../test/functional/trackable/'))
|
51
|
+
|
52
|
+
#
|
53
|
+
# More flexible. Find all test files, pick out their dir, uniq 'em and add.
|
54
|
+
#
|
55
|
+
Dir.glob( File.expand_path(File.join(File.dirname(__FILE__),
|
56
|
+
'/../../test/*/trackable/*_test.rb'))
|
57
|
+
).collect{|f|
|
58
|
+
File.dirname(f)
|
59
|
+
}.uniq.each{ |dir|
|
60
|
+
@gem_test_dirs << dir
|
61
|
+
}
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'jakewendt-simply_trackable'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class ActsAsTrackableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
# def setup
|
6
|
+
# setup_db
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# def teardown
|
10
|
+
# teardown_db
|
11
|
+
# end
|
12
|
+
|
13
|
+
test "should create book" do
|
14
|
+
assert_difference 'Book.count' do
|
15
|
+
book = create_book
|
16
|
+
assert !book.new_record?,
|
17
|
+
"#{book.errors.full_messages.to_sentence}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should NOT require tracking_number" do
|
22
|
+
assert_difference 'Book.count' do
|
23
|
+
book = create_book(:tracking_number => nil)
|
24
|
+
assert !book.errors.on(:tracking_number)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should NOT require 3 char tracking_number" do
|
29
|
+
assert_difference 'Book.count' do
|
30
|
+
book = create_book(:tracking_number => 'Hi')
|
31
|
+
assert !book.errors.on(:tracking_number)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should require unique tracking_number" do
|
36
|
+
b = create_book
|
37
|
+
assert_no_difference 'Book.count' do
|
38
|
+
book = create_book(:tracking_number => b.tracking_number)
|
39
|
+
assert book.errors.on(:tracking_number)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should have many tracks" do
|
44
|
+
book = create_book
|
45
|
+
assert_equal 0, book.tracks.length
|
46
|
+
book.tracks.create!( :name => 'name', :time => Time.now - 10000 )
|
47
|
+
assert_equal 1, book.reload.tracks.length
|
48
|
+
assert_equal 1, book.reload.tracks_count
|
49
|
+
book.tracks.create!( :name => 'name', :time => Time.now )
|
50
|
+
assert_equal 2, book.reload.tracks.length
|
51
|
+
assert_equal 2, book.reload.tracks_count
|
52
|
+
end
|
53
|
+
|
54
|
+
test "should mass assign tracking number when attr_accessible not used" do
|
55
|
+
assert_difference 'Book.count' do
|
56
|
+
book = Book.new({ :tracking_number => '123' })
|
57
|
+
book.save
|
58
|
+
assert !book.new_record?,
|
59
|
+
"#{book.errors.full_messages.to_sentence}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test "should mass assign tracking number when attr_accessible used" do
|
64
|
+
assert_difference 'Package.count' do
|
65
|
+
package = Package.new({ :tracking_number => '123' })
|
66
|
+
package.save
|
67
|
+
assert !package.new_record?,
|
68
|
+
"#{package.errors.full_messages.to_sentence}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_book(options = {})
|
73
|
+
record = Book.new({
|
74
|
+
:tracking_number => '123'
|
75
|
+
}.merge(options))
|
76
|
+
record.save
|
77
|
+
record
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class SimplyTrackable::TrackTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
# assert_should_create_default_object
|
7
|
+
assert_should_initially_belong_to(:trackable)
|
8
|
+
assert_should_require_attributes(:trackable_id,:name,:time)
|
9
|
+
assert_should_require_unique_attributes(:time,
|
10
|
+
:scope => [:trackable_id, :trackable_type])
|
11
|
+
assert_should_not_require_attributes(
|
12
|
+
:trackable_type,
|
13
|
+
:location,
|
14
|
+
:city,
|
15
|
+
:state,
|
16
|
+
:zip )
|
17
|
+
assert_should_require_attribute_length(
|
18
|
+
:name, :location, :city, :state, :zip,
|
19
|
+
:maximum => 250)
|
20
|
+
|
21
|
+
test "should create track" do
|
22
|
+
assert_difference 'Track.count' do
|
23
|
+
track = Factory(:track)
|
24
|
+
assert !track.new_record?,
|
25
|
+
"#{track.errors.full_messages.to_sentence}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "should require trackable" do
|
30
|
+
assert_no_difference 'Track.count' do
|
31
|
+
track = create_object(:trackable => nil)
|
32
|
+
assert track.errors.on(:trackable_id)
|
33
|
+
assert track.errors.on(:trackable_type)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should require trackable_type" do
|
38
|
+
assert_no_difference 'Track.count' do
|
39
|
+
track = create_object(:trackable_id => 1)
|
40
|
+
assert_nil track.trackable_type
|
41
|
+
assert track.errors.on(:trackable_type)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should copy city and state to location if no location" do
|
46
|
+
track = create_object({
|
47
|
+
:city => "Berkeley",
|
48
|
+
:state => "CA"
|
49
|
+
})
|
50
|
+
assert_equal track.reload.trackable.tracks.first.location, "Berkeley, CA"
|
51
|
+
end
|
52
|
+
|
53
|
+
test "should NOT copy city and state to location if location given" do
|
54
|
+
track = create_object({
|
55
|
+
:location => "my location",
|
56
|
+
:city => "Berkeley",
|
57
|
+
:state => "CA"
|
58
|
+
})
|
59
|
+
assert_equal track.reload.trackable.tracks.first.location, "my location"
|
60
|
+
end
|
61
|
+
|
62
|
+
test "should combine city and state into location" do
|
63
|
+
track = create_object( :city => "Berkeley", :state => "CA")
|
64
|
+
assert_equal track.location, "Berkeley, CA"
|
65
|
+
end
|
66
|
+
|
67
|
+
test "should use just city in location if that's all that's given" do
|
68
|
+
track = create_object(:city => "Berkeley")
|
69
|
+
assert_equal track.location, "Berkeley"
|
70
|
+
end
|
71
|
+
|
72
|
+
test "should use just state in location if that's all that's given" do
|
73
|
+
track = create_object(:state => "CA")
|
74
|
+
assert_equal track.location, "CA"
|
75
|
+
end
|
76
|
+
|
77
|
+
test "should use None as location when no location, city or state given" do
|
78
|
+
track = create_object
|
79
|
+
assert_equal track.location, "None"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jakewendt-simply_trackable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
- 7
|
10
|
+
version: 1.3.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- George 'Jake' Wendt
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-10 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
version: "2"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jakewendt-ruby_extension
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jakewendt-rails_extension
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: ryanb-acts-as-list
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
description: longer description of your gem
|
78
|
+
email: github@jake.otherinbox.com
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files:
|
84
|
+
- README.rdoc
|
85
|
+
files:
|
86
|
+
- app/models/track.rb
|
87
|
+
- config/routes.rb
|
88
|
+
- generators/simply_trackable/USAGE
|
89
|
+
- generators/simply_trackable/simply_trackable_generator.rb
|
90
|
+
- generators/simply_trackable/templates/autotest_simply_trackable.rb
|
91
|
+
- generators/simply_trackable/templates/migration.rb
|
92
|
+
- generators/simply_trackable/templates/simply_trackable.rake
|
93
|
+
- generators/track_migration/USAGE
|
94
|
+
- generators/track_migration/templates/migration.rb
|
95
|
+
- generators/track_migration/track_migration_generator.rb
|
96
|
+
- generators/trackable_migration/USAGE
|
97
|
+
- generators/trackable_migration/templates/migration.rb
|
98
|
+
- generators/trackable_migration/trackable_migration_generator.rb
|
99
|
+
- lib/jakewendt-simply_trackable.rb
|
100
|
+
- lib/simply_trackable.rb
|
101
|
+
- lib/simply_trackable/autotest.rb
|
102
|
+
- lib/simply_trackable/factories.rb
|
103
|
+
- lib/simply_trackable/simply_trackable.rb
|
104
|
+
- lib/simply_trackable/tasks.rb
|
105
|
+
- lib/simply_trackable/test_tasks.rb
|
106
|
+
- lib/tasks/simply_trackable_tasks.rake
|
107
|
+
- rails/init.rb
|
108
|
+
- README.rdoc
|
109
|
+
- test/app/controllers/application_controller.rb
|
110
|
+
- test/app/controllers/home_controller.rb
|
111
|
+
- test/app/models/book.rb
|
112
|
+
- test/app/models/package.rb
|
113
|
+
- test/config/routes.rb
|
114
|
+
- test/unit/acts_as_trackable_test.rb
|
115
|
+
- test/unit/trackable/track_test.rb
|
116
|
+
has_rdoc: true
|
117
|
+
homepage: http://github.com/jakewendt/simply_trackable
|
118
|
+
licenses: []
|
119
|
+
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.6.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: one-line summary of your gem
|
150
|
+
test_files:
|
151
|
+
- test/app/controllers/application_controller.rb
|
152
|
+
- test/app/controllers/home_controller.rb
|
153
|
+
- test/app/models/book.rb
|
154
|
+
- test/app/models/package.rb
|
155
|
+
- test/config/routes.rb
|
156
|
+
- test/unit/acts_as_trackable_test.rb
|
157
|
+
- test/unit/trackable/track_test.rb
|