Project

General

Profile

« Previous | Next » 

Revision 1623

Merged Rails 2.1 compatibility branch.

View differences:

trunk/app/controllers/projects_controller.rb
52 52
    respond_to do |format|
53 53
      format.html { 
54 54
        @project_tree = projects.group_by {|p| p.parent || p}
55
        @project_tree.each_key {|p| @project_tree[p] -= [p]} 
55
        @project_tree.keys.each {|p| @project_tree[p] -= [p]} 
56 56
      }
57 57
      format.atom {
58 58
        render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i), 
trunk/app/helpers/repositories_helper.rb
22 22
    txt.to_s[0,8]
23 23
  end
24 24
  
25
  def to_path_param(path)
26
    path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
27
  end
28
  
25 29
  def to_utf8(str)
26 30
    return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
27 31
    @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
trunk/app/models/user_preference.rb
42 42
    if attribute_present? attr_name
43 43
      super
44 44
    else
45
      self.others ||= {}
46
      self.others.store attr_name, value
45
      h = read_attribute(:others).dup || {}
46
      h.update(attr_name => value)
47
      write_attribute(:others, h)
48
      value
47 49
    end
48 50
  end
49 51
  
trunk/app/views/repositories/_dir_list_content.rhtml
4 4
<tr id="<%= tr_id %>" class="<%= params[:parent_id] %> entry <%= entry.kind %>">
5 5
<td style="padding-left: <%=18 * depth%>px;" class="filename">
6 6
<% if entry.is_dir? %>
7
<span class="expander" onclick="<%=  remote_function :url => {:action => 'browse', :id => @project, :path => entry.path, :rev => @rev, :depth => (depth + 1), :parent_id => tr_id},
7
<span class="expander" onclick="<%=  remote_function :url => {:action => 'browse', :id => @project, :path => to_path_param(entry.path), :rev => @rev, :depth => (depth + 1), :parent_id => tr_id},
8 8
                  :update => { :success => tr_id },
9 9
                  :position => :after,
10 10
                  :success => "scmEntryLoaded('#{tr_id}')",
11 11
                  :condition => "scmEntryClick('#{tr_id}')"%>">&nbsp</span>
12 12
<% end %>
13 13
<%=  link_to h(entry.name),
14
          {:action => (entry.is_dir? ? 'browse' : 'changes'), :id => @project, :path => entry.path, :rev => @rev},
14
          {:action => (entry.is_dir? ? 'browse' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev},
15 15
          :class => (entry.is_dir? ? 'icon icon-folder' : 'icon icon-file')%>
16 16
</td>
17 17
<td class="size"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>
trunk/app/views/repositories/_navigation.rhtml
10 10
    link_path << '/' unless link_path.empty?
11 11
    link_path << "#{dir}" 
12 12
    %>
13
    / <%= link_to h(dir), :action => 'browse', :id => @project, :path => link_path, :rev => @rev %>
13
    / <%= link_to h(dir), :action => 'browse', :id => @project, :path => to_path_param(link_path), :rev => @rev %>
14 14
<% end %>
15 15
<% if filename %>
16
    / <%= link_to h(filename), :action => 'changes', :id => @project, :path => "#{link_path}/#{filename}", :rev => @rev %>
16
    / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %>
17 17
<% end %>
18 18

  
19 19
<%= "@ #{revision}" if revision %>
trunk/app/views/repositories/_revisions.rhtml
1
<% form_tag({:controller => 'repositories', :action => 'diff', :id => @project, :path => path}, :method => :get) do %>
1
<% form_tag({:controller => 'repositories', :action => 'diff', :id => @project, :path => to_path_param(path)}, :method => :get) do %>
2 2
<table class="list changesets">
3 3
<thead><tr>
4 4
<th>#</th>
trunk/app/views/repositories/changes.rhtml
4 4

  
5 5
<p>
6 6
<% if @repository.supports_cat? %>
7
    <%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => @path, :rev => @rev } %> |
7
    <%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => to_path_param(@path), :rev => @rev } %> |
8 8
<% end %>
9 9
<% if @repository.supports_annotate? %>
10
    <%= link_to l(:button_annotate), {:action => 'annotate', :id => @project, :path => @path, :rev => @rev } %> |
10
    <%= link_to l(:button_annotate), {:action => 'annotate', :id => @project, :path => to_path_param(@path), :rev => @rev } %> |
11 11
<% end %>
12
<%= link_to(l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' }) if @repository.supports_cat? %>
12
<%= link_to(l(:button_download), {:action => 'entry', :id => @project, :path => to_path_param(@path), :rev => @rev, :format => 'raw' }) if @repository.supports_cat? %>
13 13
<%= "(#{number_to_human_size(@entry.size)})" if @entry.size %>
14 14
</p>
15 15

  
trunk/app/views/repositories/revision.rhtml
55 55
<%= "(#{change.revision})" unless change.revision.blank?  %></td>
56 56
<td align="right">
57 57
<% if change.action == "M" %>
58
<%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.relative_path), :rev => @changeset.revision %>
58
<%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => to_path_param(change.relative_path), :rev => @changeset.revision %>
59 59
<% end %>
60 60
</td>
61 61
</tr>
trunk/config/boot.rb
1
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
1
# Don't change this file!
2
# Configure your app in config/environment.rb and config/environments/*.rb
2 3

  
3
unless defined?(RAILS_ROOT)
4
  root_path = File.join(File.dirname(__FILE__), '..')
5
  unless RUBY_PLATFORM =~ /mswin32/
6
    require 'pathname'
7
    root_path = Pathname.new(root_path).cleanpath(true).to_s
4
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5

  
6
module Rails
7
  class << self
8
    def boot!
9
      unless booted?
10
        preinitialize
11
        pick_boot.run
12
      end
13
    end
14

  
15
    def booted?
16
      defined? Rails::Initializer
17
    end
18

  
19
    def pick_boot
20
      (vendor_rails? ? VendorBoot : GemBoot).new
21
    end
22

  
23
    def vendor_rails?
24
      File.exist?("#{RAILS_ROOT}/vendor/rails")
25
    end
26

  
27
    def preinitialize
28
      load(preinitializer_path) if File.exist?(preinitializer_path)
29
    end
30

  
31
    def preinitializer_path
32
      "#{RAILS_ROOT}/config/preinitializer.rb"
33
    end
8 34
  end
9
  RAILS_ROOT = root_path
10
end
11 35

  
12
if File.directory?("#{RAILS_ROOT}/vendor/rails")
13
  require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
14
else
15
  require 'rubygems'
16
  require 'initializer'
36
  class Boot
37
    def run
38
      load_initializer
39
      Rails::Initializer.run(:set_load_path)
40
    end
41
  end
42

  
43
  class VendorBoot < Boot
44
    def load_initializer
45
      require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
      Rails::Initializer.run(:install_gem_spec_stubs)
47
    end
48
  end
49

  
50
  class GemBoot < Boot
51
    def load_initializer
52
      self.class.load_rubygems
53
      load_rails_gem
54
      require 'initializer'
55
    end
56

  
57
    def load_rails_gem
58
      if version = self.class.gem_version
59
        gem 'rails', version
60
      else
61
        gem 'rails'
62
      end
63
    rescue Gem::LoadError => load_error
64
      $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
      exit 1
66
    end
67

  
68
    class << self
69
      def rubygems_version
70
        Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
      end
72

  
73
      def gem_version
74
        if defined? RAILS_GEM_VERSION
75
          RAILS_GEM_VERSION
76
        elsif ENV.include?('RAILS_GEM_VERSION')
77
          ENV['RAILS_GEM_VERSION']
78
        else
79
          parse_gem_version(read_environment_rb)
80
        end
81
      end
82

  
83
      def load_rubygems
84
        require 'rubygems'
85

  
86
        unless rubygems_version >= '0.9.4'
87
          $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
          exit 1
89
        end
90

  
91
      rescue LoadError
92
        $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
        exit 1
94
      end
95

  
96
      def parse_gem_version(text)
97
        $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
      end
99

  
100
      private
101
        def read_environment_rb
102
          File.read("#{RAILS_ROOT}/config/environment.rb")
103
        end
104
    end
105
  end
17 106
end
18 107

  
19
Rails::Initializer.run(:set_load_path)
108
# All that for this:
109
Rails.boot!
trunk/config/environment.rb
5 5
# ENV['RAILS_ENV'] ||= 'production'
6 6

  
7 7
# Specifies gem version of Rails to use when vendor/rails is not present
8
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
8
RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
9 9

  
10 10
# Bootstrap the Rails environment, frameworks, and default configuration
11 11
require File.join(File.dirname(__FILE__), 'boot')
......
71 71
	config.action_mailer.delivery_method = :smtp  
72 72

  
73 73
end
74

  
75
ActiveRecord::Errors.default_error_messages = {
76
  :inclusion => "activerecord_error_inclusion",
77
  :exclusion => "activerecord_error_exclusion",
78
  :invalid => "activerecord_error_invalid",
79
  :confirmation => "activerecord_error_confirmation",
80
  :accepted  => "activerecord_error_accepted",
81
  :empty => "activerecord_error_empty",
82
  :blank => "activerecord_error_blank",
83
  :too_long => "activerecord_error_too_long",
84
  :too_short => "activerecord_error_too_short",
85
  :wrong_length => "activerecord_error_wrong_length",
86
  :taken => "activerecord_error_taken",
87
  :not_a_number => "activerecord_error_not_a_number"
88
}
89

  
90
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
91

  
92
Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)
93
Mime::Type.register 'application/pdf', :pdf
94

  
95
GLoc.set_config :default_language => :en
96
GLoc.clear_strings
97
GLoc.set_kcode
98
GLoc.load_localized_strings
99
GLoc.set_config(:raise_string_not_found_errors => false)
100

  
101
require 'redmine'
102

  
trunk/config/initializers/10-patches.rb
1

  
2
ActiveRecord::Errors.default_error_messages = {
3
  :inclusion => "activerecord_error_inclusion",
4
  :exclusion => "activerecord_error_exclusion",
5
  :invalid => "activerecord_error_invalid",
6
  :confirmation => "activerecord_error_confirmation",
7
  :accepted  => "activerecord_error_accepted",
8
  :empty => "activerecord_error_empty",
9
  :blank => "activerecord_error_blank",
10
  :too_long => "activerecord_error_too_long",
11
  :too_short => "activerecord_error_too_short",
12
  :wrong_length => "activerecord_error_wrong_length",
13
  :taken => "activerecord_error_taken",
14
  :not_a_number => "activerecord_error_not_a_number"
15
}
16

  
17
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
0 18

  
trunk/config/initializers/20-mime_types.rb
1
# Add new mime types for use in respond_to blocks:
2

  
3
Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)
4
Mime::Type.register 'application/pdf', :pdf
0 5

  
trunk/config/initializers/30-redmine.rb
1
GLoc.set_config :default_language => :en
2
GLoc.clear_strings
3
GLoc.set_kcode
4
GLoc.load_localized_strings
5
GLoc.set_config(:raise_string_not_found_errors => false)
6

  
7
require 'redmine'
0 8

  
trunk/db/migrate/072_add_enumerations_position.rb
1 1
class AddEnumerationsPosition < ActiveRecord::Migration
2 2
  def self.up
3 3
    add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position')
4
    Enumeration.find(:all).group_by(&:opt).each_value  do |enums|
4
    Enumeration.find(:all).group_by(&:opt).each do |opt, enums|
5 5
      enums.each_with_index do |enum, i|
6 6
        # do not call model callbacks
7 7
        Enumeration.update_all "position = #{i+1}", {:id => enum.id}
trunk/db/migrate/078_add_custom_fields_position.rb
1 1
class AddCustomFieldsPosition < ActiveRecord::Migration
2 2
  def self.up
3 3
    add_column(:custom_fields, :position, :integer, :default => 1)
4
    CustomField.find(:all).group_by(&:type).each_value  do |fields|
4
    CustomField.find(:all).group_by(&:type).each  do |t, fields|
5 5
      fields.each_with_index do |field, i|
6 6
        # do not call model callbacks
7 7
        CustomField.update_all "position = #{i+1}", {:id => field.id}
trunk/lib/tabular_form_builder.rb
22 22
  
23 23
  def initialize(object_name, object, template, options, proc)
24 24
    set_language_if_valid options.delete(:lang)
25
    @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc        
25
    super
26 26
  end      
27 27
      
28 28
  (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
trunk/script/dbconsole
1
#!/usr/bin/env ruby
2
require File.dirname(__FILE__) + '/../config/boot'
3
require 'commands/dbconsole'
0 4

  
trunk/script/performance/request
1
#!/usr/bin/env ruby
2
require File.dirname(__FILE__) + '/../../config/boot'
3
require 'commands/performance/request'
0 4

  
trunk/script/process/inspector
1
#!/usr/bin/env ruby
2
require File.dirname(__FILE__) + '/../../config/boot'
3
require 'commands/process/inspector'
0 4

  
trunk/test/functional/projects_controller_test.rb
38 38
    assert_template 'index'
39 39
    assert_not_nil assigns(:project_tree)
40 40
    # Root project as hash key
41
    assert assigns(:project_tree).has_key?(Project.find(1))
41
    assert assigns(:project_tree).keys.include?(Project.find(1))
42 42
    # Subproject in corresponding value
43 43
    assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
44 44
  end
trunk/test/integration/issues_test.rb
20 20
class IssuesTest < ActionController::IntegrationTest
21 21
  fixtures :projects, 
22 22
           :users,
23
           :roles,
24
           :members,
23 25
           :trackers,
24 26
           :projects_trackers,
27
           :enabled_modules,
25 28
           :issue_statuses,
26 29
           :issues,
27 30
           :enumerations,
trunk/test/test_helper.rb
65 65
    Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
66 66
  end
67 67
end
68

  
69

  
70
# ActionController::TestUploadedFile bug
71
# see http://dev.rubyonrails.org/ticket/4635
72
class String
73
  def original_filename
74
    "testfile.txt"
75
  end
76
  
77
  def content_type
78
    "text/plain"
79
  end
80
  
81
  def read
82
    self.to_s
83
  end
84
end
trunk/test/unit/role_test.rb
26 26
    
27 27
    target = Role.new(:name => 'Target')
28 28
    assert target.save
29
    assert target.workflows.copy(source)
29
    target.workflows.copy(source)
30 30
    target.reload
31 31
    assert_equal 90, target.workflows.size
32 32
  end
trunk/test/unit/tracker_test.rb
26 26
    
27 27
    target = Tracker.new(:name => 'Target')
28 28
    assert target.save
29
    assert target.workflows.copy(source)
29
    target.workflows.copy(source)
30 30
    target.reload
31 31
    assert_equal 89, target.workflows.size
32 32
  end
trunk/vendor/plugins/acts_as_versioned/Rakefile
1
require 'rubygems'
2

  
3
Gem::manage_gems
4

  
5
require 'rake/rdoctask'
6
require 'rake/packagetask'
7
require 'rake/gempackagetask'
8
require 'rake/testtask'
9
require 'rake/contrib/rubyforgepublisher'
10

  
11
PKG_NAME           = 'acts_as_versioned'
12
PKG_VERSION        = '0.3.1'
13
PKG_FILE_NAME      = "#{PKG_NAME}-#{PKG_VERSION}"
14
PROD_HOST          = "[email protected]"
15
RUBY_FORGE_PROJECT = 'ar-versioned'
16
RUBY_FORGE_USER    = 'technoweenie'
17

  
18
desc 'Default: run unit tests.'
19
task :default => :test
20

  
21
desc 'Test the calculations plugin.'
22
Rake::TestTask.new(:test) do |t|
23
  t.libs << 'lib'
24
  t.pattern = 'test/**/*_test.rb'
25
  t.verbose = true
26
end
27

  
28
desc 'Generate documentation for the calculations plugin.'
29
Rake::RDocTask.new(:rdoc) do |rdoc|
30
  rdoc.rdoc_dir = 'rdoc'
31
  rdoc.title    = "#{PKG_NAME} -- Simple versioning with active record models"
32
  rdoc.options << '--line-numbers --inline-source'
33
  rdoc.rdoc_files.include('README', 'CHANGELOG', 'RUNNING_UNIT_TESTS')
34
  rdoc.rdoc_files.include('lib/**/*.rb')
35
end
36

  
37
spec = Gem::Specification.new do |s|
38
  s.name            = PKG_NAME
39
  s.version         = PKG_VERSION
40
  s.platform        = Gem::Platform::RUBY
41
  s.summary         = "Simple versioning with active record models"
42
  s.files           = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE CHANGELOG RUNNING_UNIT_TESTS)
43
  s.files.delete      "acts_as_versioned_plugin.sqlite.db"
44
  s.files.delete      "acts_as_versioned_plugin.sqlite3.db"
45
  s.files.delete      "test/debug.log"
46
  s.require_path    = 'lib'
47
  s.autorequire     = 'acts_as_versioned'
48
  s.has_rdoc        = true
49
  s.test_files      = Dir['test/**/*_test.rb']
50
  s.add_dependency    'activerecord', '>= 1.10.1'
51
  s.add_dependency    'activesupport', '>= 1.1.1'
52
  s.author          = "Rick Olson"
53
  s.email           = "[email protected]"
54
  s.homepage        = "http://techno-weenie.net"
55
end
56

  
57
Rake::GemPackageTask.new(spec) do |pkg|
58
  pkg.need_tar = true
59
end
60

  
61
desc "Publish the API documentation"
62
task :pdoc => [:rdoc] do
63
  Rake::RubyForgePublisher.new(RUBY_FORGE_PROJECT, RUBY_FORGE_USER).upload
64
end
65

  
66
desc 'Publish the gem and API docs'
67
task :publish => [:pdoc, :rubyforge_upload]
68

  
69
desc "Publish the release files to RubyForge."
70
task :rubyforge_upload => :package do
71
  files = %w(gem tgz).map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
72

  
73
  if RUBY_FORGE_PROJECT then
74
    require 'net/http'
75
    require 'open-uri'
76

  
77
    project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
78
    project_data = open(project_uri) { |data| data.read }
79
    group_id = project_data[/[?&]group_id=(\d+)/, 1]
80
    raise "Couldn't get group id" unless group_id
81

  
82
    # This echos password to shell which is a bit sucky
83
    if ENV["RUBY_FORGE_PASSWORD"]
84
      password = ENV["RUBY_FORGE_PASSWORD"]
85
    else
86
      print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
87
      password = STDIN.gets.chomp
88
    end
89

  
90
    login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
91
      data = [
92
        "login=1",
93
        "form_loginname=#{RUBY_FORGE_USER}",
94
        "form_pw=#{password}"
95
      ].join("&")
96
      http.post("/account/login.php", data)
97
    end
98

  
99
    cookie = login_response["set-cookie"]
100
    raise "Login failed" unless cookie
101
    headers = { "Cookie" => cookie }
102

  
103
    release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
104
    release_data = open(release_uri, headers) { |data| data.read }
105
    package_id = release_data[/[?&]package_id=(\d+)/, 1]
106
    raise "Couldn't get package id" unless package_id
107

  
108
    first_file = true
109
    release_id = ""
110

  
111
    files.each do |filename|
112
      basename  = File.basename(filename)
113
      file_ext  = File.extname(filename)
114
      file_data = File.open(filename, "rb") { |file| file.read }
115

  
116
      puts "Releasing #{basename}..."
117

  
118
      release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
119
        release_date = Time.now.strftime("%Y-%m-%d %H:%M")
120
        type_map = {
121
          ".zip"    => "3000",
122
          ".tgz"    => "3110",
123
          ".gz"     => "3110",
124
          ".gem"    => "1400"
125
        }; type_map.default = "9999"
126
        type = type_map[file_ext]
127
        boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
128

  
129
        query_hash = if first_file then
130
          {
131
            "group_id" => group_id,
132
            "package_id" => package_id,
133
            "release_name" => PKG_FILE_NAME,
134
            "release_date" => release_date,
135
            "type_id" => type,
136
            "processor_id" => "8000", # Any
137
            "release_notes" => "",
138
            "release_changes" => "",
139
            "preformatted" => "1",
140
            "submit" => "1"
141
          }
142
        else
143
          {
144
            "group_id" => group_id,
145
            "release_id" => release_id,
146
            "package_id" => package_id,
147
            "step2" => "1",
148
            "type_id" => type,
149
            "processor_id" => "8000", # Any
150
            "submit" => "Add This File"
151
          }
152
        end
153

  
154
        query = "?" + query_hash.map do |(name, value)|
155
          [name, URI.encode(value)].join("=")
156
        end.join("&")
157

  
158
        data = [
159
          "--" + boundary,
160
          "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
161
          "Content-Type: application/octet-stream",
162
          "Content-Transfer-Encoding: binary",
163
          "", file_data, ""
164
          ].join("\x0D\x0A")
165

  
166
        release_headers = headers.merge(
167
          "Content-Type" => "multipart/form-data; boundary=#{boundary}"
168
        )
169

  
170
        target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
171
        http.post(target + query, data, release_headers)
172
      end
173

  
174
      if first_file then
175
        release_id = release_response.body[/release_id=(\d+)/, 1]
176
        raise("Couldn't get release id") unless release_id
177
      end
178

  
179
      first_file = false
180
    end
181
  end
1
require 'rubygems'

2

  
3
Gem::manage_gems

4

  
5
require 'rake/rdoctask'

6
require 'rake/packagetask'

7
require 'rake/gempackagetask'

8
require 'rake/testtask'

9
require 'rake/contrib/rubyforgepublisher'

10

  
11
PKG_NAME           = 'acts_as_versioned'

12
PKG_VERSION        = '0.3.1'

13
PKG_FILE_NAME      = "#{PKG_NAME}-#{PKG_VERSION}"

14
PROD_HOST          = "[email protected]"

15
RUBY_FORGE_PROJECT = 'ar-versioned'

16
RUBY_FORGE_USER    = 'technoweenie'

17

  
18
desc 'Default: run unit tests.'

19
task :default => :test

20

  
21
desc 'Test the calculations plugin.'

22
Rake::TestTask.new(:test) do |t|

23
  t.libs << 'lib'

24
  t.pattern = 'test/**/*_test.rb'

25
  t.verbose = true

26
end

27

  
28
desc 'Generate documentation for the calculations plugin.'

29
Rake::RDocTask.new(:rdoc) do |rdoc|

30
  rdoc.rdoc_dir = 'rdoc'

31
  rdoc.title    = "#{PKG_NAME} -- Simple versioning with active record models"

32
  rdoc.options << '--line-numbers --inline-source'

33
  rdoc.rdoc_files.include('README', 'CHANGELOG', 'RUNNING_UNIT_TESTS')

34
  rdoc.rdoc_files.include('lib/**/*.rb')

35
end

36

  
37
spec = Gem::Specification.new do |s|

38
  s.name            = PKG_NAME

39
  s.version         = PKG_VERSION

40
  s.platform        = Gem::Platform::RUBY

41
  s.summary         = "Simple versioning with active record models"

42
  s.files           = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE CHANGELOG RUNNING_UNIT_TESTS)

43
  s.files.delete      "acts_as_versioned_plugin.sqlite.db"

44
  s.files.delete      "acts_as_versioned_plugin.sqlite3.db"

45
  s.files.delete      "test/debug.log"

46
  s.require_path    = 'lib'

47
  s.autorequire     = 'acts_as_versioned'

48
  s.has_rdoc        = true

49
  s.test_files      = Dir['test/**/*_test.rb']

50
  s.add_dependency    'activerecord', '>= 1.10.1'

51
  s.add_dependency    'activesupport', '>= 1.1.1'

52
  s.author          = "Rick Olson"

53
  s.email           = "[email protected]"

54
  s.homepage        = "http://techno-weenie.net"

55
end

56

  
57
Rake::GemPackageTask.new(spec) do |pkg|

58
  pkg.need_tar = true

59
end

60

  
61
desc "Publish the API documentation"

62
task :pdoc => [:rdoc] do

63
  Rake::RubyForgePublisher.new(RUBY_FORGE_PROJECT, RUBY_FORGE_USER).upload

64
end

65

  
66
desc 'Publish the gem and API docs'

67
task :publish => [:pdoc, :rubyforge_upload]

68

  
69
desc "Publish the release files to RubyForge."

70
task :rubyforge_upload => :package do

71
  files = %w(gem tgz).map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }

72

  
73
  if RUBY_FORGE_PROJECT then

74
    require 'net/http'

75
    require 'open-uri'

76

  
77
    project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"

78
    project_data = open(project_uri) { |data| data.read }

79
    group_id = project_data[/[?&]group_id=(\d+)/, 1]

80
    raise "Couldn't get group id" unless group_id

81

  
82
    # This echos password to shell which is a bit sucky

83
    if ENV["RUBY_FORGE_PASSWORD"]

84
      password = ENV["RUBY_FORGE_PASSWORD"]

85
    else

86
      print "#{RUBY_FORGE_USER}@rubyforge.org's password: "

87
      password = STDIN.gets.chomp

88
    end

89

  
90
    login_response = Net::HTTP.start("rubyforge.org", 80) do |http|

91
      data = [

92
        "login=1",

93
        "form_loginname=#{RUBY_FORGE_USER}",

94
        "form_pw=#{password}"

95
      ].join("&")

96
      http.post("/account/login.php", data)

97
    end

98

  
99
    cookie = login_response["set-cookie"]

100
    raise "Login failed" unless cookie

101
    headers = { "Cookie" => cookie }

102

  
103
    release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"

104
    release_data = open(release_uri, headers) { |data| data.read }

105
    package_id = release_data[/[?&]package_id=(\d+)/, 1]

106
    raise "Couldn't get package id" unless package_id

107

  
108
    first_file = true

109
    release_id = ""

110

  
111
    files.each do |filename|

112
      basename  = File.basename(filename)

113
      file_ext  = File.extname(filename)

114
      file_data = File.open(filename, "rb") { |file| file.read }

115

  
116
      puts "Releasing #{basename}..."

117

  
118
      release_response = Net::HTTP.start("rubyforge.org", 80) do |http|

119
        release_date = Time.now.strftime("%Y-%m-%d %H:%M")

120
        type_map = {

121
          ".zip"    => "3000",

122
          ".tgz"    => "3110",

123
          ".gz"     => "3110",

124
          ".gem"    => "1400"

125
        }; type_map.default = "9999"

126
        type = type_map[file_ext]

127
        boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"

128

  
129
        query_hash = if first_file then

130
          {

131
            "group_id" => group_id,

132
            "package_id" => package_id,

133
            "release_name" => PKG_FILE_NAME,

134
            "release_date" => release_date,

135
            "type_id" => type,

136
            "processor_id" => "8000", # Any

137
            "release_notes" => "",

138
            "release_changes" => "",

139
            "preformatted" => "1",

140
            "submit" => "1"

141
          }

142
        else

143
          {

144
            "group_id" => group_id,

145
            "release_id" => release_id,

146
            "package_id" => package_id,

147
            "step2" => "1",

148
            "type_id" => type,

149
            "processor_id" => "8000", # Any

150
            "submit" => "Add This File"

151
          }

152
        end

153

  
154
        query = "?" + query_hash.map do |(name, value)|

155
          [name, URI.encode(value)].join("=")

156
        end.join("&")

157

  
158
        data = [

159
          "--" + boundary,

160
          "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",

161
          "Content-Type: application/octet-stream",

162
          "Content-Transfer-Encoding: binary",

163
          "", file_data, ""

164
          ].join("\x0D\x0A")

165

  
166
        release_headers = headers.merge(

167
          "Content-Type" => "multipart/form-data; boundary=#{boundary}"

168
        )

169

  
170
        target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"

171
        http.post(target + query, data, release_headers)

172
      end

173

  
174
      if first_file then

175
        release_id = release_response.body[/release_id=(\d+)/, 1]

176
        raise("Couldn't get release id") unless release_id

177
      end

178

  
179
      first_file = false

180
    end

181
  end

182 182
end
trunk/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
22 22
module ActiveRecord #:nodoc:
23 23
  module Acts #:nodoc:
24 24
    # Specify this act if you want to save a copy of the row in a versioned table.  This assumes there is a 
25
    # versioned table ready and that your model has a version field.  This works with optimisic locking if the lock_version
25
    # versioned table ready and that your model has a version field.  This works with optimistic locking if the lock_version
26 26
    # column is present as well.
27 27
    #
28 28
    # The class for the versioned model is derived the first time it is seen. Therefore, if you change your database schema you have to restart
......
49 49
    #   page.revert_to(page.versions.last) # using versioned instance
50 50
    #   page.title         # => 'hello world'
51 51
    #
52
    #   page.versions.earliest # efficient query to find the first version
53
    #   page.versions.latest   # efficient query to find the most recently created version
54
    #
55
    #
56
    # Simple Queries to page between versions
57
    #
58
    #   page.versions.before(version) 
59
    #   page.versions.after(version)
60
    #
61
    # Access the previous/next versions from the versioned model itself
62
    #
63
    #   version = page.versions.latest
64
    #   version.previous # go back one version
65
    #   version.next     # go forward one version
66
    #
52 67
    # See ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned for configuration options
53 68
    module Versioned
54
      CALLBACKS = [:set_new_version, :save_version_on_create, :save_version?, :clear_changed_attributes]
69
      CALLBACKS = [:set_new_version, :save_version_on_create, :save_version?, :clear_altered_attributes]
55 70
      def self.included(base) # :nodoc:
56 71
        base.extend ClassMethods
57 72
      end
......
80 95
        #     end
81 96
        #
82 97
        # * <tt>if_changed</tt> - Simple way of specifying attributes that are required to be changed before saving a model.  This takes
83
        #   either a symbol or array of symbols.  WARNING - This will attempt to overwrite any attribute setters you may have.  
98
        #   either a symbol or array of symbols.  WARNING - This will attempt to overwrite any attribute setters you may have.
84 99
        #   Use this instead if you want to write your own attribute setters (and ignore if_changed):
85 100
        # 
86 101
        #     def name=(new_name)
......
133 148
        #       # that create_table does
134 149
        #       Post.create_versioned_table
135 150
        #     end
136
        #   
151
        # 
137 152
        #     def self.down
138 153
        #       Post.drop_versioned_table
139 154
        #     end
......
157 172
          return if self.included_modules.include?(ActiveRecord::Acts::Versioned::ActMethods)
158 173

  
159 174
          send :include, ActiveRecord::Acts::Versioned::ActMethods
160
          
175

  
161 176
          cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name, :versioned_inheritance_column, 
162
            :version_column, :max_version_limit, :track_changed_attributes, :version_condition, :version_sequence_name, :non_versioned_columns,
177
            :version_column, :max_version_limit, :track_altered_attributes, :version_condition, :version_sequence_name, :non_versioned_columns,
163 178
            :version_association_options
164
            
179

  
165 180
          # legacy
166 181
          alias_method :non_versioned_fields,  :non_versioned_columns
167 182
          alias_method :non_versioned_fields=, :non_versioned_columns=
......
171 186
            alias_method :non_versioned_fields=, :non_versioned_columns=
172 187
          end
173 188

  
174
          send :attr_accessor, :changed_attributes
189
          send :attr_accessor, :altered_attributes
175 190

  
176 191
          self.versioned_class_name         = options[:class_name]  || "Version"
177 192
          self.versioned_foreign_key        = options[:foreign_key] || self.to_s.foreign_key
......
184 199
          self.non_versioned_columns        = [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
185 200
          self.version_association_options  = {
186 201
                                                :class_name  => "#{self.to_s}::#{versioned_class_name}",
187
                                                :foreign_key => "#{versioned_foreign_key}",
188
                                                :order       => 'version',
202
                                                :foreign_key => versioned_foreign_key,
189 203
                                                :dependent   => :delete_all
190 204
                                              }.merge(options[:association_options] || {})
191 205

  
......
194 208
            silence_warnings do
195 209
              self.const_set(extension_module_name, Module.new(&extension))
196 210
            end
197
            
211

  
198 212
            options[:extend] = self.const_get(extension_module_name)
199 213
          end
200 214

  
201 215
          class_eval do
202
            has_many :versions, version_association_options
216
            has_many :versions, version_association_options do
217
              # finds earliest version of this record
218
              def earliest
219
                @earliest ||= find(:first, :order => 'version')
220
              end
221

  
222
              # find latest version of this record
223
              def latest
224
                @latest ||= find(:first, :order => 'version desc')
225
              end
226
            end
203 227
            before_save  :set_new_version
204 228
            after_create :save_version_on_create
205 229
            after_update :save_version
206 230
            after_save   :clear_old_versions
207
            after_save   :clear_changed_attributes
208
            
231
            after_save   :clear_altered_attributes
232

  
209 233
            unless options[:if_changed].nil?
210
              self.track_changed_attributes = true
234
              self.track_altered_attributes = true
211 235
              options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array)
212 236
              options[:if_changed].each do |attr_name|
213 237
                define_method("#{attr_name}=") do |value|
......
215 239
                end
216 240
              end
217 241
            end
218
            
242

  
219 243
            include options[:extend] if options[:extend].is_a?(Module)
220 244
          end
221 245

  
222 246
          # create the dynamic versioned model
223 247
          const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do
224 248
            def self.reloadable? ; false ; end
249
            # find first version before the given version
250
            def self.before(version)
251
              find :first, :order => 'version desc',
252
                :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version]
253
            end
254

  
255
            # find first version after the given version.
256
            def self.after(version)
257
              find :first, :order => 'version',
258
                :conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version]
259
            end
260

  
261
            def previous
262
              self.class.before(self)
263
            end
264

  
265
            def next
266
              self.class.after(self)
267
            end
268

  
269
            def versions_count
270
              page.version
271
            end
225 272
          end
226
          
273

  
274
          versioned_class.cattr_accessor :original_class
275
          versioned_class.original_class = self
227 276
          versioned_class.set_table_name versioned_table_name
228 277
          versioned_class.belongs_to self.to_s.demodulize.underscore.to_sym, 
229 278
            :class_name  => "::#{self.to_s}", 
......
232 281
          versioned_class.set_sequence_name version_sequence_name if version_sequence_name
233 282
        end
234 283
      end
235
    
284

  
236 285
      module ActMethods
237 286
        def self.included(base) # :nodoc:
238 287
          base.extend ClassMethods
239 288
        end
240
        
289

  
290
        # Finds a specific version of this record
291
        def find_version(version = nil)
292
          self.class.find_version(id, version)
293
        end
294

  
241 295
        # Saves a version of the model if applicable
242 296
        def save_version
243 297
          save_version_on_create if save_version?
244 298
        end
245
        
299

  
246 300
        # Saves a version of the model in the versioned table.  This is called in the after_save callback by default
247 301
        def save_version_on_create
248 302
          rev = self.class.versioned_class.new
......
263 317
          end
264 318
        end
265 319

  
266
        # Finds a specific version of this model.
267
        def find_version(version)
268
          return version if version.is_a?(self.class.versioned_class)
269
          return nil if version.is_a?(ActiveRecord::Base)
270
          find_versions(:conditions => ['version = ?', version], :limit => 1).first
320
        def versions_count
321
          version
271 322
        end
272
        
273
        # Finds versions of this model.  Takes an options hash like <tt>find</tt>
274
        def find_versions(options = {})
275
          versions.find(:all, options)
276
        end
277 323

  
278 324
        # Reverts a model to a given version.  Takes either a version number or an instance of the versioned model
279 325
        def revert_to(version)
280 326
          if version.is_a?(self.class.versioned_class)
281 327
            return false unless version.send(self.class.versioned_foreign_key) == self.id and !version.new_record?
282 328
          else
283
            return false unless version = find_version(version)
329
            return false unless version = versions.find_by_version(version)
284 330
          end
285 331
          self.clone_versioned_model(version, self)
286 332
          self.send("#{self.class.version_column}=", version.version)
287 333
          true
288 334
        end
289 335

  
290
        # Reverts a model to a given version and saves the model.  
336
        # Reverts a model to a given version and saves the model.
291 337
        # Takes either a version number or an instance of the versioned model
292 338
        def revert_to!(version)
293 339
          revert_to(version) ? save_without_revision : false
......
313 359
        def versioned_attributes
314 360
          self.attributes.keys.select { |k| !self.class.non_versioned_columns.include?(k) }
315 361
        end
316
        
362

  
317 363
        # If called with no parameters, gets whether the current model has changed and needs to be versioned.
318 364
        # If called with a single parameter, gets whether the parameter has changed.
319 365
        def changed?(attr_name = nil)
320 366
          attr_name.nil? ?
321
            (!self.class.track_changed_attributes || (changed_attributes && changed_attributes.length > 0)) :
322
            (changed_attributes && changed_attributes.include?(attr_name.to_s))
367
            (!self.class.track_altered_attributes || (altered_attributes && altered_attributes.length > 0)) :
368
            (altered_attributes && altered_attributes.include?(attr_name.to_s))
323 369
        end
324
        
370

  
325 371
        # keep old dirty? method
326 372
        alias_method :dirty?, :changed?
327
        
373

  
328 374
        # Clones a model.  Used when saving a new version or reverting a model's version.
329 375
        def clone_versioned_model(orig_model, new_model)
330 376
          self.versioned_attributes.each do |key|
331
            new_model.send("#{key}=", orig_model.attributes[key]) if orig_model.has_attribute?(key)
377
            new_model.send("#{key}=", orig_model.send(key)) if orig_model.has_attribute?(key)
332 378
          end
333
          
379

  
334 380
          if orig_model.is_a?(self.class.versioned_class)
335 381
            new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
336 382
          elsif new_model.is_a?(self.class.versioned_class)
337 383
            new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
338 384
          end
339 385
        end
340
        
386

  
341 387
        # Checks whether a new version shall be saved or not.  Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
342 388
        def save_version?
343 389
          version_condition_met? && changed?
344 390
        end
345
        
391

  
346 392
        # Checks condition set in the :if option to check whether a revision should be created or not.  Override this for
347 393
        # custom version condition checking.
348 394
        def version_condition_met?
......
353 399
            version_condition.call(self)
354 400
          else
355 401
            version_condition
356
          end          
402
          end
357 403
        end
358 404

  
359 405
        # Executes the block with the versioning callbacks disabled.
......
378 424

  
379 425
        def empty_callback() end #:nodoc:
380 426

  
381
        protected          
427
        protected
382 428
          # sets the new version before saving, unless you're using optimistic locking.  In that case, let it take care of the version.
383 429
          def set_new_version
384 430
            self.send("#{self.class.version_column}=", self.next_version) if new_record? || (!locking_enabled? && save_version?)
385 431
          end
386
          
432

  
387 433
          # Gets the next available version for the current record, or 1 for a new record
388 434
          def next_version
389 435
            return 1 if new_record?
390 436
            (versions.calculate(:max, :version) || 0) + 1
391 437
          end
392
          
438

  
393 439
          # clears current changed attributes.  Called after save.
394
          def clear_changed_attributes
395
            self.changed_attributes = []
440
          def clear_altered_attributes
441
            self.altered_attributes = []
396 442
          end
397 443

  
398 444
          def write_changed_attribute(attr_name, attr_value)
399 445
            # Convert to db type for comparison. Avoids failing Float<=>String comparisons.
400 446
            attr_value_for_db = self.class.columns_hash[attr_name.to_s].type_cast(attr_value)
401
            (self.changed_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) || self.send(attr_name) == attr_value_for_db
447
            (self.altered_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) || self.send(attr_name) == attr_value_for_db
402 448
            write_attribute(attr_name, attr_value_for_db)
403 449
          end
404 450

  
405
        private
406
          CALLBACKS.each do |attr_name| 
407
            alias_method "orig_#{attr_name}".to_sym, attr_name
408
          end
409

  
410 451
        module ClassMethods
411 452
          # Finds a specific version of a specific row of this model
412
          def find_version(id, version)
413
            find_versions(id, 
414
              :conditions => ["#{versioned_foreign_key} = ? AND version = ?", id, version], 
415
              :limit => 1).first
453
          def find_version(id, version = nil)
454
            return find(id) unless version
455

  
456
            conditions = ["#{versioned_foreign_key} = ? AND version = ?", id, version]
457
            options = { :conditions => conditions, :limit => 1 }
458

  
459
            if result = find_versions(id, options).first
460
              result
461
            else
462
              raise RecordNotFound, "Couldn't find #{name} with ID=#{id} and VERSION=#{version}"
463
            end
416 464
          end
417
        
465

  
418 466
          # Finds versions of a specific model.  Takes an options hash like <tt>find</tt>
419 467
          def find_versions(id, options = {})
420 468
            versioned_class.find :all, {
......
426 474
          def versioned_columns
427 475
            self.columns.select { |c| !non_versioned_columns.include?(c.name) }
428 476
          end
429
    
477

  
430 478
          # Returns an instance of the dynamic versioned model
431 479
          def versioned_class
432 480
            const_get versioned_class_name
......
438 486
            if !self.content_columns.find { |c| %w(version lock_version).include? c.name }
439 487
              self.connection.add_column table_name, :version, :integer
440 488
            end
441
            
489

  
442 490
            self.connection.create_table(versioned_table_name, create_table_options) do |t|
443 491
              t.column versioned_foreign_key, :integer
444 492
              t.column :version, :integer
445 493
            end
446
            
494

  
447 495
            updated_col = nil
448 496
            self.versioned_columns.each do |col| 
449 497
              updated_col = col if !updated_col && %(updated_at updated_on).include?(col.name)
450 498
              self.connection.add_column versioned_table_name, col.name, col.type, 
451 499
                :limit => col.limit, 
452
                :default => col.default
500
                :default => col.default,
501
                :scale => col.scale,
502
                :precision => col.precision
453 503
            end
454
        
504

  
455 505
            if type_col = self.columns_hash[inheritance_column]
456 506
              self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, 
457 507
                :limit => type_col.limit, 
458
                :default => type_col.default
508
                :default => type_col.default,
509
                :scale => type_col.scale,
510
                :precision => type_col.precision
459 511
            end
460
    
512

  
461 513
            if updated_col.nil?
462 514
              self.connection.add_column versioned_table_name, :updated_at, :timestamp
463 515
            end
464 516
          end
465
          
517

  
466 518
          # Rake migration task to drop the versioned table
467 519
          def drop_versioned_table
468 520
            self.connection.drop_table versioned_table_name
469 521
          end
470
          
522

  
471 523
          # Executes the block with the versioning callbacks disabled.
472 524
          #
473 525
          #   Foo.without_revision do
......
476 528
          #
477 529
          def without_revision(&block)
478 530
            class_eval do 
479
              CALLBACKS.each do |attr_name| 
531
              CALLBACKS.each do |attr_name|
532
                alias_method "orig_#{attr_name}".to_sym, attr_name
480 533
                alias_method attr_name, :empty_callback
481 534
              end
482 535
            end
483
            result = block.call
536
            block.call
537
          ensure
484 538
            class_eval do 
485 539
              CALLBACKS.each do |attr_name|
486 540
                alias_method attr_name, "orig_#{attr_name}".to_sym
487 541
              end
488 542
            end
489
            result
490 543
          end
491 544

  
492 545
          # Turns off optimistic locking for the duration of the block
......
501 554
            result = block.call
502 555
            ActiveRecord::Base.lock_optimistically = true if current
503 556
            result
504
          end          
557
          end
505 558
        end
506 559
      end
507 560
    end
trunk/vendor/plugins/acts_as_versioned/test/abstract_unit.rb
1
$:.unshift(File.dirname(__FILE__) + '/../../../rails/activesupport/lib')
2
$:.unshift(File.dirname(__FILE__) + '/../../../rails/activerecord/lib')
1 3
$:.unshift(File.dirname(__FILE__) + '/../lib')
2

  
3 4
require 'test/unit'
4
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
5
require 'active_record/fixtures'
5
begin
6
  require 'active_support'
7
  require 'active_record'
8
  require 'active_record/fixtures'
9
rescue LoadError
10
  require 'rubygems'
11
  retry
12
end
13
require 'acts_as_versioned'
6 14

  
7 15
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
8 16
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
9
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
17
ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
18
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
10 19

  
11 20
load(File.dirname(__FILE__) + "/schema.rb")
12 21

  
......
19 28
end
20 29

  
21 30
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
22
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
31
$:.unshift(Test::Unit::TestCase.fixture_path)
23 32

  
24 33
class Test::Unit::TestCase #:nodoc:
25
  def create_fixtures(*table_names)
26
    if block_given?
27
      Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
28
    else
29
      Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
30
    end
31
  end
32

  
33 34
  # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
34 35
  self.use_transactional_fixtures = true
35 36
  
trunk/vendor/plugins/acts_as_versioned/test/fixtures/widget.rb
1 1
class Widget < ActiveRecord::Base
2 2
  acts_as_versioned :sequence_name => 'widgets_seq', :association_options => {
3
    :dependent => nil, :order => 'version desc'
3
    :dependent => :nullify, :order => 'version desc'
4 4
  }
5 5
  non_versioned_columns << 'foo'
6 6
end
trunk/vendor/plugins/acts_as_versioned/test/migration_test.rb
9 9
  class MigrationTest < Test::Unit::TestCase
10 10
    self.use_transactional_fixtures = false
11 11
    def teardown
12
      ActiveRecord::Base.connection.initialize_schema_information
13
      ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
14

  
12
      if ActiveRecord::Base.connection.respond_to?(:initialize_schema_information)
13
        ActiveRecord::Base.connection.initialize_schema_information
14
        ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
15
      else
16
        ActiveRecord::Base.connection.initialize_schema_migrations_table
17
        ActiveRecord::Base.connection.assume_migrated_upto_version(0)
18
      end
19
      
15 20
      Thing.connection.drop_table "things" rescue nil
16 21
      Thing.connection.drop_table "thing_versions" rescue nil
17 22
      Thing.reset_column_information
......
21 26
      assert_raises(ActiveRecord::StatementInvalid) { Thing.create :title => 'blah blah' }
22 27
      # take 'er up
23 28
      ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
24
      t = Thing.create :title => 'blah blah'
29
      t = Thing.create :title => 'blah blah', :price => 123.45, :type => 'Thing'
25 30
      assert_equal 1, t.versions.size
31
      
32
      # check that the price column has remembered its value correctly
33
      assert_equal t.price,  t.versions.first.price
34
      assert_equal t.title,  t.versions.first.title
35
      assert_equal t[:type], t.versions.first[:type]
36
      
37
      # make sure that the precision of the price column has been preserved
38
      assert_equal 7, Thing::Version.columns.find{|c| c.name == "price"}.precision
39
      assert_equal 2, Thing::Version.columns.find{|c| c.name == "price"}.scale
26 40

  
27 41
      # now lets take 'er back down
28 42
      ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/')
trunk/vendor/plugins/acts_as_versioned/test/versioned_test.rb
4 4

  
5 5
class VersionedTest < Test::Unit::TestCase
6 6
  fixtures :pages, :page_versions, :locked_pages, :locked_pages_revisions, :authors, :landmarks, :landmark_versions
7
  set_fixture_class :page_versions => Page::Version
7 8

  
8 9
  def test_saves_versioned_copy
9
    p = Page.create :title => 'first title', :body => 'first body'
10
    p = Page.create! :title => 'first title', :body => 'first body'
10 11
    assert !p.new_record?
11 12
    assert_equal 1, p.versions.size
12 13
    assert_equal 1, p.version
......
16 17
  def test_saves_without_revision
17 18
    p = pages(:welcome)
18 19
    old_versions = p.versions.count
19
    
20

  
20 21
    p.save_without_revision
21
    
22

  
22 23
    p.without_revision do
23 24
      p.update_attributes :title => 'changed'
24 25
    end
25
    
26

  
26 27
    assert_equal old_versions, p.versions.count
27 28
  end
28 29

  
......
30 31
    p = pages(:welcome)
31 32
    assert_equal 24, p.version
32 33
    assert_equal 'Welcome to the weblog', p.title
33
    
34

  
34 35
    assert p.revert_to!(p.versions.first.version), "Couldn't revert to 23"
35 36
    assert_equal 23, p.version
36 37
    assert_equal 'Welcome to the weblg', p.title
......
57 58
    p = pages(:welcome)
58 59
    assert_equal 24, p.version
59 60
    assert_equal 'Welcome to the weblog', p.title
60
    
61

  
61 62
    assert p.revert_to!(p.versions.first), "Couldn't revert to 23"
62 63
    assert_equal 23, p.version
63 64
    assert_equal 'Welcome to the weblg', p.title
64 65
  end
65
  
66

  
66 67
  def test_rollback_fails_with_invalid_revision
67 68
    p = locked_pages(:welcome)
68 69
    assert !p.revert_to!(locked_pages(:thinking))
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff