junebug 0.0.8 → 0.0.9

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.
data/CHANGELOG ADDED
@@ -0,0 +1,40 @@
1
+ v0.0.9 2006-11-10
2
+
3
+ * Mosquito unit tests
4
+
5
+ v0.0.8 2006-11-08
6
+
7
+ * Style work
8
+ * Addd rss link to head
9
+ * Stylesheet update rake task
10
+
11
+ v0.0.7 2006-11-07
12
+
13
+ * Redirect bugfix for proxied sites
14
+
15
+ v0.0.6 2006-11-07
16
+
17
+ * Delete pages
18
+ * More style work
19
+
20
+ v0.0.5 2006-11-06
21
+
22
+ * Style cleanups
23
+ * Security fix
24
+ * Format test page
25
+
26
+ v0.0.4 2006-11-05
27
+
28
+ * Readonly pages
29
+ * Start page
30
+ * Bugfixes
31
+
32
+ v0.0.3 2006-10-30
33
+
34
+ * User accounts
35
+ * Daemonize
36
+ * Default page fixtures
37
+
38
+ v0.0.2 2006-10-22
39
+
40
+ * Initial release
data/README CHANGED
@@ -5,7 +5,7 @@ Junebug is a minimalist wiki, running on Camping.
5
5
 
6
6
  == Status
7
7
 
8
- Junebug v0.0.8 release, 2006-11-08
8
+ Junebug v0.0.9 release, 2006-11-10
9
9
 
10
10
  This is an alpha release. Use at your own risk. Please do not use this for anything important.
11
11
 
data/Rakefile ADDED
@@ -0,0 +1,97 @@
1
+ $:.unshift './lib'
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/testtask'
7
+ require 'rake/rdoctask'
8
+
9
+ require 'active_record'
10
+
11
+ Gem.manage_gems
12
+
13
+ gem_spec = Gem::Specification.new do |s|
14
+ s.name = 'junebug'
15
+ s.version = '0.0.9'
16
+ s.summary = "Junebug is a minimalist ruby wiki."
17
+ s.description = "Junebug is a minimalist ruby wiki running on Camping."
18
+ s.author = "Tim Myrtle"
19
+ s.email = 'tim.myrtle@gmail.com'
20
+ s.homepage = 'http://www.junebugwiki.com/'
21
+
22
+ s.require_paths = ['lib']
23
+ s.bindir = 'bin'
24
+ s.executables = ['junebug']
25
+ s.files = FileList['README','LICENSE','CHANGELOG','Rakefile','lib/**/*','deploy/**/*','fixtures/**/*']
26
+ s.test_files = FileList['test/**/*']
27
+
28
+ s.add_dependency('mongrel', '>=0.3.13.4')
29
+ s.add_dependency('camping', '>=1.5')
30
+ s.add_dependency('RedCloth', '>=3.0.4')
31
+ s.add_dependency('daemons')
32
+ s.add_dependency('sqlite3-ruby', '>=1.1.0.1')
33
+ s.add_dependency('activerecord', '>=1.14.4')
34
+ end
35
+
36
+ Rake::GemPackageTask.new(gem_spec) do |pkg|
37
+ pkg.need_zip = false
38
+ pkg.need_tar = false
39
+ end
40
+
41
+ desc "View tidy html from dev server in editor"
42
+ task :tidy do
43
+ system("curl http://localhost:3301/#{ENV['PAGE']} | tidy -i -wrap 1000 | #{ENV['VISUAL'] || ENV['EDITOR'] || 'vim' }")
44
+ end
45
+
46
+
47
+
48
+
49
+ desc "Clean up directory"
50
+ task :clean => :clobber_package do
51
+ rm 'deploy/junebug.db', :force => true
52
+ rm 'deploy/junebug.log', :force => true
53
+ rm 'test/test.log', :force => true
54
+ end
55
+
56
+
57
+ desc 'Dump wiki pages'
58
+ task :dump_pages do
59
+ fixtures_dir = File.join('.', 'fixtures')
60
+
61
+ # clean out fixtures dir
62
+ puts "fixtures_dir: #{fixtures_dir}"
63
+ Dir[File.join(fixtures_dir, '*')].each { |f| rm_f(f, :verbose => false) }
64
+
65
+ # open db connection
66
+ ActiveRecord::Base.establish_connection( :adapter => "sqlite3", :database => "./deploy/junebug.db")
67
+
68
+ # open fixtures file
69
+ File.open(File.join(fixtures_dir, "junebug_pages.yml"), 'w') do |file|
70
+
71
+ # grab all pages
72
+ pages = Junebug::Models::Page.find(:all)
73
+ page_data = []
74
+ pages.each do |page|
75
+ page_data << page.attributes
76
+ end
77
+
78
+ file.write page_data.to_yaml
79
+ end
80
+
81
+ puts "Got pages and put them in #{fixtures_dir}."
82
+ end
83
+
84
+
85
+ desc 'Test the campground.'
86
+ Rake::TestTask.new(:test) do |t|
87
+ # t.libs << 'lib'
88
+ t.pattern = 'test/**/*_test.rb'
89
+ t.verbose = true
90
+ end
91
+
92
+
93
+
94
+
95
+
96
+
97
+
data/bin/junebug CHANGED
@@ -9,6 +9,8 @@ if ARGV.first.empty?
9
9
  exit
10
10
  end
11
11
 
12
+ ENV['INTERACTIVE']='1'
13
+
12
14
  Junebug::Generator.generate(ARGV)
13
15
 
14
16
 
@@ -8,7 +8,6 @@ module Junebug
8
8
  extend self
9
9
 
10
10
  def generate(args)
11
- puts "In generator"
12
11
  src_root = File.dirname(__FILE__) + '/../../deploy'
13
12
  app = ARGV.first
14
13
  FileUtils.cp_r(src_root, app)
@@ -4,9 +4,21 @@ require 'acts_as_versioned'
4
4
  module Junebug::Models
5
5
 
6
6
  class User < Base
7
+ validates_uniqueness_of :username
8
+ validates_format_of :username, :with => /^([\w]*)$/
7
9
  validates_length_of :username, :within=>3..30
10
+ validates_format_of :password, :with => /^([\w]*)$/
8
11
  validates_length_of :password, :within=>5..30
9
12
  has_many :pages
13
+
14
+ def username=(text)
15
+ write_attribute(:username, (text ? text.strip.downcase : text) )
16
+ end
17
+
18
+ def password=(text)
19
+ write_attribute(:password, (text ? text.strip : text) )
20
+ end
21
+
10
22
  end
11
23
 
12
24
  class Page < Base
@@ -44,15 +56,15 @@ module Junebug::Models
44
56
  Page.reset_column_information
45
57
 
46
58
  # Create admin account
47
- if ENV['DAEMONS_ARGV']
48
- username = 'admin'
49
- password = 'password'
50
- else
59
+ if ENV['INTERACTIVE']
51
60
  print "Create an initial user account\n"
52
61
  print "\nEnter your username (3-30 chars, no spaces or punctuation): "
53
62
  username = STDIN.gets.strip
54
63
  print "\nEnter your password (5-30 chars, no spaces or punctuation): "
55
64
  password = STDIN.gets.strip
65
+ else
66
+ username = 'admin'
67
+ password = 'password'
56
68
  end
57
69
  admin = User.create :username => username, :password => password
58
70
 
@@ -0,0 +1,210 @@
1
+ %w(
2
+ rubygems
3
+ test/unit
4
+ active_record
5
+ active_record/fixtures
6
+ active_support/binding_of_caller
7
+ camping
8
+ fileutils
9
+ stringio
10
+ cgi
11
+ ).each { |lib| require lib }
12
+
13
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ":memory:")
14
+ ActiveRecord::Base.logger = Logger.new("test/test.log")
15
+
16
+ Test::Unit::TestCase.fixture_path = "test/fixtures/"
17
+
18
+ class Test::Unit::TestCase #:nodoc:
19
+ def create_fixtures(*table_names)
20
+ if block_given?
21
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
22
+ else
23
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
24
+ end
25
+ end
26
+
27
+ # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
28
+ self.use_transactional_fixtures = true
29
+ # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
30
+ self.use_instantiated_fixtures = false
31
+ end
32
+
33
+ class MockRequest
34
+ def initialize
35
+ @headers = {
36
+ 'SERVER_NAME' => 'localhost',
37
+ 'PATH_INFO' => '',
38
+ 'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
39
+ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0',
40
+ 'SCRIPT_NAME' => '/',
41
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
42
+ 'HTTP_CACHE_CONTROL' => 'max-age=0',
43
+ 'HTTP_ACCEPT_LANGUAGE' => 'en,ja;q=0.9,fr;q=0.9,de;q=0.8,es;q=0.7,it;q=0.7,nl;q=0.6,sv;q=0.5,nb;q=0.5,da;q=0.4,fi;q=0.3,pt;q=0.3,zh-Hans;q=0.2,zh-Hant;q=0.1,ko;q=0.1',
44
+ 'HTTP_HOST' => 'localhost',
45
+ 'REMOTE_ADDR' => '127.0.0.1',
46
+ 'SERVER_SOFTWARE' => 'Mongrel 0.3.12.4',
47
+ 'HTTP_KEEP_ALIVE' => '300',
48
+ 'HTTP_REFERER' => 'http://localhost/',
49
+ 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
50
+ 'HTTP_VERSION' => 'HTTP/1.1',
51
+ 'REQUEST_URI' => '/',
52
+ 'SERVER_PORT' => '80',
53
+ 'GATEWAY_INTERFACE' => 'CGI/1.2',
54
+ 'HTTP_ACCEPT' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
55
+ 'HTTP_CONNECTION' => 'keep-alive',
56
+ 'REQUEST_METHOD' => 'GET',
57
+ }
58
+ end
59
+
60
+ def set(key, val)
61
+ @headers[key] = val
62
+ end
63
+
64
+ def to_hash
65
+ @headers
66
+ end
67
+
68
+ def [](key)
69
+ @headers[key]
70
+ end
71
+
72
+ def []=(key, value)
73
+ @headers[key] = value
74
+ end
75
+
76
+ ##
77
+ # Allow getters like this:
78
+ # o.REQUEST_METHOD
79
+
80
+ def method_missing(method_name, *args)
81
+ if @headers.has_key?(method_name.to_s)
82
+ return @headers[method_name.to_s]
83
+ else
84
+ super(method_name, args)
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+
91
+ module Camping
92
+
93
+ class Test < Test::Unit::TestCase
94
+
95
+ def test_dummy; end
96
+
97
+ def deny(condition, message='')
98
+ assert !condition, message
99
+ end
100
+
101
+ # http://project.ioni.st/post/217#post-217
102
+ #
103
+ # def test_new_publication
104
+ # assert_difference(Publication, :count) do
105
+ # post :create, :publication_title => ...
106
+ # # ...
107
+ # end
108
+ # end
109
+ #
110
+ # Is the number of items different?
111
+ #
112
+ # Can be used for increment and decrement.
113
+ #
114
+ def assert_difference(object, method = :count, difference = 1)
115
+ initial_value = object.send(method)
116
+ yield
117
+ assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
118
+ end
119
+ def assert_no_difference(object, method, &block)
120
+ assert_difference object, method, 0, &block
121
+ end
122
+
123
+ end
124
+
125
+ class FunctionalTest < Test
126
+
127
+ def setup
128
+ @class_name_abbr = self.class.name.gsub(/Test$/, '')
129
+ @request = MockRequest.new
130
+ end
131
+
132
+ def get(url='/')
133
+ send_request url, {}, 'GET'
134
+ end
135
+
136
+ def post(url, post_vars={})
137
+ send_request url, post_vars, 'POST'
138
+ end
139
+
140
+ def send_request(url, post_vars, method)
141
+ @request['REQUEST_METHOD'] = method
142
+ @request['SCRIPT_NAME'] = '/' + @class_name_abbr.downcase
143
+ @request['PATH_INFO'] = '/' + url
144
+ @request['REQUEST_URI'] = [@request.SCRIPT_NAME, @request.PATH_INFO].join('')
145
+
146
+ @request['HTTP_COOKIE'] = @cookies.map {|k,v| "#{k}=#{v}" }.join('; ') if @cookies
147
+
148
+ @response = eval("#{@class_name_abbr}.run StringIO.new('#{qs_build(post_vars)}'), @request")
149
+
150
+ @cookies = @response.headers['Set-Cookie'].inject(@cookies||{}) do |res,header|
151
+ data = header.split(';').first
152
+ name, value = data.split('=')
153
+ res[name] = value
154
+ res
155
+ end
156
+
157
+ if @response.headers['X-Sendfile']
158
+ @response.body = File.read(@response.headers['X-Sendfile'])
159
+ end
160
+ end
161
+
162
+ def assert_response(status_code)
163
+ case status_code
164
+ when :success
165
+ assert_equal 200, @response.status
166
+ when :redirect
167
+ assert_equal 302, @response.status
168
+ when :error
169
+ assert @response.status >= 500
170
+ else
171
+ assert_equal status_code, @response.status
172
+ end
173
+ end
174
+
175
+ def assert_match_body(regex, message=nil)
176
+ assert_match regex, @response.body, message
177
+ end
178
+ def assert_no_match_body(regex, message=nil)
179
+ assert_no_match regex, @response.body, message
180
+ end
181
+
182
+ def assert_redirected_to(url, message=nil)
183
+ assert_equal url,
184
+ @response.headers['Location'].path.gsub(%r!/#{@class_name_abbr.downcase}!, ''),
185
+ message
186
+ end
187
+
188
+ def assert_cookie(name, pat, message=nil)
189
+ assert_match pat, @cookies[name], message
190
+ end
191
+
192
+ def test_dummy; end
193
+
194
+ private
195
+
196
+ def qs_build(var_hash)
197
+ var_hash.map do |k, v|
198
+ [Camping.escape(k.to_s), Camping.escape(v.to_s)].join('=')
199
+ end.join('&')
200
+ end
201
+
202
+ end
203
+
204
+ class UnitTest < Test
205
+
206
+ def test_dummy; end
207
+
208
+ end
209
+
210
+ end
data/lib/junebug/views.rb CHANGED
@@ -75,10 +75,10 @@ module Junebug::Views
75
75
  text " Readonly"
76
76
  br
77
77
  end
78
- input :type => 'submit', :name=>'submit', :value=>'delete', :class=>'button', :onclick=>'return confirm("You sure?")', :style=>'float: right;'
79
- input :type => 'submit', :name=>'submit', :value=>'save', :class=>'button'
78
+ _button 'cancel', :href => R(Show, @page.title, @page.version), :style=>'float: right;'
79
+ input :type => 'submit', :name=>'submit', :value=>'save', :class=>'button', :style=>'float: right;'
80
+ input :type => 'submit', :name=>'submit', :value=>'delete', :class=>'button', :onclick=>'return confirm("You sure?")'
80
81
  end
81
- _button 'cancel', :href => R(Show, @page.title, @page.version); text '&nbsp;'
82
82
  a 'syntax help', :href => 'http://hobix.com/textile/', :target=>'_blank'
83
83
  br :clear=>'all'
84
84
  }
@@ -0,0 +1,4 @@
1
+ id_1:
2
+ id: 1
3
+ username: admin
4
+ password: password
data/test/wiki_test.rb ADDED
@@ -0,0 +1,151 @@
1
+ require File.dirname(__FILE__) + "/../lib/junebug/mosquito"
2
+ require File.dirname(__FILE__) + "/../lib/junebug"
3
+
4
+ Junebug.create
5
+ include Junebug::Models
6
+
7
+ # class JunebugTest < Camping::FunctionalTest
8
+ #
9
+ # fixtures :junebug_users
10
+ #
11
+ # def setup
12
+ # super
13
+ # end
14
+ #
15
+ # def test_index
16
+ # get
17
+ # assert_response :success
18
+ # assert_match_body %r!>blog<!
19
+ # end
20
+ #
21
+ # def test_view
22
+ # get '/view/1'
23
+ # assert_response :success
24
+ # assert_match_body %r!The quick fox jumped over the lazy dog!
25
+ # end
26
+ #
27
+ # def test_styles
28
+ # get 'styles.css'
29
+ # assert_match_body %r!Utopia!
30
+ # end
31
+ #
32
+ # def test_edit_should_require_login
33
+ # get '/edit/1'
34
+ # assert_response :success
35
+ # assert_match_body 'login'
36
+ # end
37
+ #
38
+ # def test_login
39
+ # post 'login', :username => 'quentin', :password => 'password'
40
+ # assert_match_body 'login success'
41
+ # end
42
+ #
43
+ # def test_comment
44
+ # assert_difference(Comment) {
45
+ # post 'comment', :post_username => 'jim',
46
+ # :post_body => 'Nice article.',
47
+ # :post_id => 1
48
+ # assert_response :redirect
49
+ # assert_redirected_to '/view/1'
50
+ # }
51
+ # end
52
+ #
53
+ # end
54
+ #
55
+ # class PostTest < Camping::UnitTest
56
+ #
57
+ # fixtures :junebug_users
58
+ #
59
+ # def test_create
60
+ # post = create
61
+ # assert post.valid?
62
+ # end
63
+ #
64
+ # def test_assoc
65
+ # post = Post.find :first
66
+ # assert_kind_of User, post.user
67
+ # assert_equal 1, post.user.id
68
+ # end
69
+ #
70
+ # def test_destroy
71
+ # original_count = Post.count
72
+ # Post.destroy 1
73
+ # assert_equal original_count - 1, Post.count
74
+ # end
75
+ #
76
+ # private
77
+ #
78
+ # def create(options={})
79
+ # Post.create({ :user_id => 1,
80
+ # :title => "Title",
81
+ # :body => "Body"}.merge(options))
82
+ # end
83
+ #
84
+ # end
85
+
86
+ class UserTest < Camping::UnitTest
87
+
88
+ fixtures :junebug_users
89
+
90
+ def test_create
91
+ user = create
92
+ assert user.valid?
93
+ end
94
+
95
+ def test_required
96
+ user = create(:username => nil)
97
+ deny user.valid?
98
+ assert_not_nil user.errors.on(:username)
99
+
100
+ user = create(:password => nil)
101
+ deny user.valid?
102
+ assert_not_nil user.errors.on(:password)
103
+ end
104
+
105
+ def test_valid_username
106
+ user = create(:username => 'aa')
107
+ deny user.valid?
108
+ assert_not_nil user.errors.on(:username)
109
+
110
+ user = create(:username => 'aaa aaa')
111
+ deny user.valid?
112
+ assert_not_nil user.errors.on(:username)
113
+ end
114
+
115
+ def test_valid_password
116
+ user = create(:password => 'aa')
117
+ deny user.valid?
118
+ assert_not_nil user.errors.on(:password)
119
+
120
+ user = create(:password => 'aaa aaa')
121
+ deny user.valid?
122
+ assert_not_nil user.errors.on(:password)
123
+ end
124
+
125
+ def test_unique
126
+ user = create(:username => 'admin')
127
+ deny user.valid?
128
+ assert_not_nil user.errors.on(:username)
129
+
130
+ user = create(:username => 'Admin')
131
+ deny user.valid?
132
+ assert_not_nil user.errors.on(:username)
133
+ end
134
+
135
+ def test_spaces
136
+ user = create(:username => 'aaaaaa ', :password =>'aaaaaa ')
137
+ assert user.valid?
138
+ assert user.username == 'aaaaaa'
139
+ assert user.password == 'aaaaaa'
140
+ end
141
+
142
+
143
+ private
144
+
145
+ def create(options={})
146
+ User.create({ :username => 'godfrey',
147
+ :password => 'password' }.merge(options))
148
+ end
149
+
150
+ end
151
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: junebug
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.8
7
- date: 2006-11-08 00:00:00 -08:00
6
+ version: 0.0.9
7
+ date: 2006-11-10 00:00:00 -08:00
8
8
  summary: Junebug is a minimalist ruby wiki.
9
9
  require_paths:
10
10
  - lib
@@ -31,6 +31,8 @@ authors:
31
31
  files:
32
32
  - README
33
33
  - LICENSE
34
+ - CHANGELOG
35
+ - Rakefile
34
36
  - lib/acts_as_versioned.rb
35
37
  - lib/junebug
36
38
  - lib/junebug.rb
@@ -40,6 +42,7 @@ files:
40
42
  - lib/junebug/generator.rb
41
43
  - lib/junebug/helpers.rb
42
44
  - lib/junebug/models.rb
45
+ - lib/junebug/mosquito.rb
43
46
  - lib/junebug/views.rb
44
47
  - deploy/config.yml
45
48
  - deploy/console
@@ -55,8 +58,10 @@ files:
55
58
  - deploy/static/style/yui/grids.css
56
59
  - deploy/static/style/yui/reset.css
57
60
  - fixtures/junebug_pages.yml
58
- test_files: []
59
-
61
+ test_files:
62
+ - test/fixtures
63
+ - test/wiki_test.rb
64
+ - test/fixtures/junebug_users.yml
60
65
  rdoc_options: []
61
66
 
62
67
  extra_rdoc_files: []