qcourses 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/autospec +16 -0
- data/bin/autotest +16 -0
- data/bin/haml +16 -0
- data/bin/html2haml +16 -0
- data/bin/htmldiff +16 -0
- data/bin/jeweler +16 -0
- data/bin/ldiff +16 -0
- data/bin/multigem +16 -0
- data/bin/multiruby +16 -0
- data/bin/multiruby_setup +16 -0
- data/bin/nokogiri +16 -0
- data/bin/rackup +16 -0
- data/bin/rake +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/sequel +16 -0
- data/bin/tilt +16 -0
- data/bin/unit_diff +16 -0
- data/bin/zentest +16 -0
- data/lib/qcourses/controllers/events_controller.rb +9 -0
- data/lib/qcourses/resource_paths.rb +6 -0
- data/lib/qcourses/view_helpers.rb +38 -8
- data/spec/qcourses/controllers/events_controller_spec.rb +19 -1
- data/spec/qcourses/controllers/registrations_controller_spec.rb +19 -17
- data/spec/qcourses/view_helpers_spec.rb +29 -0
- data/spec/support/request_specs.rb +1 -1
- data/views/events/edit.haml +30 -0
- metadata +42 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/autospec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'autospec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'autospec')
|
data/bin/autotest
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'autotest' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('ZenTest', 'autotest')
|
data/bin/haml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'haml' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('haml', 'haml')
|
data/bin/html2haml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'html2haml' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('haml', 'html2haml')
|
data/bin/htmldiff
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'htmldiff' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('diff-lcs', 'htmldiff')
|
data/bin/jeweler
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'jeweler' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('jeweler', 'jeweler')
|
data/bin/ldiff
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'ldiff' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('diff-lcs', 'ldiff')
|
data/bin/multigem
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'multigem' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('ZenTest', 'multigem')
|
data/bin/multiruby
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'multiruby' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('ZenTest', 'multiruby')
|
data/bin/multiruby_setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'multiruby_setup' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('ZenTest', 'multiruby_setup')
|
data/bin/nokogiri
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'nokogiri' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('nokogiri', 'nokogiri')
|
data/bin/rackup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rackup' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rack', 'rackup')
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/ri
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'ri' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rdoc', 'ri')
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/sequel
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'sequel' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('sequel', 'sequel')
|
data/bin/tilt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'tilt' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('tilt', 'tilt')
|
data/bin/unit_diff
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'unit_diff' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('ZenTest', 'unit_diff')
|
data/bin/zentest
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'zentest' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('ZenTest', 'zentest')
|
@@ -32,6 +32,15 @@ module Qcourses
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
get admin_edit_request_url(:id) do
|
36
|
+
begin
|
37
|
+
@event = Event.find(params[:id])
|
38
|
+
haml :'events/edit', layout: :admin
|
39
|
+
rescue Exception => e
|
40
|
+
haml :'trainings/error', locals: { message: e.message }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
35
44
|
post admin_request_url do
|
36
45
|
@event = Event.create(event_params)
|
37
46
|
redirect admin_new_request_url
|
@@ -19,12 +19,18 @@ module Qcourses
|
|
19
19
|
def new_request_url(param = nil)
|
20
20
|
[request_url, 'new', param_symbol(param)].compact.join('/')
|
21
21
|
end
|
22
|
+
def edit_request_url(param = nil)
|
23
|
+
[basepath,'edit', param_symbol(param)].compact.join('/')
|
24
|
+
end
|
22
25
|
def admin_request_url
|
23
26
|
adminprefix + request_url
|
24
27
|
end
|
25
28
|
def admin_new_request_url
|
26
29
|
adminprefix + new_request_url
|
27
30
|
end
|
31
|
+
def admin_edit_request_url(param)
|
32
|
+
adminprefix + edit_request_url(param)
|
33
|
+
end
|
28
34
|
private
|
29
35
|
def param_symbol(param)
|
30
36
|
param && param.inspect || param
|
@@ -1,13 +1,18 @@
|
|
1
1
|
module Qcourses
|
2
2
|
module ViewHelpers
|
3
|
-
def options_for_select options
|
4
|
-
|
3
|
+
def options_for_select options, value
|
4
|
+
return '' unless options
|
5
|
+
options.collect do |option|
|
6
|
+
tag_attributes = {:value => option[0]}
|
7
|
+
tag_attributes[:selected] = "selected" if value == option[0]
|
8
|
+
haml "%option#{tag_attributes.inspect} #{option[1]}", :layout => false
|
9
|
+
end.join
|
5
10
|
end
|
6
11
|
def course_options
|
7
|
-
|
12
|
+
CourseRepository.all.collect { |course| [course.identification, course.name] }
|
8
13
|
end
|
9
14
|
def location_options
|
10
|
-
|
15
|
+
Location.all.collect { |location| [location.id, location.name] } + [['0', 'new location']]
|
11
16
|
end
|
12
17
|
def display_if_locations
|
13
18
|
Location.all.empty? && "display:none;" || "display:block"
|
@@ -29,14 +34,18 @@ module Qcourses
|
|
29
34
|
def input_for(object, attribute_name, options={})
|
30
35
|
object = instance_variable_get("@#{object}") if object.is_a?(Symbol)
|
31
36
|
return '' unless object
|
32
|
-
|
33
|
-
|
37
|
+
array_element = options.delete :array_element
|
38
|
+
klass = options.delete :class
|
39
|
+
suppress_error_messages = options.delete :suppress_error_messages
|
40
|
+
date_format = options.delete :time_format
|
41
|
+
tag_attributes = {:type => 'text', :name => input_name(object, attribute_name, array_element)}
|
42
|
+
tag_attributes[:value] = format_value(object.send(attribute_name), date_format)
|
34
43
|
tag_classes = []
|
35
44
|
tag_classes << 'error' if object.errors.on(attribute_name)
|
36
|
-
tag_classes <<
|
45
|
+
tag_classes << klass if klass
|
37
46
|
tag_attributes[:class] = tag_classes.join(' ') unless tag_classes.empty?
|
38
47
|
result = haml("%input#{tag_attributes.inspect}")
|
39
|
-
result += haml("%span{:class => 'error'} #{object.errors.on(attribute_name).first}" ) if object.errors.on(attribute_name) && !
|
48
|
+
result += haml("%span{:class => 'error'} #{object.errors.on(attribute_name).first}" ) if object.errors.on(attribute_name) && !suppress_error_messages
|
40
49
|
result
|
41
50
|
end
|
42
51
|
|
@@ -52,7 +61,28 @@ module Qcourses
|
|
52
61
|
"<textarea #{text_hash(tag_attributes)}>#{value}</textarea>"
|
53
62
|
end
|
54
63
|
|
64
|
+
def select_for(object, attribute_name, opts_for_select=[], options={})
|
65
|
+
object = instance_variable_get("@#{object}") if object.is_a?(Symbol)
|
66
|
+
return '' unless object
|
67
|
+
array_element = options.delete :array_element
|
68
|
+
klass = options.delete :class
|
69
|
+
tag_classes = []
|
70
|
+
tag_classes << 'error' if object.errors.on(attribute_name)
|
71
|
+
tag_classes << klass if klass
|
72
|
+
tag_attributes = {:name => input_name(object, attribute_name, array_element)}
|
73
|
+
tag_attributes[:class] = tag_classes.join(' ') unless tag_classes.empty?
|
74
|
+
|
75
|
+
%Q{<select #{text_hash(tag_attributes)}>
|
76
|
+
#{options_for_select(opts_for_select, object.send(attribute_name).to_s)}
|
77
|
+
</select>}
|
78
|
+
end
|
79
|
+
|
55
80
|
private
|
81
|
+
def format_value(value, date_format)
|
82
|
+
return '' unless value
|
83
|
+
return value.strftime(date_format) if date_format && (value.is_a?(Time) || value.is_a?(Date))
|
84
|
+
return value.to_s
|
85
|
+
end
|
56
86
|
def text_hash(hash)
|
57
87
|
hash.to_a.map {|e| "#{e[0]}=\"#{e[1]}\"" }.join(' ')
|
58
88
|
end
|
@@ -58,7 +58,8 @@ module Qcourses
|
|
58
58
|
it "should render a form" do
|
59
59
|
get url
|
60
60
|
last_response.should be_ok
|
61
|
-
last_body.should have_selector("form#events[@method='post']
|
61
|
+
last_body.should have_selector("form#events[@method='post']")
|
62
|
+
last_body.find("form#events")['action'].should match('/admin/events')
|
62
63
|
last_body.should have_selector("form#events select[@name='event[course_id]']")
|
63
64
|
last_body.should have_selector("form#events input[@name='event[from]']")
|
64
65
|
last_body.should have_selector("form#events input[@name='event[to]']")
|
@@ -66,6 +67,23 @@ module Qcourses
|
|
66
67
|
it_should_behave_like "an_event_lister"
|
67
68
|
end
|
68
69
|
|
70
|
+
describe 'get admin edit' do
|
71
|
+
let!(:course1) { courses.create_course identification: 'agile_engineering', name: 'Agile Engineering' }
|
72
|
+
let (:event) { Rubory.create :event }
|
73
|
+
let (:url) { "/admin/events/edit/#{event.id}" }
|
74
|
+
|
75
|
+
it "should render a form" do
|
76
|
+
event.update :course_id => course1.identification
|
77
|
+
get url
|
78
|
+
last_response.should be_ok
|
79
|
+
last_body.should have_selector("form#events[@method='put']")
|
80
|
+
last_body.find("form#events")['action'].should match("/admin/events/#{event.id}")
|
81
|
+
last_body.should have_selector("form#events input[@name='event[from]'][@value='#{event.from.strftime("%d-%m-%Y")}']")
|
82
|
+
last_body.should have_selector("form#events input[@name='event[to]'][@value='#{event.to.strftime("%d-%m-%Y")}']")
|
83
|
+
last_body.should have_selector("form#events select[@name='event[course_id]'] option[@value='#{event.course_id}']")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
69
87
|
describe 'post admin' do
|
70
88
|
let (:url) { '/admin/events' }
|
71
89
|
let (:last_body) { last_response.body }
|
@@ -1,38 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'capybara/rspec'
|
3
|
-
|
4
3
|
module Qcourses
|
5
4
|
|
6
5
|
describe RegistrationsController, :type => :request do
|
6
|
+
include Sinatra::Helpers
|
7
7
|
let(:app) { Capybara.app = RegistrationsController }
|
8
8
|
let(:event) { Rubory.create :event }
|
9
|
+
let!(:courses) { CourseRepository.in_memory }
|
9
10
|
|
10
11
|
describe 'get new' do
|
11
|
-
def
|
12
|
+
def get_url(id)
|
12
13
|
"/registrations/new/#{id}"
|
13
14
|
end
|
14
15
|
|
15
16
|
it "should render a form" do
|
16
|
-
get
|
17
|
+
get get_url(event.id)
|
17
18
|
last_response.should be_ok
|
18
|
-
last_body.should have_selector("form#registrations[@method='post']
|
19
|
+
last_body.should have_selector("form#registrations[@method='post']")
|
20
|
+
last_body.find("form#registrations")['action'].should match("/registrations/#{event.id}")
|
19
21
|
end
|
20
22
|
|
21
23
|
it "should return a 404 when event is not available" do
|
22
|
-
get
|
24
|
+
get get_url(event.id + 33334)
|
23
25
|
last_response.should be_not_found
|
24
26
|
end
|
25
27
|
|
26
28
|
it "should return a 404 when event is in the past" do
|
27
29
|
event.update :from => Date.today
|
28
|
-
get
|
30
|
+
get get_url(event.id)
|
29
31
|
last_response.should be_not_found
|
30
32
|
end
|
31
33
|
|
32
34
|
end
|
33
35
|
|
34
36
|
describe 'post registration' do
|
35
|
-
def
|
37
|
+
def post_url(id)
|
36
38
|
"/registrations/#{id}"
|
37
39
|
end
|
38
40
|
|
@@ -43,43 +45,43 @@ module Qcourses
|
|
43
45
|
|
44
46
|
context "on valid attributes" do
|
45
47
|
it "redirects to thank you" do
|
46
|
-
post
|
48
|
+
post post_url(event.id), valid_registration
|
47
49
|
last_response.should be_redirect
|
48
50
|
follow_redirect!
|
49
51
|
last_body.should have_selector(".thanks")
|
50
52
|
end
|
51
53
|
it "creates a registration" do
|
52
|
-
expect { post
|
54
|
+
expect { post post_url(event.id), valid_registration }.to change { Registration.count }.by(1)
|
53
55
|
end
|
54
56
|
it "creates a company" do
|
55
|
-
expect { post
|
57
|
+
expect { post post_url(event.id), valid_registration }.to change { Company.count }.by(1)
|
56
58
|
end
|
57
59
|
it "creates an employee" do
|
58
|
-
expect { post
|
60
|
+
expect { post post_url(event.id), valid_registration }.to change { Employee.count }.by(1)
|
59
61
|
end
|
60
62
|
context "with more employees" do
|
61
63
|
let!(:another_participant) { Rubory.attributes_for :employee }
|
62
64
|
let(:participants) { [valid_participant, another_participant] }
|
63
65
|
it "creates more registrations" do
|
64
|
-
expect { post
|
66
|
+
expect { post post_url(event.id), valid_registration }.to change { Registration.count }.by(2)
|
65
67
|
end
|
66
68
|
it "creates a company" do
|
67
|
-
expect { post
|
69
|
+
expect { post post_url(event.id), valid_registration }.to change { Company.count }.by(1)
|
68
70
|
end
|
69
71
|
it "creates more employees" do
|
70
|
-
expect { post
|
72
|
+
expect { post post_url(event.id), valid_registration }.to change { Employee.count }.by(2)
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
context "problems with event" do
|
75
77
|
it "should return a 404 when event is not available" do
|
76
|
-
post
|
78
|
+
post post_url(event.id + 33334)
|
77
79
|
last_response.should be_not_found
|
78
80
|
end
|
79
81
|
|
80
82
|
it "should return a 404 when event is in the past" do
|
81
83
|
event.update :from => Date.today
|
82
|
-
post
|
84
|
+
post post_url(event.id)
|
83
85
|
last_response.should be_not_found
|
84
86
|
end
|
85
87
|
end
|
@@ -87,7 +89,7 @@ module Qcourses
|
|
87
89
|
context "participant invalid" do
|
88
90
|
it "shows error on attribute" do
|
89
91
|
valid_participant[:email] = ''
|
90
|
-
post
|
92
|
+
post post_url(event.id), valid_registration
|
91
93
|
last_response.should be_ok
|
92
94
|
last_body.should have_selector("form input.error[name='employee[][email]']")
|
93
95
|
end
|
@@ -86,5 +86,34 @@ module Qcourses
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
|
+
describe "select_for" do
|
90
|
+
def html_for(result)
|
91
|
+
Capybara.string(result)
|
92
|
+
end
|
93
|
+
before do
|
94
|
+
@employee = Rubory.build :employee
|
95
|
+
@employee.valid?
|
96
|
+
end
|
97
|
+
describe "on an existing object" do
|
98
|
+
it 'creates a select tag' do
|
99
|
+
html_for(select_for(:employee, :company_id)).should have_selector("select[name='employee[company_id]']")
|
100
|
+
html_for(select_for(@employee, :company_id)).should have_selector("select[name='employee[company_id]']")
|
101
|
+
end
|
102
|
+
it 'creates a options' do
|
103
|
+
options = [["99", "Other Company"]]
|
104
|
+
options << [@employee.company_id.to_s, "Company"]
|
105
|
+
html_for(select_for(:employee, :company_id, options)).should have_selector("select[name='employee[company_id]'] option[value='99']", :text => "Other Company")
|
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
|
+
end
|
108
|
+
it 'can have a class' do
|
109
|
+
html_for(select_for(:employee, :company_id, nil, :class => 'short')).should have_selector("select[name='employee[company_id]'][class='short']")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
describe "on an array object" do
|
113
|
+
it "creates an input tag with an extra [] inthe name" do
|
114
|
+
html_for(select_for(:employee, :company_id, nil, :array_element=>true)).should have_selector("select[name='employee[][company_id]']")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
89
118
|
end
|
90
119
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
%section.form
|
2
|
+
%form(id='events' action= "#{url admin_request_url}/#{@event.id}" method ='put')
|
3
|
+
.label
|
4
|
+
%label(for="event[course_id]") Course:
|
5
|
+
.input
|
6
|
+
= select_for :event, :course_id, course_options
|
7
|
+
.label
|
8
|
+
%label(for="event[from]") From:
|
9
|
+
.input
|
10
|
+
= input_for :event, :from, :time_format => "%d-%m-%Y", :class => "date"
|
11
|
+
.label
|
12
|
+
%label(for="event[to]") To:
|
13
|
+
.input
|
14
|
+
= input_for :event, :to, :time_format => "%d-%m-%Y", :class => "date"
|
15
|
+
#location_selector{ :style => display_if_locations }
|
16
|
+
.label
|
17
|
+
%label(for="event[location_id]") Where
|
18
|
+
.input
|
19
|
+
= select_for :event, :location_id, location_options
|
20
|
+
#location_name{ :style => display_unless_locations }
|
21
|
+
.label
|
22
|
+
%label(for="event[location]") New location name
|
23
|
+
.input
|
24
|
+
%input{:type => "text", :name => "event[location]"}
|
25
|
+
|
26
|
+
.label
|
27
|
+
.input
|
28
|
+
%input{:type => "submit", :value => "plan event" }
|
29
|
+
%span.clear
|
30
|
+
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -205,7 +205,26 @@ dependencies:
|
|
205
205
|
version: '0'
|
206
206
|
description: Course management module for QWAN nesta site
|
207
207
|
email: rob.westgeest@gmail.com
|
208
|
-
executables:
|
208
|
+
executables:
|
209
|
+
- autospec
|
210
|
+
- autotest
|
211
|
+
- haml
|
212
|
+
- html2haml
|
213
|
+
- htmldiff
|
214
|
+
- jeweler
|
215
|
+
- ldiff
|
216
|
+
- multigem
|
217
|
+
- multiruby
|
218
|
+
- multiruby_setup
|
219
|
+
- nokogiri
|
220
|
+
- rackup
|
221
|
+
- rake
|
222
|
+
- ri
|
223
|
+
- rspec
|
224
|
+
- sequel
|
225
|
+
- tilt
|
226
|
+
- unit_diff
|
227
|
+
- zentest
|
209
228
|
extensions: []
|
210
229
|
extra_rdoc_files:
|
211
230
|
- LICENSE.txt
|
@@ -265,6 +284,7 @@ files:
|
|
265
284
|
- spec/support/request_specs.rb
|
266
285
|
- spec/support/test_files.rb
|
267
286
|
- views/admin.haml
|
287
|
+
- views/events/edit.haml
|
268
288
|
- views/events/index.haml
|
269
289
|
- views/events/new.haml
|
270
290
|
- views/layout.haml
|
@@ -275,6 +295,25 @@ files:
|
|
275
295
|
- views/trainings/error.haml
|
276
296
|
- views/trainings/index.haml
|
277
297
|
- LICENSE.txt
|
298
|
+
- bin/autospec
|
299
|
+
- bin/autotest
|
300
|
+
- bin/haml
|
301
|
+
- bin/html2haml
|
302
|
+
- bin/htmldiff
|
303
|
+
- bin/jeweler
|
304
|
+
- bin/ldiff
|
305
|
+
- bin/multigem
|
306
|
+
- bin/multiruby
|
307
|
+
- bin/multiruby_setup
|
308
|
+
- bin/nokogiri
|
309
|
+
- bin/rackup
|
310
|
+
- bin/rake
|
311
|
+
- bin/ri
|
312
|
+
- bin/rspec
|
313
|
+
- bin/sequel
|
314
|
+
- bin/tilt
|
315
|
+
- bin/unit_diff
|
316
|
+
- bin/zentest
|
278
317
|
homepage: http://github.com/rwestgeest/qcourses
|
279
318
|
licenses:
|
280
319
|
- MIT
|
@@ -290,7 +329,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
290
329
|
version: '0'
|
291
330
|
segments:
|
292
331
|
- 0
|
293
|
-
hash:
|
332
|
+
hash: 342118163
|
294
333
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
295
334
|
none: false
|
296
335
|
requirements:
|