Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge

  • Loading branch information...
commit 2a9295379f65ce58f66bed0ed198875de4811720 2 parents 5a78335 + 3120ed4
Michael Simpson authored November 16, 2012
29  Gemfile
@@ -33,11 +33,32 @@ end
33 33
 
34 34
 group :development, :test do
35 35
   gem 'debugger'
  36
+  gem 'guard'
  37
+  gem 'rb-fsevent'
  38
+  gem 'guard-rspec'
  39
+  gem 'guard-cucumber'
  40
+  gem 'guard-coffeescript'
  41
+  gem 'guard-livereload'
  42
+  gem 'guard-spork'
  43
+  gem 'spork'
  44
+  gem 'faker'
  45
+  gem "mailcatcher"
  46
+  gem "rspec-rails", "~> 2.0"
  47
+end
  48
+
  49
+group :development do
  50
+  gem "rails-erd"
  51
+  gem 'letters'
  52
+  gem 'pry-rails'
  53
+end
  54
+
  55
+
  56
+group :test do
  57
+  gem "cucumber-rails"
36 58
 end
37 59
 
38 60
 gem "jquery-rails"
39  
-gem "rspec-rails", ">= 2.0.1", :group => [:development, :test]
40 61
 gem 'devise'
41  
-gem 'whenever'
42  
-gem 'letters'
43  
-gem 'pry-rails'
  62
+gem 'whenever', :require => false
  63
+gem 'will_paginate', '~> 3.0'
  64
+
115  Gemfile.lock
@@ -28,10 +28,21 @@ GEM
28 28
     activesupport (3.2.8)
29 29
       i18n (~> 0.6)
30 30
       multi_json (~> 1.0)
  31
+    addressable (2.3.2)
31 32
     arel (3.0.2)
32 33
     awesome_print (1.1.0)
33 34
     bcrypt-ruby (3.0.1)
34 35
     builder (3.0.4)
  36
+    capybara (2.0.0)
  37
+      mime-types (>= 1.16)
  38
+      nokogiri (>= 1.3.3)
  39
+      rack (>= 1.0.0)
  40
+      rack-test (>= 0.5.4)
  41
+      selenium-webdriver (~> 2.0)
  42
+      xpath (~> 1.0.0)
  43
+    childprocess (0.3.6)
  44
+      ffi (~> 1.0, >= 1.0.6)
  45
+    choice (0.1.6)
35 46
     chronic (0.6.7)
36 47
     coderay (1.0.8)
37 48
     coffee-rails (3.2.2)
@@ -43,6 +54,16 @@ GEM
43 54
     coffee-script-source (1.3.3)
44 55
     colorize (0.5.8)
45 56
     columnize (0.3.6)
  57
+    cucumber (1.2.1)
  58
+      builder (>= 2.1.2)
  59
+      diff-lcs (>= 1.1.3)
  60
+      gherkin (~> 2.11.0)
  61
+      json (>= 1.4.6)
  62
+    cucumber-rails (1.3.0)
  63
+      capybara (>= 1.1.2)
  64
+      cucumber (>= 1.1.8)
  65
+      nokogiri (>= 1.5.0)
  66
+    daemons (1.1.9)
46 67
     debugger (1.2.1)
47 68
       columnize (>= 0.3.1)
48 69
       debugger-linecache (~> 1.1.1)
@@ -56,9 +77,42 @@ GEM
56 77
       railties (~> 3.1)
57 78
       warden (~> 1.2.1)
58 79
     diff-lcs (1.1.3)
  80
+    em-websocket (0.3.8)
  81
+      addressable (>= 2.1.1)
  82
+      eventmachine (>= 0.12.9)
59 83
     erubis (2.7.0)
  84
+    eventmachine (1.0.0)
60 85
     execjs (1.4.0)
61 86
       multi_json (~> 1.0)
  87
+    faker (1.1.2)
  88
+      i18n (~> 0.5)
  89
+    ffi (1.1.5)
  90
+    gherkin (2.11.5)
  91
+      json (>= 1.4.6)
  92
+    guard (1.5.4)
  93
+      listen (>= 0.4.2)
  94
+      lumberjack (>= 1.0.2)
  95
+      pry (>= 0.9.10)
  96
+      thor (>= 0.14.6)
  97
+    guard-coffeescript (1.2.1)
  98
+      coffee-script (>= 2.2.0)
  99
+      guard (>= 1.1.0)
  100
+    guard-cucumber (1.2.2)
  101
+      cucumber (>= 1.2.0)
  102
+      guard (>= 1.1.0)
  103
+    guard-livereload (1.1.0)
  104
+      em-websocket (>= 0.2.0)
  105
+      guard (>= 1.5.0)
  106
+      multi_json (~> 1.0)
  107
+    guard-rspec (2.1.1)
  108
+      guard (>= 1.1)
  109
+      rspec (~> 2.11)
  110
+    guard-spork (1.2.3)
  111
+      childprocess (>= 0.2.3)
  112
+      guard (>= 1.1)
  113
+      spork (>= 0.8.4)
  114
+      sys-proctable
  115
+    haml (3.1.7)
62 116
     hike (1.2.1)
63 117
     i18n (0.6.1)
64 118
     journey (1.0.4)
@@ -72,14 +126,28 @@ GEM
72 126
       colorize
73 127
       debugger
74 128
       xml-simple
  129
+    libwebsocket (0.1.5)
  130
+      addressable
  131
+    listen (0.5.3)
  132
+    lumberjack (1.0.2)
75 133
     mail (2.4.4)
76 134
       i18n (>= 0.4.0)
77 135
       mime-types (~> 1.16)
78 136
       treetop (~> 1.4.8)
  137
+    mailcatcher (0.5.10)
  138
+      activesupport (~> 3.0)
  139
+      eventmachine (~> 1.0.0)
  140
+      haml (~> 3.1)
  141
+      mail (~> 2.3)
  142
+      sinatra (~> 1.2)
  143
+      skinny (~> 0.2.3)
  144
+      sqlite3 (~> 1.3)
  145
+      thin (~> 1.5.0)
79 146
     method_source (0.8.1)
80 147
     mime-types (1.19)
81 148
     multi_json (1.3.6)
82 149
     mysql2 (0.3.11)
  150
+    nokogiri (1.5.5)
83 151
     orm_adapter (0.4.0)
84 152
     polyglot (0.3.3)
85 153
     pry (0.9.10)
@@ -91,6 +159,8 @@ GEM
91 159
     rack (1.4.1)
92 160
     rack-cache (1.2)
93 161
       rack (>= 0.4)
  162
+    rack-protection (1.2.0)
  163
+      rack
94 164
     rack-ssl (1.3.2)
95 165
       rack
96 166
     rack-test (0.6.2)
@@ -103,6 +173,11 @@ GEM
103 173
       activesupport (= 3.2.8)
104 174
       bundler (~> 1.0)
105 175
       railties (= 3.2.8)
  176
+    rails-erd (1.0.0)
  177
+      activerecord (>= 3.0)
  178
+      activesupport (>= 3.0)
  179
+      choice (~> 0.1.6)
  180
+      ruby-graphviz (~> 1.0.4)
106 181
     railties (3.2.8)
107 182
       actionpack (= 3.2.8)
108 183
       activesupport (= 3.2.8)
@@ -111,6 +186,7 @@ GEM
111 186
       rdoc (~> 3.4)
112 187
       thor (>= 0.14.6, < 2.0)
113 188
     rake (0.9.2.2)
  189
+    rb-fsevent (0.9.2)
114 190
     rdoc (3.12)
115 191
       json (~> 1.4)
116 192
     rspec (2.11.0)
@@ -126,16 +202,37 @@ GEM
126 202
       activesupport (>= 3.0)
127 203
       railties (>= 3.0)
128 204
       rspec (~> 2.11.0)
  205
+    ruby-graphviz (1.0.8)
  206
+    rubyzip (0.9.9)
129 207
     sass (3.2.1)
130 208
     sass-rails (3.2.5)
131 209
       railties (~> 3.2.0)
132 210
       sass (>= 3.1.10)
133 211
       tilt (~> 1.3)
  212
+    selenium-webdriver (2.26.0)
  213
+      childprocess (>= 0.2.5)
  214
+      libwebsocket (~> 0.1.3)
  215
+      multi_json (~> 1.0)
  216
+      rubyzip
  217
+    sinatra (1.3.3)
  218
+      rack (~> 1.3, >= 1.3.6)
  219
+      rack-protection (~> 1.2)
  220
+      tilt (~> 1.3, >= 1.3.3)
  221
+    skinny (0.2.3)
  222
+      eventmachine (~> 1.0.0)
  223
+      thin (~> 1.5.0)
134 224
     slop (3.3.3)
  225
+    spork (0.9.2)
135 226
     sprockets (2.1.3)
136 227
       hike (~> 1.2)
137 228
       rack (~> 1.0)
138 229
       tilt (~> 1.1, != 1.3.0)
  230
+    sqlite3 (1.3.6)
  231
+    sys-proctable (0.9.2)
  232
+    thin (1.5.0)
  233
+      daemons (>= 1.0.9)
  234
+      eventmachine (>= 0.12.6)
  235
+      rack (>= 1.0.0)
139 236
     thor (0.16.0)
140 237
     tilt (1.3.3)
141 238
     treetop (1.4.11)
@@ -150,21 +247,37 @@ GEM
150 247
     whenever (0.7.3)
151 248
       activesupport (>= 2.3.4)
152 249
       chronic (~> 0.6.3)
  250
+    will_paginate (3.0.3)
153 251
     xml-simple (1.1.2)
  252
+    xpath (1.0.0)
  253
+      nokogiri (~> 1.3)
154 254
 
155 255
 PLATFORMS
156 256
   ruby
157 257
 
158 258
 DEPENDENCIES
159 259
   coffee-rails (~> 3.2.1)
  260
+  cucumber-rails
160 261
   debugger
161 262
   devise
  263
+  faker
  264
+  guard
  265
+  guard-coffeescript
  266
+  guard-cucumber
  267
+  guard-livereload
  268
+  guard-rspec
  269
+  guard-spork
162 270
   jquery-rails
163 271
   letters
  272
+  mailcatcher
164 273
   mysql2
165 274
   pry-rails
166 275
   rails (= 3.2.8)
167  
-  rspec-rails (>= 2.0.1)
  276
+  rails-erd
  277
+  rb-fsevent
  278
+  rspec-rails (~> 2.0)
168 279
   sass-rails (~> 3.2.3)
  280
+  spork
169 281
   uglifier (>= 1.0.3)
170 282
   whenever
  283
+  will_paginate (~> 3.0)
20  README.md
Source Rendered
... ...
@@ -1,4 +1,22 @@
1 1
 temptd
2 2
 ======
3 3
 
4  
-An automated event scheduler.
  4
+An automated event scheduler.
  5
+
  6
+**TODO**  
  7
+assume UI is there
  8
+
  9
+voting: ui just captures the data, kind of done from the back-end POV
  10
+
  11
+
  12
+cron job weds night
  13
+  creates new sports (for now) event
  14
+  this should implicitly have time slots for all of the days
  15
+  sends out email letting ALL (for now until we incorporate groups) users know about next week's event poll.
  16
+
  17
+
  18
+
  19
+cron job tallies votes for each of the current events.
  20
+
  21
+
  22
+
29  app/models/event.rb
@@ -19,6 +19,33 @@ def calculate_event_details
19 19
   end
20 20
 
21 21
   def calculate_event_time
22  
-    timeslots.all(order: timeslots.votes.length).first
  22
+    timeslot = votes.select("votes.*, count(*) AS count").
  23
+                     group(:timeslot_id).
  24
+                     order("count DESC").
  25
+                     limit(1).try(:timeslot)
  26
+    
  27
+    timeslot ? [timeslot.starts_at, timeslot.end_at] : nil
23 28
   end
  29
+  
  30
+  
  31
+  
  32
+  # 5.times do |day_index|
  33
+  #   day = monday + day_index.days
  34
+  #   2.times do |i|
  35
+  #     start_time = day + (17 + i * 2).hours 
  36
+  #     end_time = day + (19 + i * 2).hours 
  37
+  # 
  38
+  #     Timeslot.create(event_id: test_event.id, starts_at: start_time, ends_at: end_time)
  39
+  #   end
  40
+  # end
  41
+  
  42
+  
  43
+  def self.start_new_sports_event
  44
+    # Event.
  45
+  end
  46
+  
  47
+  def self.finish_current_sports_event
  48
+    
  49
+  end
  50
+  
24 51
 end
2  app/models/event_preferences.rb → app/models/event_preference.rb
... ...
@@ -1,3 +1,3 @@
1  
-class EventPreferences < ActiveRecord::Base
  1
+class EventPreference < ActiveRecord::Base
2 2
   attr_accessible :category, :event_type_id
3 3
 end
2  app/models/timeslot.rb
... ...
@@ -1,5 +1,5 @@
1 1
 class Timeslot < ActiveRecord::Base
2  
-  attr_accessible :ends_at, :event_id, :starts_at
  2
+  attr_accessible :event_id, :ends_at, :starts_at
3 3
   belongs_to :event
4 4
   has_many :votes
5 5
   
2  app/models/user.rb
@@ -9,5 +9,5 @@ class User < ActiveRecord::Base
9 9
          :recoverable, :rememberable, :trackable, :validatable
10 10
 
11 11
   # Setup accessible (or protected) attributes for your model
12  
-  attr_accessible :email, :password, :password_confirmation, :remember_me
  12
+  attr_accessible :email, :password, :password_confirmation, :remember_me, :nickname
13 13
 end
2  app/models/user_event_preferences.rb → app/models/user_event_preference.rb
... ...
@@ -1,3 +1,3 @@
1  
-class UserEventPreferences < ActiveRecord::Base
  1
+class UserEventPreference < ActiveRecord::Base
2 2
   attr_accessible :event_preference_id, :user_id, :value
3 3
 end
2  app/views/events/show.html.erb
... ...
@@ -1,6 +1,6 @@
1 1
 <p id="notice"><%= notice %></p>
2 2
 <h1><%= @event %></h1>
3  
-<h2><%= @event.starts_at.strftime() %></h2>
  3
+<h2><%= @event.starts_at %></h2>
4 4
 
5 5
 <% if @event.timeslots.empty? %>
6 6
   No timeslots!
8  config/schedule.rb
@@ -18,3 +18,11 @@
18 18
 # end
19 19
 
20 20
 # Learn more: http://github.com/javan/whenever
  21
+
  22
+every :wednesday, :at => '10pm' do
  23
+  runner "Event.start_new_sports_event"
  24
+end
  25
+
  26
+every :saturday, :at => '12pm' do
  27
+  runner "Event.finish_current_sports_event"
  28
+end
27  db/seeds.rb
@@ -13,6 +13,33 @@
13 13
   sports_event.timeslots.create!(starts_at: starts_at)
14 14
 end
15 15
 
  16
+
  17
+EventType.destroy_all
  18
+Event.destroy_all
  19
+User.destroy_all
  20
+Timeslot.destroy_all
  21
+Vote.destroy_all
  22
+
  23
+sport = EventType.find_or_create_by_name("Sports")
  24
+test_event = Event.find_or_create_by_event_type_id(sport.id)
  25
+test_user = User.create(email: "user@name.com", password: 'password', password_confirmation: 'password', nickname: "The Hammer")
  26
+
  27
+monday = Time.now.beginning_of_week
  28
+
  29
+5.times do |day_index|
  30
+  day = monday + day_index.days
  31
+  2.times do |i|
  32
+    start_time = day + (17 + i * 2).hours 
  33
+    end_time = day + (19 + i * 2).hours 
  34
+
  35
+    Timeslot.create(event_id: test_event.id, starts_at: start_time, ends_at: end_time)
  36
+  end
  37
+end
  38
+
  39
+Vote.create(user_id: test_user.id, event_id: test_event.id, timeslot_id: Timeslot.last.id)
  40
+Vote.create(user_id: 2, event_id: test_event.id, timeslot_id: Timeslot.first.id)
  41
+Vote.create(user_id: 3, event_id: test_event.id, timeslot_id: Timeslot.last.id)
  42
+
16 43
 user = User.find_or_initialize_by_email("sports@scimedsolutions.com")
17 44
 user.nickname = "Sporty"
18 45
 user.password = "sporty"
19  spec/models/event_spec.rb
... ...
@@ -1,5 +1,22 @@
1 1
 require 'spec_helper'
2 2
 
3 3
 describe Event do
4  
-  pending "add some examples to (or delete) #{__FILE__}"
  4
+  
  5
+  it "should calculate_event_time" do
  6
+    
  7
+  end
  8
+  
  9
+  describe "#start_new_sports_event" do
  10
+    
  11
+    describe "should create new event"
  12
+      expect { Event.start_new_sports_event }.to
  13
+        change { Event.count }.by(1)
  14
+    end
  15
+    
  16
+  
  17
+  end
  18
+  
  19
+  
5 20
 end
  21
+
  22
+
73  spec/spec_helper.rb
... ...
@@ -1,38 +1,37 @@
1  
-# This file is copied to spec/ when you run 'rails generate rspec:install'
2  
-ENV["RAILS_ENV"] ||= 'test'
3  
-require File.expand_path("../../config/environment", __FILE__)
4  
-require 'rspec/rails'
5  
-require 'rspec/autorun'
6  
-
7  
-# Requires supporting ruby files with custom matchers and macros, etc,
8  
-# in spec/support/ and its subdirectories.
9  
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
10  
-
11  
-RSpec.configure do |config|
12  
-  # ## Mock Framework
13  
-  #
14  
-  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15  
-  #
16  
-  # config.mock_with :mocha
17  
-  # config.mock_with :flexmock
18  
-  # config.mock_with :rr
19  
-
20  
-  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21  
-  config.fixture_path = "#{::Rails.root}/spec/fixtures"
22  
-
23  
-  # If you're not using ActiveRecord, or you'd prefer not to run each of your
24  
-  # examples within a transaction, remove the following line or assign false
25  
-  # instead of true.
26  
-  config.use_transactional_fixtures = true
27  
-
28  
-  # If true, the base class of anonymous controllers will be inferred
29  
-  # automatically. This will be the default behavior in future versions of
30  
-  # rspec-rails.
31  
-  config.infer_base_class_for_anonymous_controllers = false
32  
-
33  
-  # Run specs in random order to surface order dependencies. If you find an
34  
-  # order dependency and want to debug it, you can fix the order by providing
35  
-  # the seed, which is printed after each run.
36  
-  #     --seed 1234
37  
-  config.order = "random"
  1
+require 'rubygems'
  2
+require 'spork'
  3
+#uncomment the following line to use spork with the debugger
  4
+#require 'spork/ext/ruby-debug'
  5
+
  6
+
  7
+Spork.prefork do
  8
+  ENV["RAILS_ENV"] ||= 'test'
  9
+  require File.expand_path("../../config/environment", __FILE__)
  10
+  require 'rspec/rails'
  11
+  # require 'factories'
  12
+  require File.expand_path("../../features/support/ldms_env", __FILE__)
  13
+
  14
+  # Requires supporting ruby files with custom matchers and macros, etc,
  15
+  # in spec/support/ and its subdirectories.
  16
+  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  17
+
  18
+  RSpec.configure do |config|
  19
+
  20
+    config.mock_with :rspec
  21
+    
  22
+    # now you can just call 'create', or 'build', etc w/out having to preface these calls w/ "FactoryGirl"
  23
+    config.include FactoryGirl::Syntax::Methods
  24
+
  25
+    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  26
+    config.fixture_path = "#{::Rails.root}/spec/fixtures"
  27
+
  28
+    # If you're not using ActiveRecord, or you'd prefer not to run each of your
  29
+    # examples within a transaction, remove the following line or assign false
  30
+    # instead of true.
  31
+    config.use_transactional_fixtures = true
  32
+  end
  33
+end
  34
+
  35
+Spork.each_run do
  36
+  # This code will be run each time you run your specs.
38 37
 end

0 notes on commit 2a92953

Please sign in to comment.
Something went wrong with that request. Please try again.