acts_as_working_days 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Pablo Cantero
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ ActsAsWorkingDays
2
+ ================
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2010 Pablo Cantero, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the acts_as_working_days plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the acts_as_working_days plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'ActsAsWorkingDays'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ PKG_FILES = FileList[
4
+ '[a-zA-Z]*',
5
+ 'generators/**/*',
6
+ 'lib/**/*',
7
+ 'rails/**/*',
8
+ 'tasks/**/*',
9
+ 'test/**/*'
10
+ ]
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = "acts_as_working_days"
14
+ s.version = "0.0.1"
15
+ s.author = "Pablo Cantero"
16
+ s.email = "pablo@pablocantero.com"
17
+ s.homepage = "http://pablocantero.com/"
18
+ s.platform = Gem::Platform::RUBY
19
+ s.summary = "acts_as_working_days is a Rails plugin to add working days on models"
20
+ s.files = PKG_FILES.to_a
21
+ s.require_path = "lib"
22
+ s.has_rdoc = false
23
+ s.extra_rdoc_files = ["README.rdoc"]
24
+ end
25
+
26
+ desc 'Turn this plugin into a gem.'
27
+ Rake::GemPackageTask.new(spec) do |pkg|
28
+ pkg.gem_spec = spec
29
+ end
data/init.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'acts_as_working_days'
2
+
3
+ #TODO Não é vendor/plugins/yaffle/lib/yaffle.rb: - Conforme o Guia
4
+ %w{ models }.each do |dir|
5
+ path = File.join(File.dirname(__FILE__), 'app', dir)
6
+ $LOAD_PATH << path
7
+ ActiveSupport::Dependencies.load_paths << path
8
+ ActiveSupport::Dependencies.load_once_paths.delete(path)
9
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,43 @@
1
+ module ActsAsWorkingDays
2
+ def self.included(base)
3
+ base.send :extend, ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ # any method placed here will apply to classes, like Hickwall
8
+ def acts_as_working_days
9
+ # adding relationship to self class
10
+ has_many :working_days, :as => :workable
11
+ send :include, InstanceMethods
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def working_day?(params ={:week_day => Time.now.wday, :hour => Time.now.hour, :min => Time.now.min })
17
+ result = working_days.where("week_day = :week_day AND ((start_hour < :hour) OR (start_hour = :hour AND start_min <= :min)) AND ((end_hour > :hour) OR (end_hour = :hour AND end_min <= :min))",
18
+ {
19
+ :week_day => params[:week_day],
20
+ :hour => params[:hour],
21
+ :min => params[:min]
22
+ })
23
+ !result.empty?
24
+ end
25
+
26
+ def put_working_day(params = {:week_day => Time.now.wday, :start_hour => 0, :start_min => 0, :end_hour => 23, :end_min => 59})
27
+ working_day = nil
28
+ working_days.each do | wd |
29
+ if wd.week_day == params[:week_day]
30
+ working_day = wd
31
+ break
32
+ end
33
+ end
34
+ if working_day.nil?
35
+ working_days.build(params)
36
+ else
37
+ working_day.update_attributes(params)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ ActiveRecord::Base.send :include, ActsAsWorkingDays
@@ -0,0 +1,32 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module ActsAsWorkingDays
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ desc "Generates migration for Tag and Tagging models"
8
+
9
+ def self.orm
10
+ Rails::Generators.options[:rails][:orm]
11
+ end
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
15
+ end
16
+
17
+ def self.orm_has_migration?
18
+ [:active_record].include? orm
19
+ end
20
+
21
+ def self.next_migration_number(path)
22
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ end
24
+
25
+ def create_migration_file
26
+ if self.class.orm_has_migration?
27
+ migration_template 'migration.rb', 'db/migrate/acts_as_working_days_migration'
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,25 @@
1
+ class ActsAsWorkingDaysMigration < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :working_days, :force => true do |t|
5
+ #Date time columns
6
+ t.integer :week_day
7
+ t.integer :start_hour
8
+ t.integer :start_min
9
+ t.integer :end_hour
10
+ t.integer :end_min
11
+ #Polymorphic columns
12
+ t.integer :workable_id
13
+ t.string :workable_type
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+
19
+ add_index :working_days, [:workable_id, :workable_type]
20
+
21
+ def self.down
22
+ drop_table :working_days
23
+ end
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ # namespace :db do
2
+ # namespace :migrate do
3
+ # description = "Migrate the database through scripts in vendor/plugins/acts_as_working_days/lib/db/migrate"
4
+ # description << "and update db/schema.rb by invoking db:schema:dump."
5
+ # description << "Target specific version with VERSION=x. Turn off output with VERBOSE=false."
6
+ #
7
+ # desc description
8
+ # task :act_as_working_days => :environment do
9
+ # ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
10
+ # ActiveRecord::Migrator.migrate("vendor/plugins/acts_as_working_days/lib/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
11
+ # Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
12
+ # end
13
+ # end
14
+ # end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'acts_as_working_days'
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsWorkingDaysTest < Test::Unit::TestCase
4
+ load_schema
5
+
6
+ # called before every single test
7
+ def setup
8
+ #@nuclear_power_plant = Company.new(:name => 'Springfield Nuclear Power Plant')
9
+ #@nuclear_power_plant.save
10
+ Company.delete_all
11
+ end
12
+
13
+ class Company < ActiveRecord::Base
14
+ acts_as_working_days
15
+ end
16
+
17
+ def test_schema_has_loaded_correctly
18
+ assert_equal [], Company.all
19
+ end
20
+
21
+ def test_put_working_day
22
+ the_leftorium = Company.new(:name => 'The Leftorium')
23
+ assert_equal [], the_leftorium.working_days
24
+ working_day = the_leftorium.put_working_day(:week_day => 0, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)
25
+ the_leftorium.save
26
+ assert_equal [working_day], the_leftorium.working_days
27
+ assert_equal 0, working_day.week_day
28
+ assert_equal 8, working_day.start_hour
29
+ assert_equal 30, working_day.start_min
30
+ assert_equal 18, working_day.end_hour
31
+ assert_equal 45, working_day.end_min
32
+ end
33
+
34
+ def test_put_updating_a_working_day
35
+ moes_tavern = Company.new(:name => 'Moes Tavern')
36
+ working_day = moes_tavern.put_working_day(:week_day => 0, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)
37
+ moes_tavern.save
38
+ #Updating working day
39
+ moes_tavern.put_working_day(:week_day => 0, :start_hour => 10, :start_min => 13, :end_hour => 19, :end_min => 23)
40
+ moes_tavern.save
41
+ working_day = moes_tavern.working_days.first
42
+ assert_equal 0, working_day.week_day
43
+ assert_equal 10, working_day.start_hour
44
+ assert_equal 13, working_day.start_min
45
+ assert_equal 19, working_day.end_hour
46
+ assert_equal 23, working_day.end_min
47
+ end
48
+
49
+ def test_true_working_day
50
+ moes_tavern = Company.new(:name => 'Moes Tavern')
51
+ moes_tavern.put_working_day(:week_day => 0, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)
52
+ moes_tavern.save
53
+ assert_equal true, moes_tavern.working_day?(:week_day => 0, :hour => 12, :minute => 0)
54
+ end
55
+
56
+ def test_uniqueness_week_day_per_model
57
+ nuclear_power_plant = Company.new(:name => 'Springfield Nuclear Power Plant')
58
+ working_day = nuclear_power_plant.put_working_day(:week_day => 0, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)
59
+ nuclear_power_plant.put_working_day(:week_day => 0, :start_hour => 9, :start_min => 15, :end_hour => 19, :end_min => 30)
60
+ nuclear_power_plant.save
61
+ assert_equal [working_day], nuclear_power_plant.working_days
62
+ nuclear_power_plant.put_working_day(:week_day => 0, :start_hour => 6, :start_min => 0, :end_hour => 16, :end_min => 15)
63
+ nuclear_power_plant.save
64
+ assert_equal [working_day], nuclear_power_plant.working_days
65
+ end
66
+
67
+ def test_false_working_day
68
+ kwik_e_mart = Company.new(:name => 'Kwik-E-Mart')
69
+ kwik_e_mart.put_working_day(:week_day => 1, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)
70
+ kwik_e_mart.save
71
+ assert_equal false, kwik_e_mart.working_day?(:week_day => 0, :hour => 12, :min => 0)
72
+ assert_equal false, kwik_e_mart.working_day?(:week_day => 1, :hour => 21)
73
+ assert_equal false, kwik_e_mart.working_day?(:week_day => 1, :hour => 7, :min => 15)
74
+ end
75
+
76
+ end
data/test/database.yml ADDED
@@ -0,0 +1,23 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ #TODO Não é dbfile como no guide
4
+ :database: vendor/plugins/acts_as_working_days/test/acts_as_working_days_plugin.sqlite.db
5
+
6
+ sqlite3:
7
+ :adapter: sqlite3
8
+ #TODO Não é dbfile como no guide
9
+ :database: vendor/plugins/acts_as_working_days/test/acts_as_working_days_plugin.sqlite3.db
10
+
11
+ postgresql:
12
+ :adapter: postgresql
13
+ :username: postgres
14
+ :password: postgres
15
+ :database: acts_as_working_days_test
16
+ :min_messages: ERROR
17
+
18
+ mysql:
19
+ :adapter: mysql
20
+ :host: localhost
21
+ :username: root
22
+ :password: password
23
+ :database: acts_as_working_days_test
data/test/debug.log ADDED
@@ -0,0 +1,161 @@
1
+ # Logfile created on Fri Nov 19 18:17:34 -0200 2010 by logger.rb/22285
2
+ SQL (0.3ms) select sqlite_version(*)
3
+ SQL (0.4ms) SELECT name
4
+ FROM sqlite_master
5
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
6
+
7
+ SQL (2.4ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
8
+ SQL (0.2ms) SELECT name
9
+ FROM sqlite_master
10
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
11
+
12
+ SQL (1.3ms) CREATE TABLE "working_days" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "week_day" integer, "start_hour" integer, "start_min" integer, "end_hour" integer, "end_min" integer, "workable_id" integer, "workable_type" varchar(255), "created_at" datetime, "updated_at" datetime) 
13
+ SQL (0.2ms) SELECT name
14
+ FROM sqlite_master
15
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
16
+
17
+ SQL (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
18
+ SQL (0.1ms) PRAGMA index_list("schema_migrations")
19
+ SQL (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
20
+ SQL (0.2ms) SELECT name
21
+ FROM sqlite_master
22
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
23
+
24
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
25
+ SQL (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
26
+ SQL (0.1ms) select sqlite_version(*)
27
+ SQL (0.3ms) SELECT name
28
+ FROM sqlite_master
29
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
30
+
31
+ SQL (2.0ms) DROP TABLE "companies"
32
+ SQL (1.2ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255))
33
+ SQL (0.2ms)  SELECT name
34
+ FROM sqlite_master
35
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
36
+ 
37
+ SQL (1.1ms) DROP TABLE "working_days"
38
+ SQL (1.3ms) CREATE TABLE "working_days" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "week_day" integer, "start_hour" integer, "start_min" integer, "end_hour" integer, "end_min" integer, "workable_id" integer, "workable_type" varchar(255), "created_at" datetime, "updated_at" datetime) 
39
+ SQL (0.2ms) SELECT name
40
+ FROM sqlite_master
41
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
42
+
43
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
44
+ SQL (0.2ms) SELECT name
45
+ FROM sqlite_master
46
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
47
+
48
+ SQL (0.1ms) DELETE FROM "companies" WHERE 1=1
49
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 1) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
50
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Kwik-E-Mart')
51
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 1) AND ("working_days"."workable_id" = 1) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
52
+ SQL (0.1ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:34.276908', 18, 45, 8, 30, '2010-11-19 20:17:34.276908', 1, 1, 'ActsAsWorkingDaysTest::Company')
53
+ SQL (0.3ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 1 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 0 AND ((start_hour < 12) OR (start_hour = 12 AND start_min <= 0)) AND ((end_hour > 12) OR (end_hour = 12 AND end_min <= 0)))) AS subquery
54
+ SQL (0.3ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 1 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 1 AND ((start_hour < 21) OR (start_hour = 21 AND start_min <= NULL)) AND ((end_hour > 21) OR (end_hour = 21 AND end_min <= NULL)))) AS subquery
55
+ SQL (0.2ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 1 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 1 AND ((start_hour < 7) OR (start_hour = 7 AND start_min <= 15)) AND ((end_hour > 7) OR (end_hour = 7 AND end_min <= 15)))) AS subquery
56
+ SQL (1.2ms) DELETE FROM "companies" WHERE 1=1
57
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
58
+ SQL (0.2ms) INSERT INTO "companies" ("name") VALUES ('Moes Tavern')
59
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 2) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
60
+ SQL (0.2ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:34.293433', 18, 45, 8, 30, '2010-11-19 20:17:34.293433', 0, 2, 'ActsAsWorkingDaysTest::Company')
61
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 2) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 2) LIMIT 1
62
+ SQL (0.3ms) UPDATE "working_days" SET "end_hour" = 19, "end_min" = 23, "start_hour" = 10, "start_min" = 13, "updated_at" = '2010-11-19 20:17:34.300106' WHERE ("working_days"."id" = 2)
63
+ SQL (1.0ms) DELETE FROM "companies" WHERE 1=1
64
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
65
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('The Leftorium')
66
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 3) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
67
+ SQL (0.1ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:34.309800', 18, 45, 8, 30, '2010-11-19 20:17:34.309800', 0, 3, 'ActsAsWorkingDaysTest::Company')
68
+ SQL (1.2ms) DELETE FROM "companies" WHERE 1=1
69
+ ActsAsWorkingDaysTest::Company Load (0.1ms) SELECT "companies".* FROM "companies"
70
+ SQL (0.1ms) DELETE FROM "companies" WHERE 1=1
71
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
72
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Moes Tavern')
73
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 4) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
74
+ SQL (0.2ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:34.320302', 18, 45, 8, 30, '2010-11-19 20:17:34.320302', 0, 4, 'ActsAsWorkingDaysTest::Company')
75
+ SQL (0.2ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 4 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 0 AND ((start_hour < 12) OR (start_hour = 12 AND start_min <= NULL)) AND ((end_hour > 12) OR (end_hour = 12 AND end_min <= NULL)))) AS subquery
76
+ SQL (1.0ms) DELETE FROM "companies" WHERE 1=1
77
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
78
+ SQL (0.3ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:34.329076', 19, 30, 9, 15, '2010-11-19 20:17:34.329076', 0, NULL, 'ActsAsWorkingDaysTest::Company')
79
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 5) LIMIT 1
80
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Springfield Nuclear Power Plant')
81
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 5) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 5) LIMIT 1
82
+ SQL (0.1ms) UPDATE "working_days" SET "updated_at" = '2010-11-19 20:17:34.336563', "workable_id" = 5 WHERE ("working_days"."id" = 5)
83
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 5) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 5) LIMIT 1
84
+ SQL (0.3ms) UPDATE "working_days" SET "end_hour" = 16, "end_min" = 15, "start_hour" = 6, "start_min" = 0, "updated_at" = '2010-11-19 20:17:34.341172' WHERE ("working_days"."id" = 5)
85
+ SQL (0.2ms) select sqlite_version(*)
86
+ SQL (0.4ms) SELECT name
87
+ FROM sqlite_master
88
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
89
+
90
+ SQL (2.6ms) DROP TABLE "companies"
91
+ SQL (1.1ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255))
92
+ SQL (0.2ms)  SELECT name
93
+ FROM sqlite_master
94
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
95
+ 
96
+ SQL (1.1ms) DROP TABLE "working_days"
97
+ SQL (1.3ms) CREATE TABLE "working_days" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "week_day" integer, "start_hour" integer, "start_min" integer, "end_hour" integer, "end_min" integer, "workable_id" integer, "workable_type" varchar(255), "created_at" datetime, "updated_at" datetime) 
98
+ SQL (0.2ms) SELECT name
99
+ FROM sqlite_master
100
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
101
+
102
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
103
+ SQL (0.1ms) select sqlite_version(*)
104
+ SQL (0.3ms)  SELECT name
105
+ FROM sqlite_master
106
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
107
+ 
108
+ SQL (1.2ms) DROP TABLE "companies"
109
+ SQL (1.0ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
110
+ SQL (0.2ms) SELECT name
111
+ FROM sqlite_master
112
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
113
+
114
+ SQL (1.4ms) DROP TABLE "working_days"
115
+ SQL (1.5ms) CREATE TABLE "working_days" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "week_day" integer, "start_hour" integer, "start_min" integer, "end_hour" integer, "end_min" integer, "workable_id" integer, "workable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
116
+ SQL (0.4ms)  SELECT name
117
+ FROM sqlite_master
118
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
119
+ 
120
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
121
+ SQL (0.2ms)  SELECT name
122
+ FROM sqlite_master
123
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
124
+ 
125
+ SQL (0.1ms) DELETE FROM "companies" WHERE 1=1
126
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 1) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
127
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Kwik-E-Mart')
128
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 1) AND ("working_days"."workable_id" = 1) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
129
+ SQL (0.1ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:39.252654', 18, 45, 8, 30, '2010-11-19 20:17:39.252654', 1, 1, 'ActsAsWorkingDaysTest::Company')
130
+ SQL (0.3ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 1 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 0 AND ((start_hour < 12) OR (start_hour = 12 AND start_min <= 0)) AND ((end_hour > 12) OR (end_hour = 12 AND end_min <= 0)))) AS subquery
131
+ SQL (0.2ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 1 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 1 AND ((start_hour < 21) OR (start_hour = 21 AND start_min <= NULL)) AND ((end_hour > 21) OR (end_hour = 21 AND end_min <= NULL)))) AS subquery
132
+ SQL (0.2ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 1 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 1 AND ((start_hour < 7) OR (start_hour = 7 AND start_min <= 15)) AND ((end_hour > 7) OR (end_hour = 7 AND end_min <= 15)))) AS subquery
133
+ SQL (1.1ms) DELETE FROM "companies" WHERE 1=1
134
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
135
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Moes Tavern')
136
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 2) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
137
+ SQL (0.1ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:39.268266', 18, 45, 8, 30, '2010-11-19 20:17:39.268266', 0, 2, 'ActsAsWorkingDaysTest::Company')
138
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 2) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 2) LIMIT 1
139
+ SQL (0.3ms) UPDATE "working_days" SET "end_hour" = 19, "end_min" = 23, "start_hour" = 10, "start_min" = 13, "updated_at" = '2010-11-19 20:17:39.273344' WHERE ("working_days"."id" = 2)
140
+ SQL (1.1ms) DELETE FROM "companies" WHERE 1=1
141
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
142
+ SQL (0.2ms) INSERT INTO "companies" ("name") VALUES ('The Leftorium')
143
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 3) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
144
+ SQL (0.1ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:39.283311', 18, 45, 8, 30, '2010-11-19 20:17:39.283311', 0, 3, 'ActsAsWorkingDaysTest::Company')
145
+ SQL (1.1ms) DELETE FROM "companies" WHERE 1=1
146
+ ActsAsWorkingDaysTest::Company Load (0.1ms) SELECT "companies".* FROM "companies"
147
+ SQL (0.1ms) DELETE FROM "companies" WHERE 1=1
148
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
149
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Moes Tavern')
150
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 4) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
151
+ SQL (0.1ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:39.294696', 18, 45, 8, 30, '2010-11-19 20:17:39.294696', 0, 4, 'ActsAsWorkingDaysTest::Company')
152
+ SQL (0.3ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM "working_days" WHERE ("working_days".workable_id = 4 AND "working_days".workable_type = 'ActsAsWorkingDaysTest::Company') AND (week_day = 0 AND ((start_hour < 12) OR (start_hour = 12 AND start_min <= NULL)) AND ((end_hour > 12) OR (end_hour = 12 AND end_min <= NULL)))) AS subquery
153
+ SQL (1.1ms) DELETE FROM "companies" WHERE 1=1
154
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') LIMIT 1
155
+ SQL (0.3ms) INSERT INTO "working_days" ("created_at", "end_hour", "end_min", "start_hour", "start_min", "updated_at", "week_day", "workable_id", "workable_type") VALUES ('2010-11-19 20:17:39.304368', 19, 30, 9, 15, '2010-11-19 20:17:39.304368', 0, NULL, 'ActsAsWorkingDaysTest::Company')
156
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" IS NULL) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 5) LIMIT 1
157
+ SQL (0.3ms) INSERT INTO "companies" ("name") VALUES ('Springfield Nuclear Power Plant')
158
+ WorkingDay Load (0.1ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 5) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 5) LIMIT 1
159
+ SQL (0.1ms) UPDATE "working_days" SET "updated_at" = '2010-11-19 20:17:39.312441', "workable_id" = 5 WHERE ("working_days"."id" = 5)
160
+ WorkingDay Load (0.2ms) SELECT "working_days"."id" FROM "working_days" WHERE ("working_days"."week_day" = 0) AND ("working_days"."workable_id" = 5) AND ("working_days"."workable_type" = 'ActsAsWorkingDaysTest::Company') AND ("working_days".id <> 5) LIMIT 1
161
+ SQL (0.3ms) UPDATE "working_days" SET "end_hour" = 16, "end_min" = 15, "start_hour" = 6, "start_min" = 0, "updated_at" = '2010-11-19 20:17:39.317952' WHERE ("working_days"."id" = 5)
data/test/schema.rb ADDED
@@ -0,0 +1,18 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :companies, :force => true do |t|
3
+ t.string :name
4
+ end
5
+ create_table :working_days, :force => true do |t|
6
+ #Date time columns
7
+ t.integer :week_day
8
+ t.integer :start_hour
9
+ t.integer :start_min
10
+ t.integer :end_hour
11
+ t.integer :end_min
12
+ #Polymorphic columns
13
+ t.integer :workable_id
14
+ t.string :workable_type
15
+
16
+ t.timestamps
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
3
+
4
+ require 'test/unit'
5
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
6
+
7
+ def load_schema
8
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
9
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
10
+
11
+ db_adapter = ENV['DB']
12
+
13
+ # no db passed, try one of these fine config-free DBs before bombing.
14
+ db_adapter ||=
15
+ begin
16
+ require 'rubygems'
17
+ require 'sqlite'
18
+ 'sqlite'
19
+ rescue MissingSourceFile
20
+ begin
21
+ require 'sqlite3'
22
+ 'sqlite3'
23
+ rescue MissingSourceFile
24
+ end
25
+ end
26
+
27
+ if db_adapter.nil?
28
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
29
+ end
30
+
31
+ ActiveRecord::Base.establish_connection(config[db_adapter])
32
+ load(File.dirname(__FILE__) + "/schema.rb")
33
+ require File.dirname(__FILE__) + '/../rails/init'
34
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class WorkingDayTest < Test::Unit::TestCase
4
+ load_schema
5
+
6
+ def test_working_day
7
+ assert_kind_of WorkingDay, WorkingDay.new
8
+ end
9
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_working_days
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Pablo Cantero
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-19 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: pablo@pablocantero.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - acts_as_working_days.gemspec
32
+ - init.rb
33
+ - install.rb
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - README.rdoc
37
+ - uninstall.rb
38
+ - lib/acts_as_working_days.rb
39
+ - lib/generators/acts_as_working_days/migration/migration_generator.rb
40
+ - lib/generators/acts_as_working_days/migration/templates/active_record/migration.rb
41
+ - lib/tasks/acts_as_working_days_tasks.rake
42
+ - rails/init.rb
43
+ - test/acts_as_working_days_plugin.sqlite3.db
44
+ - test/acts_as_working_days_test.rb
45
+ - test/database.yml
46
+ - test/debug.log
47
+ - test/schema.rb
48
+ - test/test_helper.rb
49
+ - test/working_day_test.rb
50
+ has_rdoc: true
51
+ homepage: http://pablocantero.com/
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: acts_as_working_days is a Rails plugin to add working days on models
84
+ test_files: []
85
+