| |   |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | 39 | def full_repository_path |
| 40 | | File.expand_path(File.join(BASE_REPOSITORY_DIR, gitdir)) |
| 40 | self.class.full_path_from_partial_path(gitdir) |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | | def create_git_repository |
| 44 | | git_backend.create(full_repository_path) |
| 43 | def self.create_git_repository(path) |
| 44 | git_backend.create(full_path_from_partial_path(path)) |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | | def delete_git_repository |
| 48 | | git_backend.delete!(full_repository_path) |
| 47 | def self.delete_git_repository(path) |
| 48 | git_backend.delete!(full_path_from_partial_path(path)) |
| 49 | 49 | end |
| 50 | 50 | |
| 51 | 51 | def has_commits? |
| 52 | 52 | git_backend.repository_has_commits?(full_repository_path) |
| 53 | 53 | end |
| 54 | 54 | |
| 55 | def self.git_backend |
| 56 | RAILS_ENV == "test" ? MockGitBackend : GitBackend |
| 57 | end |
| 58 | |
| 55 | 59 | def git_backend |
| 56 | 60 | RAILS_ENV == "test" ? MockGitBackend : GitBackend |
| 57 | 61 | end |
| … | … | |
| 75 | 75 | end |
| 76 | 76 | |
| 77 | 77 | def create_new_repos_task |
| 78 | | Task.create!(:target => self, :command => "create_git_repository") |
| 78 | Task.create!(:target_class => self.class.name, |
| 79 | :command => "create_git_repository", :arguments => gitdir) |
| 79 | 80 | end |
| 80 | 81 | |
| 81 | 82 | def create_delete_repos_task |
| 82 | | Task.create!(:target => self, :command => "delete_git_repository") |
| 83 | Task.create!(:target_class => self.class.name, |
| 84 | :command => "delete_git_repository", :arguments => gitdir) |
| 83 | 85 | end |
| 84 | 86 | |
| 85 | 87 | protected |
| … | … | |
| 94 | 94 | def add_user_as_committer |
| 95 | 95 | committers << user |
| 96 | 96 | end |
| 97 | |
| 98 | def self.full_path_from_partial_path(path) |
| 99 | File.expand_path(File.join(BASE_REPOSITORY_DIR, path)) |
| 100 | end |
| 97 | 101 | end |
| toggle raw diff |
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -37,21 +37,25 @@ class Repository < ActiveRecord::Base
end
def full_repository_path
- File.expand_path(File.join(BASE_REPOSITORY_DIR, gitdir))
+ self.class.full_path_from_partial_path(gitdir)
end
- def create_git_repository
- git_backend.create(full_repository_path)
+ def self.create_git_repository(path)
+ git_backend.create(full_path_from_partial_path(path))
end
- def delete_git_repository
- git_backend.delete!(full_repository_path)
+ def self.delete_git_repository(path)
+ git_backend.delete!(full_path_from_partial_path(path))
end
def has_commits?
git_backend.repository_has_commits?(full_repository_path)
end
+ def self.git_backend
+ RAILS_ENV == "test" ? MockGitBackend : GitBackend
+ end
+
def git_backend
RAILS_ENV == "test" ? MockGitBackend : GitBackend
end
@@ -71,11 +75,13 @@ class Repository < ActiveRecord::Base
end
def create_new_repos_task
- Task.create!(:target => self, :command => "create_git_repository")
+ Task.create!(:target_class => self.class.name,
+ :command => "create_git_repository", :arguments => gitdir)
end
def create_delete_repos_task
- Task.create!(:target => self, :command => "delete_git_repository")
+ Task.create!(:target_class => self.class.name,
+ :command => "delete_git_repository", :arguments => gitdir)
end
protected
@@ -88,4 +94,8 @@ class Repository < ActiveRecord::Base
def add_user_as_committer
committers << user
end
+
+ def self.full_path_from_partial_path(path)
+ File.expand_path(File.join(BASE_REPOSITORY_DIR, path))
+ end
end |
| |   |
| 22 | 22 | %Q{\n### END KEY #{self.id || "nil"} ###} |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | | def add_to_authorized_keys(key_file_class=SshKeyFile) |
| 25 | def self.add_to_authorized_keys(keydata, key_file_class=SshKeyFile) |
| 26 | 26 | key_file = key_file_class.new |
| 27 | | key_file.add_key(self.to_key) |
| 27 | key_file.add_key(keydata) |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | | def delete_from_authorized_keys(key_file_class=SshKeyFile) |
| 30 | def self.delete_from_authorized_keys(keydata, key_file_class=SshKeyFile) |
| 31 | 31 | key_file = key_file_class.new |
| 32 | | key_file.delete_key(self.to_key) |
| 32 | key_file.delete_key(keydata) |
| 33 | 33 | end |
| 34 | 34 | |
| 35 | 35 | def create_new_task |
| 36 | | Task.create!(:target => self, :command => "add_to_authorized_keys") |
| 36 | Task.create!(:target_class => self.class.name, |
| 37 | :command => "add_to_authorized_keys", :arguments => self.to_key) |
| 37 | 38 | end |
| 38 | 39 | |
| 39 | 40 | def create_delete_task |
| 40 | | Task.create!(:target => self, :command => "delete_from_authorized_keys") |
| 41 | Task.create!(:target_class => self.class.name, |
| 42 | :command => "delete_from_authorized_keys", :arguments => self.to_key) |
| 41 | 43 | end |
| 42 | 44 | |
| 43 | 45 | protected |
| toggle raw diff |
--- a/app/models/ssh_key.rb
+++ b/app/models/ssh_key.rb
@@ -22,22 +22,24 @@ class SshKey < ActiveRecord::Base
%Q{\n### END KEY #{self.id || "nil"} ###}
end
- def add_to_authorized_keys(key_file_class=SshKeyFile)
+ def self.add_to_authorized_keys(keydata, key_file_class=SshKeyFile)
key_file = key_file_class.new
- key_file.add_key(self.to_key)
+ key_file.add_key(keydata)
end
- def delete_from_authorized_keys(key_file_class=SshKeyFile)
+ def self.delete_from_authorized_keys(keydata, key_file_class=SshKeyFile)
key_file = key_file_class.new
- key_file.delete_key(self.to_key)
+ key_file.delete_key(keydata)
end
def create_new_task
- Task.create!(:target => self, :command => "add_to_authorized_keys")
+ Task.create!(:target_class => self.class.name,
+ :command => "add_to_authorized_keys", :arguments => self.to_key)
end
def create_delete_task
- Task.create!(:target => self, :command => "delete_from_authorized_keys")
+ Task.create!(:target_class => self.class.name,
+ :command => "delete_from_authorized_keys", :arguments => self.to_key)
end
protected |
| |   |
| 5 | 5 | find(:all, :conditions => {:performed => false}) |
| 6 | 6 | end |
| 7 | 7 | |
| 8 | | def self.perform_all_pending! |
| 9 | | find_all_pending.each do |task| |
| 10 | | task.perform! |
| 8 | def self.perform_all_pending!(log=RAILS_DEFAULT_LOGGER) |
| 9 | tasks_to_perform = find_all_pending |
| 10 | log.info("Got #{tasks_to_perform.size.inspect} tasks to perform...") |
| 11 | tasks_to_perform.each do |task| |
| 12 | task.perform!(log) |
| 11 | 13 | end |
| 12 | 14 | end |
| 13 | 15 | |
| 14 | | def perform! |
| 16 | def perform!(log=RAILS_DEFAULT_LOGGER) |
| 15 | 17 | transaction do |
| 16 | | target.send(command) |
| 18 | log.info("Performing Task #{self.id.inspect}: #{target_class}::#{command}(#{arguments[0..64].inspect}..)") |
| 19 | target_class.constantize.send(command, arguments) |
| 17 | 20 | self.performed = true |
| 18 | 21 | self.performed_at = Time.now |
| 19 | 22 | save! |
| toggle raw diff |
--- a/app/models/task.rb
+++ b/app/models/task.rb
@@ -5,15 +5,18 @@ class Task < ActiveRecord::Base
find(:all, :conditions => {:performed => false})
end
- def self.perform_all_pending!
- find_all_pending.each do |task|
- task.perform!
+ def self.perform_all_pending!(log=RAILS_DEFAULT_LOGGER)
+ tasks_to_perform = find_all_pending
+ log.info("Got #{tasks_to_perform.size.inspect} tasks to perform...")
+ tasks_to_perform.each do |task|
+ task.perform!(log)
end
end
- def perform!
+ def perform!(log=RAILS_DEFAULT_LOGGER)
transaction do
- target.send(command)
+ log.info("Performing Task #{self.id.inspect}: #{target_class}::#{command}(#{arguments[0..64].inspect}..)")
+ target_class.constantize.send(command, arguments)
self.performed = true
self.performed_at = Time.now
save! |
| |   |
| 1 | 1 | class CreateTasks < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | 3 | create_table :tasks do |t| |
| 4 | | t.integer :target_id |
| 5 | | t.string :target_type |
| 4 | t.string :target_class |
| 6 | 5 | t.string :command |
| 6 | t.text :arguments |
| 7 | 7 | t.boolean :performed, :default => false |
| 8 | 8 | t.datetime :performed_at |
| 9 | 9 | t.timestamps |
| 10 | 10 | end |
| 11 | | add_index :tasks, :target_id |
| 12 | | add_index :tasks, :target_type |
| 13 | 11 | add_index :tasks, :performed |
| 14 | 12 | end |
| 15 | 13 | |
| toggle raw diff |
--- a/db/migrate/016_create_tasks.rb
+++ b/db/migrate/016_create_tasks.rb
@@ -1,15 +1,13 @@
class CreateTasks < ActiveRecord::Migration
def self.up
create_table :tasks do |t|
- t.integer :target_id
- t.string :target_type
+ t.string :target_class
t.string :command
+ t.text :arguments
t.boolean :performed, :default => false
t.datetime :performed_at
t.timestamps
end
- add_index :tasks, :target_id
- add_index :tasks, :target_type
add_index :tasks, :performed
end
|
| |   |
| 81 | 81 | end |
| 82 | 82 | |
| 83 | 83 | create_table "tasks", :force => true do |t| |
| 84 | | t.integer "target_id" |
| 85 | | t.string "target_type" |
| 84 | t.string "target_class" |
| 86 | 85 | t.string "command" |
| 86 | t.text "arguments" |
| 87 | 87 | t.boolean "performed", :default => false |
| 88 | 88 | t.datetime "performed_at" |
| 89 | 89 | t.datetime "created_at" |
| 90 | 90 | t.datetime "updated_at" |
| 91 | 91 | end |
| 92 | 92 | |
| 93 | | add_index "tasks", ["target_id"], :name => "index_tasks_on_target_id" |
| 94 | | add_index "tasks", ["target_type"], :name => "index_tasks_on_target_type" |
| 95 | 93 | add_index "tasks", ["performed"], :name => "index_tasks_on_performed" |
| 96 | 94 | |
| 97 | 95 | create_table "users", :force => true do |t| |
| toggle raw diff |
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -81,17 +81,15 @@ ActiveRecord::Schema.define(:version => 16) do
end
create_table "tasks", :force => true do |t|
- t.integer "target_id"
- t.string "target_type"
+ t.string "target_class"
t.string "command"
+ t.text "arguments"
t.boolean "performed", :default => false
t.datetime "performed_at"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "tasks", ["target_id"], :name => "index_tasks_on_target_id"
- add_index "tasks", ["target_type"], :name => "index_tasks_on_target_type"
add_index "tasks", ["performed"], :name => "index_tasks_on_performed"
create_table "users", :force => true do |t| |
| |   |
| 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | ENV["RAILS_ENV"] ||= "production" |
| 4 | require File.dirname(__FILE__) + "/../config/environment" |
| 5 | require "fileutils" |
| 6 | |
| 7 | LOCK_FILE_PATH = File.join(RAILS_ROOT, "tmp", "task_lockfile") |
| 8 | |
| 9 | class TaskLockError < StandardError; end |
| 10 | |
| 11 | def with_lock(&block) |
| 12 | begin |
| 13 | if File.exist?(LOCK_FILE_PATH) |
| 14 | raise TaskLockError |
| 15 | end |
| 16 | FileUtils.touch(LOCK_FILE_PATH) |
| 17 | yield |
| 18 | FileUtils.rm(LOCK_FILE_PATH) |
| 19 | rescue TaskLockError |
| 20 | $stderr.puts "Task lockfile exists" |
| 21 | exit(1) |
| 22 | end |
| 23 | end |
| 24 | |
| 25 | with_lock do |
| 26 | log = Logger.new(File.join(RAILS_ROOT, "log", "tasks.log")) |
| 27 | log.formatter = Logger::Formatter.new |
| 28 | log.formatter.datetime_format = "%Y-%m-%d %H:%M:%S" |
| 29 | Task.perform_all_pending!(log) |
| 30 | end |
| toggle raw diff |
--- /dev/null
+++ b/script/task_performer
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+ENV["RAILS_ENV"] ||= "production"
+require File.dirname(__FILE__) + "/../config/environment"
+require "fileutils"
+
+LOCK_FILE_PATH = File.join(RAILS_ROOT, "tmp", "task_lockfile")
+
+class TaskLockError < StandardError; end
+
+def with_lock(&block)
+ begin
+ if File.exist?(LOCK_FILE_PATH)
+ raise TaskLockError
+ end
+ FileUtils.touch(LOCK_FILE_PATH)
+ yield
+ FileUtils.rm(LOCK_FILE_PATH)
+ rescue TaskLockError
+ $stderr.puts "Task lockfile exists"
+ exit(1)
+ end
+end
+
+with_lock do
+ log = Logger.new(File.join(RAILS_ROOT, "log", "tasks.log"))
+ log.formatter = Logger::Formatter.new
+ log.formatter.datetime_format = "%Y-%m-%d %H:%M:%S"
+ Task.perform_all_pending!(log)
+end
\ No newline at end of file |
| |   |
| 1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
| 2 | 2 | create_repo: |
| 3 | 3 | id: 1 |
| 4 | | target_id: 1 |
| 5 | | target_type: Repository |
| 4 | target_class: Repository |
| 6 | 5 | command: create_git_repository |
| 6 | arguments: foo/bar.git |
| 7 | 7 | performed: 0 |
| 8 | 8 | |
| 9 | 9 | add_key: |
| 10 | 10 | id: 2 |
| 11 | | target_id: 1 |
| 12 | | target_type: SshKey |
| 11 | target_class: SshKey |
| 13 | 12 | command: add_to_authorized_keys |
| 13 | arguments: |- |
| 14 | ### START KEY 2 ### |
| 15 | command="gitorious johan",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa bXljYWtkZHlpemltd21vY2NqdGJnaHN2bXFjdG9zbXplaGlpZnZ0a3VyZWFc2dkanB4aXNxamxieGVib3l6Z3hmb2ZxZW15Y2FrZGR5aXppbXdtb2NjanRiZ2hzdm1xY3Rvc216ZWhpaWZ2dGt1cmVhc3NnZGpweGlzcWpsYnhlYm95emd4Zm9mcWU= foo@example.com |
| 16 | ### END KEY 2 ### |
| 14 | 17 | performed: 0 |
| toggle raw diff |
--- a/spec/fixtures/tasks.yml
+++ b/spec/fixtures/tasks.yml
@@ -1,14 +1,17 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
create_repo:
id: 1
- target_id: 1
- target_type: Repository
+ target_class: Repository
command: create_git_repository
+ arguments: foo/bar.git
performed: 0
add_key:
id: 2
- target_id: 1
- target_type: SshKey
+ target_class: SshKey
command: add_to_authorized_keys
+ arguments: |-
+ ### START KEY 2 ###
+ command="gitorious johan",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa bXljYWtkZHlpemltd21vY2NqdGJnaHN2bXFjdG9zbXplaGlpZnZ0a3VyZWFc2dkanB4aXNxamxieGVib3l6Z3hmb2ZxZW15Y2FrZGR5aXppbXdtb2NjanRiZ2hzdm1xY3Rvc216ZWhpaWZ2dGt1cmVhc3NnZGpweGlzcWpsYnhlYm95emd4Zm9mcWU= foo@example.com
+ ### END KEY 2 ###
performed: 0 |
| |   |
| 81 | 81 | end |
| 82 | 82 | |
| 83 | 83 | it "inits the git repository" do |
| 84 | | @repository.git_backend.should_receive(:create).with(@repository.full_repository_path).and_return(true) |
| 85 | | @repository.create_git_repository |
| 84 | Repository.git_backend.should_receive(:create).with(@repository.full_repository_path).and_return(true) |
| 85 | Repository.create_git_repository(@repository.gitdir) |
| 86 | 86 | end |
| 87 | 87 | |
| 88 | 88 | it "deletes a repository" do |
| 89 | | @repository.git_backend.should_receive(:delete!).with(@repository.full_repository_path).and_return(true) |
| 90 | | @repository.delete_git_repository |
| 89 | Repository.git_backend.should_receive(:delete!).with(@repository.full_repository_path).and_return(true) |
| 90 | Repository.delete_git_repository(@repository.gitdir) |
| 91 | 91 | end |
| 92 | 92 | |
| 93 | 93 | it "knows if has commits" do |
| … | … | |
| 130 | 130 | proc{ |
| 131 | 131 | @repository.save! |
| 132 | 132 | }.should change(Task, :count) |
| 133 | | task = Task.find(:first, :conditions => ["target_id = ?", @repository.id], :order => "id desc") |
| 133 | task = Task.find(:first, :conditions => ["target_class = 'Repository'"], :order => "id desc") |
| 134 | 134 | task.command.should == "create_git_repository" |
| 135 | task.arguments.should match(/#{@repository.gitdir}$/) |
| 135 | 136 | end |
| 136 | 137 | |
| 137 | 138 | it "creates a Task on destroy" do |
| … | … | |
| 140 | 140 | proc{ |
| 141 | 141 | @repository.destroy |
| 142 | 142 | }.should change(Task, :count) |
| 143 | | task = Task.find(:first, :conditions => ["target_id = ?", @repository.id], :order => "id desc") |
| 143 | task = Task.find(:first, :conditions => ["target_class = 'Repository'"], :order => "id desc") |
| 144 | 144 | task.command.should == "delete_git_repository" |
| 145 | task.arguments.should match(/#{@repository.gitdir}$/) |
| 145 | 146 | end |
| 146 | 147 | end |
| toggle raw diff |
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -81,13 +81,13 @@ describe Repository do
end
it "inits the git repository" do
- @repository.git_backend.should_receive(:create).with(@repository.full_repository_path).and_return(true)
- @repository.create_git_repository
+ Repository.git_backend.should_receive(:create).with(@repository.full_repository_path).and_return(true)
+ Repository.create_git_repository(@repository.gitdir)
end
it "deletes a repository" do
- @repository.git_backend.should_receive(:delete!).with(@repository.full_repository_path).and_return(true)
- @repository.delete_git_repository
+ Repository.git_backend.should_receive(:delete!).with(@repository.full_repository_path).and_return(true)
+ Repository.delete_git_repository(@repository.gitdir)
end
it "knows if has commits" do
@@ -130,8 +130,9 @@ describe Repository do
proc{
@repository.save!
}.should change(Task, :count)
- task = Task.find(:first, :conditions => ["target_id = ?", @repository.id], :order => "id desc")
+ task = Task.find(:first, :conditions => ["target_class = 'Repository'"], :order => "id desc")
task.command.should == "create_git_repository"
+ task.arguments.should match(/#{@repository.gitdir}$/)
end
it "creates a Task on destroy" do
@@ -139,7 +140,8 @@ describe Repository do
proc{
@repository.destroy
}.should change(Task, :count)
- task = Task.find(:first, :conditions => ["target_id = ?", @repository.id], :order => "id desc")
+ task = Task.find(:first, :conditions => ["target_class = 'Repository'"], :order => "id desc")
task.command.should == "delete_git_repository"
+ task.arguments.should match(/#{@repository.gitdir}$/)
end
end |
| |   |
| 63 | 63 | ssh_key = new_key |
| 64 | 64 | ssh_key_file_mock.should_receive(:new).and_return(ssh_key_file_mock) |
| 65 | 65 | ssh_key_file_mock.should_receive(:add_key).with(ssh_key.to_key).and_return(true) |
| 66 | | ssh_key.add_to_authorized_keys(ssh_key_file_mock) |
| 66 | SshKey.add_to_authorized_keys(ssh_key.to_key, ssh_key_file_mock) |
| 67 | 67 | end |
| 68 | 68 | |
| 69 | 69 | it "removes itself to the authorized keys file" do |
| … | … | |
| 71 | 71 | ssh_key = new_key |
| 72 | 72 | ssh_key_file_mock.should_receive(:new).and_return(ssh_key_file_mock) |
| 73 | 73 | ssh_key_file_mock.should_receive(:delete_key).with(ssh_key.to_key).and_return(true) |
| 74 | | ssh_key.delete_from_authorized_keys(ssh_key_file_mock) |
| 74 | SshKey.delete_from_authorized_keys(ssh_key.to_key, ssh_key_file_mock) |
| 75 | 75 | end |
| 76 | 76 | |
| 77 | 77 | it "creates a Task on create and update" do |
| … | … | |
| 79 | 79 | proc{ |
| 80 | 80 | ssh_key.save! |
| 81 | 81 | }.should change(Task, :count) |
| 82 | | task = Task.find(:first, :conditions => ["target_id = ?", ssh_key.id], :order => "id desc") |
| 82 | task = Task.find(:first, :conditions => ["target_class = 'SshKey'"], :order => "id desc") |
| 83 | 83 | task.command.should == "add_to_authorized_keys" |
| 84 | task.arguments.should == ssh_key.to_key |
| 84 | 85 | end |
| 85 | 86 | |
| 86 | 87 | it "creates a Task on destroy" do |
| 87 | 88 | ssh_key = new_key |
| 88 | 89 | ssh_key.save! |
| 90 | keydata = ssh_key.to_key.dup |
| 89 | 91 | proc{ |
| 90 | 92 | ssh_key.destroy |
| 91 | 93 | }.should change(Task, :count) |
| 92 | | task = Task.find(:first, :conditions => ["target_id = ?", ssh_key.id], :order => "id desc") |
| 94 | task = Task.find(:first, :conditions => ["target_class = 'SshKey'"], :order => "id desc") |
| 93 | 95 | task.command.should == "delete_from_authorized_keys" |
| 96 | task.arguments.should == keydata |
| 94 | 97 | end |
| 95 | 98 | end |
| toggle raw diff |
--- a/spec/models/ssh_key_spec.rb
+++ b/spec/models/ssh_key_spec.rb
@@ -63,7 +63,7 @@ describe SshKey do
ssh_key = new_key
ssh_key_file_mock.should_receive(:new).and_return(ssh_key_file_mock)
ssh_key_file_mock.should_receive(:add_key).with(ssh_key.to_key).and_return(true)
- ssh_key.add_to_authorized_keys(ssh_key_file_mock)
+ SshKey.add_to_authorized_keys(ssh_key.to_key, ssh_key_file_mock)
end
it "removes itself to the authorized keys file" do
@@ -71,7 +71,7 @@ describe SshKey do
ssh_key = new_key
ssh_key_file_mock.should_receive(:new).and_return(ssh_key_file_mock)
ssh_key_file_mock.should_receive(:delete_key).with(ssh_key.to_key).and_return(true)
- ssh_key.delete_from_authorized_keys(ssh_key_file_mock)
+ SshKey.delete_from_authorized_keys(ssh_key.to_key, ssh_key_file_mock)
end
it "creates a Task on create and update" do
@@ -79,17 +79,20 @@ describe SshKey do
proc{
ssh_key.save!
}.should change(Task, :count)
- task = Task.find(:first, :conditions => ["target_id = ?", ssh_key.id], :order => "id desc")
+ task = Task.find(:first, :conditions => ["target_class = 'SshKey'"], :order => "id desc")
task.command.should == "add_to_authorized_keys"
+ task.arguments.should == ssh_key.to_key
end
it "creates a Task on destroy" do
ssh_key = new_key
ssh_key.save!
+ keydata = ssh_key.to_key.dup
proc{
ssh_key.destroy
}.should change(Task, :count)
- task = Task.find(:first, :conditions => ["target_id = ?", ssh_key.id], :order => "id desc")
+ task = Task.find(:first, :conditions => ["target_class = 'SshKey'"], :order => "id desc")
task.command.should == "delete_from_authorized_keys"
+ task.arguments.should == keydata
end
end |