recurs 0.0.4.2 → 0.0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,8 @@ Feature:
5
5
 
6
6
  Scenario: The recurs generators create a recurs scaffold
7
7
  for each model that I generate with a recurs generator
8
+ #Given I run "rake build"
9
+ #And I run "gem install pkg/recurs-0.0.4.2.gem"
8
10
  Given I run "rails new test_app"
9
11
  And I cd to "test_app"
10
12
  And a file named "Gemfile" with:
@@ -14,19 +16,224 @@ Feature:
14
16
  gem 'sqlite3-ruby', :require => 'sqlite3'
15
17
  gem 'recurs' #, :path => '../../../'
16
18
  """
17
- And I run "bundle install"
19
+ #And I run "bundle install"
18
20
  And I run "rails generate recurs_widget Event"
19
- Then the output should contain:
20
- """
21
- create app/models/event.rb
22
-
23
- """
21
+ # Then the output should contain:
22
+ # """
23
+ # create app/models/event.rb
24
+ # create db/migrate
25
+ #
26
+ # """
27
+ And the following directories should exist:
28
+ | db/migrate |
24
29
  And the following files should exist:
25
30
  | app/models/event.rb |
26
31
  | app/views/events/index.html.haml |
27
32
  | app/views/events/new.html.haml |
28
33
  | app/views/events/edit.html.haml |
29
34
  | app/views/events/_form.html.haml |
30
- | app/views/events/schemes/_form.html.haml |
31
- And the following files should not exist:
32
- And I run "rake db:migrate"
35
+ | app/views/events/schemes/_monthly.html.haml |
36
+ | app/views/events/schemes/_set_points.html.haml |
37
+ | app/views/events/schemes/_standard.html.haml |
38
+ | app/views/events/schemes/_weekly.html.haml |
39
+ | app/controllers/events_controller.rb |
40
+ And the file "app/models/event.rb" should contain exactly:
41
+ """
42
+ class Event < ActiveRecord::Base
43
+ acts_as_recurring
44
+ end
45
+ """
46
+
47
+
48
+ And the file "app/views/events/new.html.haml" should contain exactly:
49
+ """
50
+ %h1 New event
51
+
52
+ = render 'form'
53
+
54
+ = link_to 'Back', events_path
55
+ """
56
+
57
+
58
+
59
+ And the file "app/views/events/_form.html.haml" should contain exactly:
60
+ """
61
+ = form_for @event do |f|
62
+ -if @event.errors.any?
63
+ #errorExplanation
64
+ %h2= "#{pluralize(@event.errors.count, "error")} prohibited this recurrence from being saved:"
65
+ %ul
66
+ - @event.errors.full_messages.each do |msg|
67
+ %li= msg
68
+
69
+ .field
70
+ .field
71
+ = f.label :repeats
72
+ = f.select :repeats, Event.schemes
73
+
74
+ - if flash[:interval]
75
+ .field
76
+ = f.label :repeats_every
77
+ = f.select :interval, 1..52, :class => :left
78
+ = @recurs_template[1]
79
+
80
+ = render :partial => "recurrences/schemes/#{@recurs_template[0]}"
81
+
82
+ .field
83
+ = f.label :starts_at
84
+ = f.datetime_select :starts_at
85
+ .field
86
+ = f.label :ends_at
87
+ = f.datetime_select :ends_at
88
+ .field
89
+ = f.label :never_ends
90
+ = f.check_box :never_ends
91
+ .field
92
+ = f.label :summary
93
+ = f.text_field :summary
94
+ .actions
95
+ = f.submit 'Save'
96
+ """
97
+ And the file "app/views/events/edit.html.haml" should contain exactly:
98
+ """
99
+ %h1 Edit event
100
+
101
+ = render 'form'
102
+
103
+ = link_to 'Show', @event
104
+ \|
105
+ = link_to 'Back', events_path
106
+ """
107
+ And the file "app/views/events/index.html.haml" should contain exactly:
108
+ """
109
+ %h1 Listing events
110
+
111
+ %table
112
+ %tr
113
+ %th Starts on
114
+ %th Ends on date
115
+ %th Recurrence
116
+ %th Summary
117
+ %th
118
+ %th
119
+ %th
120
+
121
+ - @events.each do |event|
122
+ %tr
123
+ %td= event.starts_at
124
+ %td= event.ends_at
125
+ %td= event.rrule
126
+ %td= event.summary
127
+ %td= link_to 'Show', event
128
+ %td= link_to 'Edit', edit_event_path(event)
129
+ %td= link_to 'Destroy', event, :confirm => 'Are you sure?', :method => :delete
130
+
131
+ %br
132
+
133
+ = link_to 'New event', new_event_path
134
+ """
135
+ And the file "app/controllers/events_controller.rb" should contain exactly:
136
+ """
137
+ class EventsController < ApplicationController
138
+ # GET /events
139
+ # GET /events.xml
140
+ def index
141
+ @events = Event.all
142
+
143
+ respond_to do |format|
144
+ format.html # index.html.erb
145
+ format.xml { render :xml => @events }
146
+ end
147
+ end
148
+
149
+ # GET /events/1
150
+ # GET /events/1.xml
151
+ def show
152
+ @event = Event.find(params[:id])
153
+
154
+ respond_to do |format|
155
+ format.html # show.html.erb
156
+ format.xml { render :xml => @event }
157
+ end
158
+ end
159
+
160
+ # GET /events/new
161
+ # GET /events/new.xml
162
+ def new
163
+ @event = Event.new
164
+ if flash[:repeats]
165
+ flash[:scheme] = flash[:repeats]
166
+ @event_template = Event.scheme(flash[:repeats]).call
167
+ end
168
+
169
+ respond_to do |format|
170
+ format.html # new.html.erb
171
+ format.xml { render :xml => @event }
172
+ end
173
+ end
174
+
175
+ # GET /events/1/edit
176
+ def edit
177
+ @event = Event.find(params[:id])
178
+ end
179
+
180
+ # POST /events
181
+ # POST /events.xml
182
+ def create
183
+ unless flash[:repeats]
184
+ flash[:repeats] = params[:event][:repeats].to_i
185
+ redirect_to new_event_path
186
+ else
187
+ #@event = Event.new(params[:event])
188
+ Event.scheme(flash[:scheme]).call(:set => params[:event])
189
+ end
190
+ end
191
+
192
+ # PUT /events/1
193
+ # PUT /events/1.xml
194
+ def update
195
+ @event = Event.find(params[:id])
196
+
197
+ respond_to do |format|
198
+ if @event.update_attributes(params[:event])
199
+ format.html { redirect_to(@event, :notice => 'Event was successfully updated.') }
200
+ format.xml { head :ok }
201
+ else
202
+ format.html { render :action => "edit" }
203
+ format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
204
+ end
205
+ end
206
+ end
207
+
208
+ # DELETE /events/1
209
+ # DELETE /events/1.xml
210
+ def destroy
211
+ @event = Event.find(params[:id])
212
+ @event.destroy
213
+
214
+ respond_to do |format|
215
+ format.html { redirect_to(events_url) }
216
+ format.xml { head :ok }
217
+ end
218
+ end
219
+ end
220
+ """
221
+ And the file "config/routes.rb" should contain "resources :events"
222
+ And the file that's name includes "create_events.rb" in "db/migrate" should contain exactly:
223
+ """
224
+ class CreateEvents < ActiveRecord::Migration
225
+ def self.up
226
+ create_table(:events) do |t|
227
+
228
+ t.timestamps
229
+ end
230
+
231
+ end
232
+
233
+ def self.down
234
+ drop_table :events
235
+ end
236
+ end
237
+ """
238
+ #And the following files should not exist:
239
+ #And I run "rake db:migrate"
@@ -266,6 +266,16 @@ Then /^the file "([^"]*)" should contain exactly:$/ do |file, exact_content|
266
266
  check_exact_file_content(file, exact_content)
267
267
  end
268
268
 
269
+ Then /^the migration file create_"([^"]*)"s.rb should contain exactly:$/ do |file, exact_content|
270
+ found = Dir.entries("#{current_dir}/db/migrate").select {|f| f if f.match(/\n*_create_#{file}s.rb/) }
271
+ check_exact_file_content("#{current_dir}/db/migrate/#{found.first}", exact_content)
272
+ end
273
+
274
+ Then /^the file that's name includes "([^"]*)" in "([^"]*)" should contain exactly:$/ do |file, folder, exact_content|
275
+ found = Dir.entries("#{current_dir}/#{folder}").select {|f| f if f.match(/\S*#{file}\S*/) }
276
+ check_exact_file_content("#{current_dir}/#{folder}/#{found.first}", exact_content)
277
+ end
278
+
269
279
  Then /^the file "([^"]*)" should match \/([^\/]*)\/$/ do |file, partial_content|
270
280
  check_file_content(file, /#{partial_content}/, true)
271
281
  end
@@ -49,6 +49,14 @@ module Aruba
49
49
  end
50
50
  end
51
51
 
52
+ def check_exact_migration_file_content(file, exact_content)
53
+ #in_current_dir do
54
+ #prep_for_fs_check do
55
+ found = Dir.entries("#{current_dir}/db/migrate").select {|f| f if f.match(/\n*_create_#{file}s.rb/) }
56
+ check_exact_file_content("#{current_dir}/db/migrate/#{found}", exact_content)
57
+ #end
58
+ end
59
+
52
60
  def check_file_presence(paths, expect_presence)
53
61
  prep_for_fs_check do
54
62
  paths.each do |path|
@@ -1,26 +1,42 @@
1
- module Recurs
2
- class WidgetGenerator < Rails::Generators::Base
1
+ #module
2
+ #require 'rails/generators/migration'
3
+ require 'rails/generators/active_record'
4
+ class RecursWidgetGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ #include Actic::Generator
3
7
  source_root File.expand_path("../templates", __FILE__)
4
8
  argument :name, :type => :string, :default => "event"
9
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
5
10
 
6
11
  def create_instance_model
7
- template "instance.rb.tmpl", "app/models/#{name}.rb"
12
+ template "instance.rb.tmpl", "app/models/#{name.downcase}.rb"
8
13
  #create_file "app/models#{model_name}"
9
14
  end
10
15
 
11
16
  def create_instance_views
12
17
  ['index', 'show', 'edit', 'new', '_form'].each {|v|
13
- template "views/#{v}", "app/views/#{name.downcase}/#{v}.html.haml"
18
+ template "views/#{v}", "app/views/#{name.downcase}s/#{v}.html.haml"
19
+ }
20
+ ['_monthly', '_set_points', '_standard', '_weekly'].each {|v|
21
+ template "views/schemes/#{v}", "app/views/#{name.downcase}s/schemes/#{v}.html.haml"
14
22
  }
15
23
  end
16
24
 
17
25
  def create_instance_route
18
- insert_into_file 'config/routes.rb'
26
+ insert_into_file 'config/routes.rb', "resources :#{name.downcase}s", :after => "Application.routes.draw do\n"
19
27
  end
20
28
 
21
29
  def create_instance_controller
30
+ template "controller.rb.tmpl", "app/controllers/#{name.downcase}s_controller.rb"
31
+ end
32
+
33
+ def self.next_migration_number(dirname)
34
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
35
+ end
22
36
 
37
+ def create_migration_file
38
+ migration_template 'migration.rb.tmpl', "db/migrate/create_#{name.downcase}s.rb"
23
39
  end
24
40
 
25
41
  end
26
- end
42
+ #end
@@ -0,0 +1,83 @@
1
+ class <%= name %>sController < ApplicationController
2
+ # GET /<%= dname = name.downcase %>s
3
+ # GET /<%= dname %>s.xml
4
+ def index
5
+ @<%= dname %>s = <%= name %>.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @<%= dname %>s }
10
+ end
11
+ end
12
+
13
+ # GET /<%= dname %>s/1
14
+ # GET /<%= dname %>s/1.xml
15
+ def show
16
+ @<%= dname %> = <%= name %>.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @<%= dname %> }
21
+ end
22
+ end
23
+
24
+ # GET /<%= dname %>s/new
25
+ # GET /<%= dname %>s/new.xml
26
+ def new
27
+ @<%= dname %> = <%= name %>.new
28
+ if flash[:repeats]
29
+ flash[:scheme] = flash[:repeats]
30
+ @<%= dname %>_template = <%= name %>.scheme(flash[:repeats]).call
31
+ end
32
+
33
+ respond_to do |format|
34
+ format.html # new.html.erb
35
+ format.xml { render :xml => @<%= dname %> }
36
+ end
37
+ end
38
+
39
+ # GET /<%= dname %>s/1/edit
40
+ def edit
41
+ @<%= dname %> = <%= name %>.find(params[:id])
42
+ end
43
+
44
+ # POST /<%= dname %>s
45
+ # POST /<%= dname %>s.xml
46
+ def create
47
+ unless flash[:repeats]
48
+ flash[:repeats] = params[:<%= dname %>][:repeats].to_i
49
+ redirect_to new_<%= dname %>_path
50
+ else
51
+ #@<%= dname %> = <%= name %>.new(params[:<%= dname %>])
52
+ <%= name %>.scheme(flash[:scheme]).call(:set => params[:<%= dname %>])
53
+ end
54
+ end
55
+
56
+ # PUT /<%= dname %>s/1
57
+ # PUT /<%= dname %>s/1.xml
58
+ def update
59
+ @<%= dname %> = <%= name %>.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @<%= dname %>.update_attributes(params[:<%= dname %>])
63
+ format.html { redirect_to(@<%= dname %>, :notice => '<%= name %> was successfully updated.') }
64
+ format.xml { head :ok }
65
+ else
66
+ format.html { render :action => "edit" }
67
+ format.xml { render :xml => @<%= dname %>.errors, :status => :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /<%= dname %>s/1
73
+ # DELETE /<%= dname %>s/1.xml
74
+ def destroy
75
+ @<%= dname %> = <%= name %>.find(params[:id])
76
+ @<%= dname %>.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to(<%= dname %>s_url) }
80
+ format.xml { head :ok }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,17 @@
1
+ class Create<%= name.camelize %>s < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= name.downcase %>s) do |t|
4
+ <% if attributes %>
5
+ <% for attribute in attributes -%>
6
+ t.<%= attribute[:type] %> :<%= attribute[:name] %>
7
+ <% end -%>
8
+ <% end -%>
9
+ t.timestamps
10
+ end
11
+
12
+ end
13
+
14
+ def self.down
15
+ drop_table :<%= name.downcase %>s
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ = form_for @<%= dname = name.downcase %> do |f|
2
+ -if @<%= dname %>.errors.any?
3
+ #errorExplanation
4
+ %h2= "#{pluralize(@<%= dname %>.errors.count, "error")} prohibited this recurrence from being saved:"
5
+ %ul
6
+ - @<%= dname %>.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ .field
10
+ .field
11
+ = f.label :repeats
12
+ = f.select :repeats, Event.schemes
13
+
14
+ - if flash[:interval]
15
+ .field
16
+ = f.label :repeats_every
17
+ = f.select :interval, 1..52, :class => :left
18
+ = @recurs_template[1]
19
+
20
+ = render :partial => "recurrences/schemes/#{@recurs_template[0]}"
21
+
22
+ .field
23
+ = f.label :starts_at
24
+ = f.datetime_select :starts_at
25
+ .field
26
+ = f.label :ends_at
27
+ = f.datetime_select :ends_at
28
+ .field
29
+ = f.label :never_ends
30
+ = f.check_box :never_ends
31
+ .field
32
+ = f.label :summary
33
+ = f.text_field :summary
34
+ .actions
35
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Edit <%= name.downcase %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @<%= name.downcase %>
6
+ \|
7
+ = link_to 'Back', <%= name.downcase %>s_path
@@ -0,0 +1,25 @@
1
+ %h1 Listing <%= dname = name.downcase %>s
2
+
3
+ %table
4
+ %tr
5
+ %th Starts on
6
+ %th Ends on date
7
+ %th Recurrence
8
+ %th Summary
9
+ %th
10
+ %th
11
+ %th
12
+
13
+ - @<%= dname %>s.each do |<%= dname %>|
14
+ %tr
15
+ %td= <%= dname %>.starts_at
16
+ %td= <%= dname %>.ends_at
17
+ %td= <%= dname %>.rrule
18
+ %td= <%= dname %>.summary
19
+ %td= link_to 'Show', <%= dname %>
20
+ %td= link_to 'Edit', edit_<%= dname %>_path(<%= dname %>)
21
+ %td= link_to 'Destroy', <%= dname %>, :confirm => 'Are you sure?', :method => :delete
22
+
23
+ %br
24
+
25
+ = link_to 'New <%= dname %>', new_<%= dname %>_path
@@ -0,0 +1,5 @@
1
+ %h1 New <%= name.downcase %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= name.downcase %>s_path
File without changes
File without changes
File without changes
File without changes
data/lib/recurs.rb CHANGED
@@ -8,7 +8,7 @@ module Recurs
8
8
  module Parser
9
9
 
10
10
  def self.included(base)
11
- base.send :extend, ClassMethods
11
+ base.send :extend, ModelMethods
12
12
  end
13
13
 
14
14
  class << self
@@ -192,9 +192,17 @@ module Recurs
192
192
 
193
193
  end
194
194
 
195
- module ClassMethods
195
+ module ModelMethods
196
196
  def acts_as_recurring
197
197
  send :include, InstanceMethods
198
+ send :extend, ModelClassMethods
199
+ end
200
+
201
+ end
202
+
203
+ module ModelClassMethods
204
+ def schemes
205
+ Recurs::Rules.schemes
198
206
  end
199
207
  end
200
208
 
@@ -1,3 +1,3 @@
1
1
  module Recurs
2
- VERSION = "0.0.4.2"
2
+ VERSION = "0.0.4.3"
3
3
  end
@@ -15,6 +15,18 @@ describe Event do
15
15
  @event.recurs
16
16
  end
17
17
 
18
+ it "should have the schemes" do
19
+ Event.schemes.should == ["Daily",
20
+ "Every Weekday ( Mon - Fri )",
21
+ "Every Mon, Wed, Fri",
22
+ "Every Tues, Thurs",
23
+ "Every Weekend",
24
+ "Weekly",
25
+ "Monthly",
26
+ "Yearly"]
27
+
28
+ end
29
+
18
30
  it "should add an rrule" do
19
31
  @event.add_rrule(:daily).should == "RRULE:FREQ=DAILY"
20
32
  @event.recurs.should == "RRULE:FREQ=DAILY"
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.0.4.2
9
+ - 3
10
+ version: 0.0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Caney Martin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-15 00:00:00 +00:00
18
+ date: 2010-12-16 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -124,6 +124,16 @@ files:
124
124
  - lib/generators/recurs_widget_generator.rb
125
125
  - lib/generators/templates/controller.rb.tmpl
126
126
  - lib/generators/templates/instance.rb.tmpl
127
+ - lib/generators/templates/migration.rb.tmpl
128
+ - lib/generators/templates/views/_form
129
+ - lib/generators/templates/views/edit
130
+ - lib/generators/templates/views/index
131
+ - lib/generators/templates/views/new
132
+ - lib/generators/templates/views/schemes/_monthly
133
+ - lib/generators/templates/views/schemes/_set_points
134
+ - lib/generators/templates/views/schemes/_standard
135
+ - lib/generators/templates/views/schemes/_weekly
136
+ - lib/generators/templates/views/show
127
137
  - lib/recurs.rb
128
138
  - lib/recurs/consts.rb
129
139
  - lib/recurs/rules.rb