qcourses 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/db/migrations/003_add_closed_state_and_max_participants_to_event.rb +15 -0
- data/lib/qcourses/configuration.rb +3 -0
- data/lib/qcourses/controllers/events_controller.rb +17 -4
- data/lib/qcourses/models/event.rb +4 -0
- data/lib/qcourses/models.rb +2 -1
- data/lib/qcourses/resource_paths.rb +2 -2
- data/lib/qcourses/view_helpers.rb +5 -2
- data/lib/qcourses.rb +3 -0
- data/spec/qcourses/controllers/events_controller_spec.rb +32 -1
- data/spec/qcourses/view_helpers_spec.rb +2 -1
- data/views/events/admin_index.haml +4 -0
- data/views/events/admin_list.haml +21 -0
- data/views/events/edit.haml +9 -3
- data/views/events/new.haml +8 -6
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
alter_table(:events) do
|
4
|
+
add_column :open, :boolean, default: true
|
5
|
+
add_column :max_participants, :integer, default: 14
|
6
|
+
add_index :open
|
7
|
+
end
|
8
|
+
end
|
9
|
+
down do
|
10
|
+
alter_table(:events) do
|
11
|
+
drop_column :max_participants
|
12
|
+
drop_column :open
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -5,7 +5,7 @@ module Qcourses
|
|
5
5
|
get request_url do
|
6
6
|
begin
|
7
7
|
CourseRepository.all
|
8
|
-
@events = Event.
|
8
|
+
@events = Event.planned
|
9
9
|
haml :'events/index', layout: false
|
10
10
|
rescue Exception => e
|
11
11
|
haml :'trainings/error', locals: { message: e.message }
|
@@ -15,8 +15,8 @@ module Qcourses
|
|
15
15
|
get admin_request_url do
|
16
16
|
begin
|
17
17
|
CourseRepository.all
|
18
|
-
@events = Event.
|
19
|
-
haml :'events/
|
18
|
+
@events = Event.order(:from)
|
19
|
+
haml :'events/admin_index', layout: :admin
|
20
20
|
rescue Exception => e
|
21
21
|
haml :'trainings/error', locals: { message: e.message }
|
22
22
|
end
|
@@ -25,7 +25,7 @@ module Qcourses
|
|
25
25
|
get admin_new_request_url do
|
26
26
|
begin
|
27
27
|
@event = Event.new
|
28
|
-
@events = Event.
|
28
|
+
@events = Event.order(:from)
|
29
29
|
haml :'events/new', layout: :admin
|
30
30
|
rescue Exception => e
|
31
31
|
haml :'trainings/error', locals: { message: e.message }
|
@@ -45,6 +45,19 @@ module Qcourses
|
|
45
45
|
@event = Event.create(event_params)
|
46
46
|
redirect admin_new_request_url
|
47
47
|
end
|
48
|
+
|
49
|
+
put admin_request_url(:id) do
|
50
|
+
begin
|
51
|
+
@event = Event.find(params[:id])
|
52
|
+
if @event.update event_params
|
53
|
+
redirect admin_request_url
|
54
|
+
else
|
55
|
+
haml :'events/edit', layout: :admin
|
56
|
+
end
|
57
|
+
rescue Exception => e
|
58
|
+
haml :'trainings/error', locals: { message: e.message }
|
59
|
+
end
|
60
|
+
end
|
48
61
|
|
49
62
|
private
|
50
63
|
def event_params
|
data/lib/qcourses/models.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'sequel'
|
2
2
|
require 'sequel/extensions/migration'
|
3
3
|
require 'yaml'
|
4
|
-
|
4
|
+
require 'logger'
|
5
5
|
module Qcourses
|
6
6
|
def self.db
|
7
7
|
@@db ||= create_connection
|
@@ -9,6 +9,7 @@ module Qcourses
|
|
9
9
|
def self.create_connection(environment = Qcourses.env)
|
10
10
|
environment = environment.to_s
|
11
11
|
connection = Sequel.connect(YAML::load(File.read(File.join(config.root, 'config', 'database.yml')))[environment])
|
12
|
+
connection.logger = Logger.new(Qcourses.log_file())
|
12
13
|
schema_definition.apply(connection, :up) if environment == 'test'
|
13
14
|
connection
|
14
15
|
end
|
@@ -22,8 +22,8 @@ module Qcourses
|
|
22
22
|
def edit_request_url(param = nil)
|
23
23
|
[basepath,'edit', param_symbol(param)].compact.join('/')
|
24
24
|
end
|
25
|
-
def admin_request_url
|
26
|
-
adminprefix + request_url
|
25
|
+
def admin_request_url(param = nil)
|
26
|
+
adminprefix + request_url(param)
|
27
27
|
end
|
28
28
|
def admin_new_request_url
|
29
29
|
adminprefix + new_request_url
|
@@ -44,6 +44,7 @@ module Qcourses
|
|
44
44
|
tag_classes << 'error' if object.errors.on(attribute_name)
|
45
45
|
tag_classes << klass if klass
|
46
46
|
tag_attributes[:class] = tag_classes.join(' ') unless tag_classes.empty?
|
47
|
+
tag_attributes.merge! options
|
47
48
|
result = haml("%input#{tag_attributes.inspect}")
|
48
49
|
result += haml("%span{:class => 'error'} #{object.errors.on(attribute_name).first}" ) if object.errors.on(attribute_name) && !suppress_error_messages
|
49
50
|
result
|
@@ -52,12 +53,14 @@ module Qcourses
|
|
52
53
|
def textarea_for(object, attribute_name, options={})
|
53
54
|
object = instance_variable_get("@#{object}") if object.is_a?(Symbol)
|
54
55
|
return '' unless object
|
56
|
+
klass = options.delete :class
|
55
57
|
tag_attributes = {:name => input_name(object, attribute_name, options[:array_element])}
|
56
58
|
value = object.send(attribute_name) || ''
|
57
59
|
tag_classes = []
|
58
60
|
tag_classes << 'error' if object.errors.on(attribute_name)
|
59
|
-
tag_classes <<
|
61
|
+
tag_classes << klass if klass
|
60
62
|
tag_attributes[:class] = tag_classes.join(' ') unless tag_classes.empty?
|
63
|
+
tag_attributes.merge! options
|
61
64
|
"<textarea #{text_hash(tag_attributes)}>#{value}</textarea>"
|
62
65
|
end
|
63
66
|
|
@@ -71,7 +74,7 @@ module Qcourses
|
|
71
74
|
tag_classes << klass if klass
|
72
75
|
tag_attributes = {:name => input_name(object, attribute_name, array_element)}
|
73
76
|
tag_attributes[:class] = tag_classes.join(' ') unless tag_classes.empty?
|
74
|
-
|
77
|
+
tag_attributes.merge! options
|
75
78
|
%Q{<select #{text_hash(tag_attributes)}>
|
76
79
|
#{options_for_select(opts_for_select, object.send(attribute_name).to_s)}
|
77
80
|
</select>}
|
data/lib/qcourses.rb
CHANGED
@@ -76,8 +76,9 @@ module Qcourses
|
|
76
76
|
event.update :course_id => course1.identification
|
77
77
|
get url
|
78
78
|
last_response.should be_ok
|
79
|
-
last_body.should have_selector("form#events[@method='
|
79
|
+
last_body.should have_selector("form#events[@method='post']")
|
80
80
|
last_body.find("form#events")['action'].should match("/admin/events/#{event.id}")
|
81
|
+
last_body.should have_selector("form#events input[@type='hidden'][@name='_method'][@value='put']")
|
81
82
|
last_body.should have_selector("form#events input[@name='event[from]'][@value='#{event.from.strftime("%d-%m-%Y")}']")
|
82
83
|
last_body.should have_selector("form#events input[@name='event[to]'][@value='#{event.to.strftime("%d-%m-%Y")}']")
|
83
84
|
last_body.should have_selector("form#events select[@name='event[course_id]'] option[@value='#{event.course_id}']")
|
@@ -113,6 +114,36 @@ module Qcourses
|
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
117
|
+
describe 'put admin' do
|
118
|
+
let!(:course1) { courses.create_course identification: 'agile_engineering', name: 'Agile Engineering' }
|
119
|
+
let (:event) { Rubory.create :event }
|
120
|
+
let (:url) { "/admin/events/#{event.id}" }
|
121
|
+
let (:event_parameters) { {from: Date.a_month_from_now.as_date_string, to: Date.a_month_from_now.as_date_string, location: 'Tilburg' } }
|
122
|
+
|
123
|
+
context "on valid parameters" do
|
124
|
+
it "should create an event" do
|
125
|
+
expect {
|
126
|
+
put url, event: event_parameters
|
127
|
+
}.to change {Event.count}.from(0).to(1)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should redirect back to list" do
|
131
|
+
put url, event: event_parameters
|
132
|
+
last_response.should be_redirect
|
133
|
+
follow_redirect!
|
134
|
+
last_request.url.should include('/admin/events')
|
135
|
+
end
|
136
|
+
|
137
|
+
it "uses an existing location when location id is not '0'" do
|
138
|
+
location = Location.create(name:"Tilburg")
|
139
|
+
event_parameters[:location_id] = location.id.to_s
|
140
|
+
event_parameters[:location] = ''
|
141
|
+
put url, event: event_parameters
|
142
|
+
Event.order(:id).last.location.should == location
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
116
147
|
end
|
117
148
|
|
118
149
|
end
|
@@ -105,8 +105,9 @@ module Qcourses
|
|
105
105
|
html_for(select_for(:employee, :company_id, options)).should have_selector("select[name='employee[company_id]'] option[value='99']", :text => "Other Company")
|
106
106
|
html_for(select_for(:employee, :company_id, options)).should have_selector("select[name='employee[company_id]'] option[value='#{@employee.company_id}'][selected='selected']", :text => "Company")
|
107
107
|
end
|
108
|
-
it 'can have a class' do
|
108
|
+
it 'can have a class and or id ' do
|
109
109
|
html_for(select_for(:employee, :company_id, nil, :class => 'short')).should have_selector("select[name='employee[company_id]'][class='short']")
|
110
|
+
html_for(select_for(:employee, :company_id, nil, :id => 'my_id')).should have_selector("select#my_id")
|
110
111
|
end
|
111
112
|
end
|
112
113
|
describe "on an array object" do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
%section.list
|
2
|
+
-if @events.empty?
|
3
|
+
.events no events planned
|
4
|
+
- else
|
5
|
+
.events
|
6
|
+
- @events.each do |event|
|
7
|
+
%div(id="event_#{event.id}" class='event')
|
8
|
+
.event_name
|
9
|
+
= event.name
|
10
|
+
.event_subtitle
|
11
|
+
= event.subtitle
|
12
|
+
.event_registration
|
13
|
+
%a{ :href=> url("/admin/events/edit/#{event.id}") } edit
|
14
|
+
%br
|
15
|
+
%a{ :href=> url("/admin/events/participants/#{event.id}") } participants
|
16
|
+
.event_date_location
|
17
|
+
= human_period event.from, event.to
|
18
|
+
%br
|
19
|
+
= event.location_name
|
20
|
+
.clear
|
21
|
+
|
data/views/events/edit.haml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
%h2 Edit event
|
1
2
|
%section.form
|
2
|
-
%form(id='events' action= "#{url admin_request_url}/#{@event.id}" method ='
|
3
|
+
%form(id='events' action= "#{url admin_request_url}/#{@event.id}" method ='post')
|
4
|
+
%input(type="hidden" name="_method" value="put")
|
3
5
|
.label
|
4
6
|
%label(for="event[course_id]") Course:
|
5
7
|
.input
|
@@ -12,11 +14,15 @@
|
|
12
14
|
%label(for="event[to]") To:
|
13
15
|
.input
|
14
16
|
= input_for :event, :to, :time_format => "%d-%m-%Y", :class => "date"
|
17
|
+
.label
|
18
|
+
%label(for="event[max_participants]") Max participants:
|
19
|
+
.input
|
20
|
+
= input_for :event, :max_participants
|
15
21
|
#location_selector{ :style => display_if_locations }
|
16
22
|
.label
|
17
23
|
%label(for="event[location_id]") Where
|
18
24
|
.input
|
19
|
-
= select_for :event, :location_id, location_options
|
25
|
+
= select_for :event, :location_id, location_options, :id => :event_location
|
20
26
|
#location_name{ :style => display_unless_locations }
|
21
27
|
.label
|
22
28
|
%label(for="event[location]") New location name
|
@@ -25,6 +31,6 @@
|
|
25
31
|
|
26
32
|
.label
|
27
33
|
.input
|
28
|
-
%input{:type => "submit", :value => "
|
34
|
+
%input{:type => "submit", :value => "update event" }
|
29
35
|
%span.clear
|
30
36
|
|
data/views/events/new.haml
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
1
|
+
%h2 Planning events
|
2
2
|
%section.form
|
3
3
|
%form(id='events' action= "#{admin_request_url}" method ='post')
|
4
4
|
.label
|
5
5
|
%label(for="event[course_id]") Course:
|
6
6
|
.input
|
7
|
-
|
8
|
-
= course_options
|
7
|
+
= select_for :event, :course_id, course_options
|
9
8
|
.label
|
10
9
|
%label(for="event[from]") From:
|
11
10
|
.input
|
@@ -14,12 +13,15 @@
|
|
14
13
|
%label(for="event[to]") To:
|
15
14
|
.input
|
16
15
|
%input{:type => "text", :name => "event[to]", :class => "date"}
|
16
|
+
.label
|
17
|
+
%label(for="event[max_participants]") Max participants:
|
18
|
+
.input
|
19
|
+
= input_for :event, :max_participants
|
17
20
|
#location_selector{ :style => display_if_locations }
|
18
21
|
.label
|
19
22
|
%label(for="event[location_id]") Where
|
20
23
|
.input
|
21
|
-
|
22
|
-
= location_options
|
24
|
+
= select_for :event, :location_id, location_options, :id => :event_location
|
23
25
|
#location_name{ :style => display_unless_locations }
|
24
26
|
.label
|
25
27
|
%label(for="event[location]") New location name
|
@@ -31,4 +33,4 @@
|
|
31
33
|
%input{:type => "submit", :value => "plan event" }
|
32
34
|
%span.clear
|
33
35
|
|
34
|
-
= haml :'/events/
|
36
|
+
= haml :'/events/admin_list', :layout => false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qcourses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- config.ru
|
240
240
|
- db/migrations/001_initial_database.rb
|
241
241
|
- db/migrations/002_create_registrations.rb
|
242
|
+
- db/migrations/003_add_closed_state_and_max_participants_to_event.rb
|
242
243
|
- demo_app.rb
|
243
244
|
- lib/factories.rb
|
244
245
|
- lib/qcourses.rb
|
@@ -284,6 +285,8 @@ files:
|
|
284
285
|
- spec/support/request_specs.rb
|
285
286
|
- spec/support/test_files.rb
|
286
287
|
- views/admin.haml
|
288
|
+
- views/events/admin_index.haml
|
289
|
+
- views/events/admin_list.haml
|
287
290
|
- views/events/edit.haml
|
288
291
|
- views/events/index.haml
|
289
292
|
- views/events/new.haml
|
@@ -329,7 +332,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
329
332
|
version: '0'
|
330
333
|
segments:
|
331
334
|
- 0
|
332
|
-
hash:
|
335
|
+
hash: 12649459
|
333
336
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
334
337
|
none: false
|
335
338
|
requirements:
|