Permalink
Browse files

Fixing requirements in a migration instead

  • Loading branch information...
1 parent ec1c662 commit 0d7b4936fdfa24137570b9fa7c2e8ab3482b354f @qrush qrush committed Oct 27, 2009
Showing with 28 additions and 19 deletions.
  1. +2 −1 app/models/version.rb
  2. +23 −0 db/migrate/20091026234707_fix_dependencies.rb
  3. +1 −1 db/schema.rb
  4. +0 −15 lib/tasks/gemcutter.rake
  5. +2 −2 test/unit/version_test.rb
View
@@ -21,6 +21,7 @@ class Version < ActiveRecord::Base
:include => :rubygem,
:order => "versions.built_at desc" }
named_scope :latest, { :conditions => { :latest => true }}
+ named_scope :with_deps, { :include => {:dependencies => :rubygem} }
named_scope :prerelease, { :conditions => { :prerelease => true }}
named_scope :release, { :conditions => { :prerelease => false }}
@@ -160,7 +161,7 @@ def to_spec
spec.summary = summary
dependencies.each do |dep|
- spec.add_dependency(dep.rubygem.name, dep.requirements)
+ spec.add_dependency(dep.rubygem.name, dep.requirements.split(', '))
end
end
end
@@ -0,0 +1,23 @@
+class FixDependencies < ActiveRecord::Migration
+ def self.up
+ # fix bad version reqs
+ Dependency.all.each do |dep|
+ reqs = dep.requirements
+ begin
+ Gem::Requirement.new(reqs)
+ rescue ArgumentError => ex
+ list = reqs.split(/(>=)|(<=)|(~>)|(>)|(<)|(=)/).reject(&:empty?)
+ fixed = list[0] + list[1] + ", " + list[2] + list[3]
+
+ dep.update_attribute(:requirements, fixed)
+ end
+ end
+
+ # kill bad deps too
+ Dependency.all(:include => :rubygem).select { |v| v.rubygem.nil? }.each { |d| d.destroy }
+ end
+
+ def self.down
+ # yeah, no way
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20091021203534) do
+ActiveRecord::Schema.define(:version => 20091026234707) do
create_table "delayed_jobs", :force => true do |t|
t.integer "priority", :default => 0
View
@@ -16,21 +16,6 @@ namespace :gemcutter do
Rake::Task["gemcutter:import:process"].execute
end
- desc "Fix dependencies"
- task :fix_deps => :environment do
- Dependency.all.each do |dep|
- reqs = dep.requirements
- begin
- Gem::Requirement.new(reqs)
- rescue ArgumentError => ex
- list = reqs.split(/(>=)|(<=)|(~>)|(>)|(<)|(=)/).reject(&:empty?)
- fixed = list[0] + list[1] + ", " + list[2] + list[3]
-
- dep.update_attribute(:requirements, fixed)
- end
- end
- end
-
namespace :index do
desc "Create the index"
task :create => :environment do
@@ -135,13 +135,13 @@ class VersionTest < ActiveSupport::TestCase
end
should "create gemspec with some dependencies" do
- @dep_one = Factory(:dependency, :version => @version, :requirements => ">= 1.2.3")
+ @dep_one = Factory(:dependency, :version => @version, :requirements => ">= 0, = 1.2.3")
@dep_two = Factory(:dependency, :version => @version, :requirements => "= 3.0.0")
spec = @version.to_spec
assert_equal 2, spec.dependencies.size
assert_equal @dep_one.rubygem.name, spec.dependencies.last.name
- assert_equal [@dep_one.requirements], spec.dependencies.last.requirements_list
+ assert_equal @dep_one.requirements.split(", "), spec.dependencies.last.requirements_list
assert_equal @dep_two.rubygem.name, spec.dependencies.first.name
assert_equal [@dep_two.requirements], spec.dependencies.first.requirements_list

0 comments on commit 0d7b493

Please sign in to comment.