parlement 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES +26 -0
  2. data/README +2 -1
  3. data/app/controllers/account_controller.rb +27 -18
  4. data/app/controllers/application.rb +1 -3
  5. data/app/controllers/elt_controller.rb +92 -42
  6. data/app/helpers/elt_helper.rb +7 -18
  7. data/app/models/elt.rb +76 -22
  8. data/app/models/mail.rb +13 -10
  9. data/app/models/mail_notify.rb +11 -27
  10. data/app/models/person.rb +1 -1
  11. data/app/views/account/_login.rhtml +14 -9
  12. data/app/views/account/_show.rhtml +23 -9
  13. data/app/views/elt/_choice.rhtml +32 -0
  14. data/app/views/elt/_elt.rhtml +90 -78
  15. data/app/views/elt/_list.rhtml +83 -50
  16. data/app/views/elt/_listByDate.rhtml +60 -0
  17. data/app/views/elt/_listByVote.rhtml +71 -0
  18. data/app/views/elt/choices.rhtml +29 -0
  19. data/app/views/elt/new.rhtml +11 -26
  20. data/app/views/elt/rss.rxml +14 -12
  21. data/app/views/elt/show.rhtml +23 -29
  22. data/app/views/elt/vote_rss.rxml +40 -0
  23. data/app/views/layouts/top.rhtml +5 -13
  24. data/config/environment.rb +3 -1
  25. data/config/routes.rb +4 -0
  26. data/db/development_structure.sql +5 -2
  27. data/db/migrate/002_nested_set.rb +22 -0
  28. data/db/migrate/003_elt_children_count.rb +12 -0
  29. data/public/images/ParlementLogo.png +0 -0
  30. data/public/images/indicator.gif +0 -0
  31. data/public/javascripts/behaviour.js +254 -0
  32. data/public/javascripts/mybehaviour.js +96 -0
  33. data/public/javascripts/slider.js +188 -163
  34. data/test/fixtures/elts.yml +19 -0
  35. data/test/fixtures/mail/mail_ruby +4 -0
  36. data/test/fixtures/mail/mail_rubyChild +1 -1
  37. data/test/fixtures/mail/mail_rubyChild2 +1 -1
  38. data/test/functional/account_controller_test.rb +24 -0
  39. data/test/functional/elt_controller_test.rb +64 -4
  40. data/test/unit/elt_test.rb +28 -4
  41. data/test/unit/mail_notify_test.rb +7 -5
  42. data/test/unit/mail_test.rb +1 -1
  43. data/vendor/plugins/google_analytics/README +19 -0
  44. data/vendor/plugins/google_analytics/Rakefile +22 -0
  45. data/vendor/plugins/google_analytics/init.rb +3 -0
  46. data/vendor/plugins/google_analytics/lib/rubaidh/google_analytics.rb +70 -0
  47. data/vendor/plugins/google_analytics/test/google_analytics_test.rb +8 -0
  48. data/vendor/plugins/output_compression/README +4 -0
  49. data/vendor/plugins/output_compression/Rakefile +22 -0
  50. data/vendor/plugins/output_compression/init.rb +2 -0
  51. data/vendor/plugins/output_compression/lib/output_compression.rb +66 -0
  52. data/vendor/plugins/output_compression/tasks/output_compression_tasks.rake +4 -0
  53. data/vendor/plugins/output_compression/test/output_compression_test.rb +8 -0
  54. metadata +32 -4
  55. data/public/images/smile.svg +0 -257
  56. data/public/javascripts/borders.js +0 -687
@@ -5,14 +5,74 @@ require 'elt_controller'
5
5
  class EltController; def rescue_action(e) raise e end; end
6
6
 
7
7
  class EltControllerTest < Test::Unit::TestCase
8
+ #fixtures :people, :users, :elts, :mails, :attachments, :subscribers
9
+
8
10
  def setup
9
11
  @controller = EltController.new
10
12
  @request = ActionController::TestRequest.new
11
13
  @response = ActionController::TestResponse.new
12
- end
13
14
 
14
- # Replace this with your real tests.
15
- def test_truth
16
- assert true
15
+ @elt = Elt.find 'ROOT'
17
16
  end
17
+
18
+ def test_create
19
+ post :create, :id => @elt.id, :commit => "Propose!",
20
+ :elt =>{
21
+ :body => "Un joli test", :subject => "test_create", :parent_id => @elt.id }
22
+ assert_equal 4, @elt.children_count
23
+ end
24
+
25
+ def test_create_login
26
+ login
27
+ post :create, :id => @elt.id, :commit => "Propose!",
28
+ :elt =>{
29
+ :body => "Un joli test", :subject => "test_create", :parent_id => @elt.id }
30
+ assert_equal 4, @elt.children_count
31
+ end
32
+
33
+ def test_vote_pro
34
+ login
35
+ post :vote, :id => @elt.id, :choice => { :value => "+1" }, :commit => "Vote!"
36
+ assert_equal 4, @elt.children_count
37
+ assert_equal 1, @elt.result
38
+ end
39
+
40
+ def test_vote_con
41
+ login
42
+ post :vote, :id => @elt.id, :choice => { :value => "-1" }, :commit => "Vote!"
43
+ assert_equal 4, @elt.children_count
44
+ assert_equal -1, @elt.result
45
+ end
46
+
47
+ def test_vote_zero
48
+ login
49
+ post :vote, :id => @elt.id, :choice => { :value => "+1" }, :commit => "Vote!"
50
+ post :vote, :id => @elt.id, :choice => { :value => "+1" }, :commit => "Vote!"
51
+ assert_equal 5, @elt.children_count
52
+ assert_equal 0, @elt.result
53
+
54
+ post :vote, :id => @elt.id, :choice => { :value => "-1" }, :commit => "Vote!"
55
+ post :vote, :id => @elt.id, :choice => { :value => "-1" }, :commit => "Vote!"
56
+ assert_equal 7, @elt.children_count
57
+ assert_equal 0, @elt.result
58
+ end
59
+
60
+ def test_fight_spam
61
+ post :create, :id => @elt.id, :commit => "Propose!", :elt => {
62
+ :parent_id => @elt.id,
63
+ :subject => "cheap_atenolol<a_href='http_pohyis.org_tramadol_'",
64
+ :body => "Un spam" }
65
+ assert_equal 3, @elt.children_count
66
+
67
+ post :create, :id => @elt.id, :commit => "Propose!", :elt => {
68
+ :parent_id => @elt.id,
69
+ :subject => "href='http_pohyis.org_tramadol_'",
70
+ :body => "Un spam" }
71
+ assert_equal 3, @elt.children_count
72
+
73
+ post :create, :id => @elt.id, :commit => "Propose!", :elt => {
74
+ :parent_id => @elt.id, :subject => ">'", :body => "Un spam" }
75
+ assert_equal 3, @elt.children_count
76
+ end
18
77
  end
78
+
@@ -1,15 +1,39 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class EltTest < Test::Unit::TestCase
4
- fixtures :elts, :mails, :attachments
4
+ fixtures :people, :users, :elts, :mails, :attachments, :subscribers
5
5
 
6
6
  def setup
7
7
  @elt = Elt.find(1)
8
8
  end
9
9
 
10
- # Replace this with your real tests.
11
- def test_truth
12
- assert_kind_of Elt, @elt
10
+ def test_generated_id
11
+ e = @elt.children.new
12
+ e.subject = "Test: /de\ #?&subject"
13
+ e.body = "Test de body"
14
+ e.save
15
+ @elt.add_child e
16
+
17
+ assert_equal "Test_de_subject", e.id
18
+
19
+ e = @elt.children.new
20
+ e.subject = "Test&? de subject"
21
+ e.body = "Test de body"
22
+ e.save
23
+ @elt.add_child e
24
+
25
+ assert_equal "Test_de_subject_1", e.id
26
+ end
27
+
28
+ def test_vote_hidden_from_view
29
+ vote = @elt.children.new
30
+ vote.save
31
+ @elt.add_child vote
32
+ vote.body = "+1"
33
+ vote.publish
34
+
35
+ assert_equal -1, vote.result
36
+ assert_equal 1, vote.parent.result
13
37
  end
14
38
  end
15
39
 
@@ -18,10 +18,11 @@ class MailNotifyTest < Test::Unit::TestCase
18
18
 
19
19
  assert_equal 0, ActionMailer::Base.deliveries.size
20
20
 
21
- elt = Elt.find('mail')
22
- elt.save
21
+ elt = Elt.find('mailList')
22
+ elt.publish
23
23
 
24
24
  assert_equal 1, ActionMailer::Base.deliveries.size
25
+ assert_equal "mail@leparlement.org", ActionMailer::Base.deliveries[0].to[0]
25
26
  end
26
27
 
27
28
  def test_redeliver_mail
@@ -29,11 +30,12 @@ class MailNotifyTest < Test::Unit::TestCase
29
30
 
30
31
  assert_equal 0, ActionMailer::Base.deliveries.size
31
32
 
32
- elt = Elt.find('mail')
33
- elt.save
33
+ elt = Elt.find('mailList')
34
+ elt.publish
34
35
 
35
36
  assert_equal 1, ActionMailer::Base.deliveries.size
36
- #puts ActionMailer::Base.deliveries[0]
37
+ assert_equal "mail@leparlement.org", ActionMailer::Base.deliveries[0].to[0]
38
+ #puts ActionMailer::Base.deliveries[0].to
37
39
  end
38
40
  end
39
41
 
@@ -194,7 +194,7 @@ class MailTest < Test::Unit::TestCase
194
194
  assert_equal 1, eltChild.voters.size
195
195
 
196
196
  assert_equal 1, eltChild.result
197
- assert_equal -1, elt.result
197
+ assert_equal 0, elt.result
198
198
  end
199
199
 
200
200
  def test_receive_second_choice
@@ -0,0 +1,19 @@
1
+ GoogleAnalytics
2
+ ===============
3
+
4
+ This is a quick 'n' dirty module to easily enable Google Analytics support
5
+ in your application. By default it'll output the analytics code for every
6
+ single page automatically, if it's configured correctly. This is done by
7
+ adding:
8
+
9
+ Rubaidh::GoogleAnalytics.tracker_id = 'UA-12345-67'
10
+
11
+ to your `config/environment.rb`, inserting your own tracker id. This can be
12
+ discovered by looking at the value assigned to +_uacct+ in the Javascript
13
+ code.
14
+
15
+ If you want to disable the code insertion for particular pages, add the following to controllers that don't want it:
16
+
17
+ skip_after_filter :add_google_analytics_code
18
+
19
+ Simple. :-)
@@ -0,0 +1,22 @@
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 google_analytics plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the google_analytics plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'GoogleAnalytics'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubaidh/google_analytics'
2
+ ActionController::Base.send :include, Rubaidh::GoogleAnalyticsMixin
3
+ ActionController::Base.send :after_filter, :add_google_analytics_code
@@ -0,0 +1,70 @@
1
+ module Rubaidh # :nodoc:
2
+ module GoogleAnalyticsMixin
3
+ def google_analytics_code(request = nil)
4
+ return unless GoogleAnalytics.enabled?
5
+ GoogleAnalytics.new.google_analytics_code(request)
6
+ end
7
+
8
+ # An after_filter to automatically add the analytics code.
9
+ def add_google_analytics_code
10
+ code = google_analytics_code(request)
11
+ return if code.blank?
12
+ response.body.gsub! '</body>', code + '</body>'
13
+ end
14
+ end
15
+
16
+ class GoogleAnalytics
17
+ # Specify the Google Analytics ID for this web site. This can be found
18
+ # as the value of +_uacct+ in the Javascript excerpt
19
+ @@tracker_id = nil
20
+ cattr_accessor :tracker_id
21
+
22
+ # Specify a different domain name from the default. You'll want to use
23
+ # this if you have several subdomains that you want to combine into
24
+ # one report. See the Google Analytics documentation for more
25
+ # information.
26
+ @@domain_name = nil
27
+ cattr_accessor :domain_name
28
+
29
+ # I can't see why you'd want to do this, but you can always change the
30
+ # analytics URL.
31
+ @@analytics_url = 'http://www.google-analytics.com/urchin.js'
32
+ cattr_accessor :analytics_url
33
+
34
+ # I can't see why you'd want to do this, but you can always change the
35
+ # analytics URL (ssl version).
36
+ @@analytics_ssl_url = 'https://ssl.google-analytics.com/urchin.js'
37
+ cattr_accessor :analytics_ssl_url
38
+
39
+ # The environments in which to enable the Google Analytics code. Defaults
40
+ # to 'production' only.
41
+ @@environments = ['production']
42
+ cattr_accessor :environments
43
+
44
+ # Return true if the Google Analytics system is enabled and configured
45
+ # correctly.
46
+ def self.enabled?
47
+ (environments.include?(RAILS_ENV) and
48
+ not tracker_id.blank? and
49
+ not analytics_url.blank?)
50
+ end
51
+
52
+ def google_analytics_code(request = nil)
53
+ extra_code = domain_name.blank? ? nil : "_udn = \"#{domain_name}\";"
54
+ url = (not request.blank? and request.ssl?) ? analytics_ssl_url : analytics_url
55
+
56
+ # OK, I'm not very bright -- I tried to turn this into a partial and
57
+ # failed miserably! So it'll have to live here for now.
58
+ code = <<-HTML
59
+ <script src="#{url}" type="text/javascript">
60
+ </script>
61
+ <script type="text/javascript">
62
+ _uacct = "#{tracker_id}";
63
+ #{extra_code}
64
+ urchinTracker();
65
+ </script>
66
+ HTML
67
+ code
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class GoogleAnalyticsTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ OutputCompression
2
+ =================
3
+
4
+ Description goes here
@@ -0,0 +1,22 @@
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 output_compression plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the output_compression plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'OutputCompression'
19
+ rdoc.options << '--line-numbers --inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require 'output_compression'
@@ -0,0 +1,66 @@
1
+ # OutputCompression
2
+ # Rails output compression filters
3
+ #
4
+ # Adds two classmethods to ActionController that can be used as after-filters:
5
+ # strip_whitespace and compress_output.
6
+ # If you use page-caching, you MUST specify the compress_output filter AFTER
7
+ # caches_page, otherwise the compressed data will be cached instead of the HTML
8
+ #
9
+ # class MyController < ApplicationController
10
+ # after_filter :strip_whitespace
11
+ # caches_page :index
12
+ # after_filter :compress_output
13
+ # end
14
+
15
+ begin
16
+ require 'zlib'
17
+ require 'stringio'
18
+ GZIP_SUPPORTED = true
19
+ rescue
20
+ GZIP_SUPPORTED = false
21
+ end
22
+
23
+ module CompressionSystem
24
+ def compress_output
25
+ return unless accepts_gzip?
26
+ output = StringIO.new
27
+ def output.close
28
+ # Zlib does a close. Bad Zlib...
29
+ rewind
30
+ end
31
+ gz = Zlib::GzipWriter.new(output)
32
+ gz.write(response.body)
33
+ gz.close
34
+ if output.length < response.body.length
35
+ @old_response_body = response.body
36
+ response.body = output.string
37
+ response.headers['Content-encoding'] = @compression_encoding
38
+ end
39
+ end
40
+
41
+ def accepts_gzip?
42
+ return false unless GZIP_SUPPORTED
43
+ accepts = request.env['HTTP_ACCEPT_ENCODING']
44
+ return false unless accepts && accepts =~ /(x-gzip|gzip)/
45
+ @compression_encoding = $1
46
+ true
47
+ end
48
+
49
+ def strip_whitespace
50
+ response.body.gsub!(/()|(.*?<\/script>)|()|()|\s+/m) do |m|
51
+ if m =~ /^()(.*?)<\/script>$/m
52
+ $1 + $2.strip.gsub(/\s+/, ' ').gsub('',"\n-->") + ''
53
+ elsif m =~ /^$/m
54
+ ''
55
+ elsif m =~ /^<(textarea|pre)/
56
+ m
57
+ else ' '
58
+ end
59
+ end
60
+ response.body.gsub! /\s+\s+/, '>'
61
+ end
62
+ end
63
+
64
+ class ActionController::Base
65
+ include CompressionSystem
66
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :output_compression do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class OutputCompressionTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: parlement
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.5"
7
- date: 2006-05-20 00:00:00 +02:00
6
+ version: "0.6"
7
+ date: 2006-06-18 00:00:00 +02:00
8
8
  summary: Trusted Direct Democracy on a forum
9
9
  require_paths:
10
10
  - lib
@@ -74,6 +74,11 @@ files:
74
74
  - app/views/elt/_list.rhtml
75
75
  - app/views/elt/new.rhtml
76
76
  - app/views/elt/show.rhtml
77
+ - app/views/elt/_listByDate.rhtml
78
+ - app/views/elt/_choice.rhtml
79
+ - app/views/elt/_listByVote.rhtml
80
+ - app/views/elt/vote_rss.rxml
81
+ - app/views/elt/choices.rhtml
77
82
  - app/views/account/welcome.rhtml
78
83
  - app/views/account/_login.rhtml
79
84
  - app/views/account/logout.rhtml
@@ -99,6 +104,8 @@ files:
99
104
  - db/ROOT
100
105
  - db/development_structure.sql
101
106
  - db/migrate/001_create_choices.rb
107
+ - db/migrate/002_nested_set.rb
108
+ - db/migrate/003_elt_children_count.rb
102
109
  - db/ROOT/perso
103
110
  - db/ROOT/parlement.txt
104
111
  - db/ROOT/perso.txt
@@ -143,12 +150,13 @@ files:
143
150
  - public/images/rails.png
144
151
  - public/images/orange_by_darren_Hester_350o.jpg
145
152
  - public/images/Sleep-Deprivation-5.JPG
153
+ - public/images/indicator.gif
146
154
  - public/images/smile.png
147
- - public/images/smile.svg
148
155
  - public/images/eltBackground.svg
149
156
  - public/images/world.png
150
157
  - public/images/world.svg
151
158
  - public/images/eltBackground.jng
159
+ - public/images/ParlementLogo.png
152
160
  - public/engine_files/README
153
161
  - public/engine_files/login_engine
154
162
  - public/javascripts/prototype.js
@@ -160,9 +168,10 @@ files:
160
168
  - public/javascripts/slider.js
161
169
  - public/javascripts/blank.gif
162
170
  - public/javascripts/ie7.js
163
- - public/javascripts/borders.js
171
+ - public/javascripts/behaviour.js
164
172
  - public/javascripts/ie7-load.htc
165
173
  - public/javascripts/application.js
174
+ - public/javascripts/mybehaviour.js
166
175
  - test/fixtures
167
176
  - test/functional
168
177
  - test/mocks
@@ -204,6 +213,8 @@ files:
204
213
  - vendor/plugins/engines
205
214
  - vendor/plugins/guid
206
215
  - vendor/plugins/file_column
216
+ - vendor/plugins/output_compression
217
+ - vendor/plugins/google_analytics
207
218
  - vendor/plugins/login_engine/test
208
219
  - vendor/plugins/login_engine/app
209
220
  - vendor/plugins/login_engine/db
@@ -336,6 +347,23 @@ files:
336
347
  - vendor/plugins/file_column/lib/magick_file_column.rb
337
348
  - vendor/plugins/file_column/lib/file_column_helper.rb
338
349
  - vendor/plugins/file_column/lib/file_column.rb
350
+ - vendor/plugins/output_compression/test
351
+ - vendor/plugins/output_compression/tasks
352
+ - vendor/plugins/output_compression/lib
353
+ - vendor/plugins/output_compression/Rakefile
354
+ - vendor/plugins/output_compression/init.rb
355
+ - vendor/plugins/output_compression/README
356
+ - vendor/plugins/output_compression/test/output_compression_test.rb
357
+ - vendor/plugins/output_compression/tasks/output_compression_tasks.rake
358
+ - vendor/plugins/output_compression/lib/output_compression.rb
359
+ - vendor/plugins/google_analytics/test
360
+ - vendor/plugins/google_analytics/lib
361
+ - vendor/plugins/google_analytics/Rakefile
362
+ - vendor/plugins/google_analytics/init.rb
363
+ - vendor/plugins/google_analytics/README
364
+ - vendor/plugins/google_analytics/test/google_analytics_test.rb
365
+ - vendor/plugins/google_analytics/lib/rubaidh
366
+ - vendor/plugins/google_analytics/lib/rubaidh/google_analytics.rb
339
367
  test_files:
340
368
  - test/unit/mail_test.rb
341
369
  - test/unit/elt_test.rb