acts_as_aliased 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -27,9 +27,9 @@ aliasing in your model by using `acts_as_aliased`:
27
27
 
28
28
  This assumes a column called `name` on your company model. You can specify a different column by passing a `column` argument:
29
29
 
30
- model Company < ActiveRecord::Base
31
- acts_as_aliased :column => 'title'
32
- end
30
+ model Company < ActiveRecord::Base
31
+ acts_as_aliased :column => 'title'
32
+ end
33
33
 
34
34
  An alias can be created manually like this:
35
35
 
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
-
3
2
  require 'rubygems'
4
3
  require 'bundler'
5
4
  begin
@@ -10,18 +9,18 @@ rescue Bundler::BundlerError => e
10
9
  exit e.status_code
11
10
  end
12
11
  require 'rake'
13
-
14
12
  require 'jeweler'
13
+
15
14
  Jeweler::Tasks.new do |gem|
16
15
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "acts_as_aliased"
18
- gem.homepage = "http://github.com/trusche/acts_as_aliased"
16
+ gem.name = "acts_as_aliased"
17
+ gem.homepage = "http://github.com/legitscript/acts_as_aliased"
19
18
  gem.license = "MIT"
20
19
  gem.summary = %Q{Alias names for your models}
21
20
  gem.description = %Q{Provides aliases and lookup methods for ActiveRecord models.}
22
21
  gem.email = "thilo.rusche@legitscript.com"
23
22
  gem.authors = ["Thilo Rusche"]
24
- gem.version = "0.0.4"
23
+ gem.version = "0.0.5"
25
24
  gem.files = FileList["[A-Z]*", "{lib,spec}/**/*"]
26
25
  gem.require_paths = ['lib']
27
26
  end
@@ -35,14 +35,22 @@ module ActsAsAliased
35
35
  def to_alias! aliased
36
36
  raise "Cannot create alias for myself" if aliased == self
37
37
  self.class.transaction do
38
+
39
+ # Move references to this instance from the provided associations to the
40
+ # newly aliased one
38
41
  a = ::ActsAsAliased::Alias.create(aliased: aliased, name: self[column])
39
42
  associations.each do |association|
40
43
  klass = association.to_s.classify.constantize
41
44
  key = self.class.to_s.foreign_key
42
45
  klass.where(key => id).update_all(key => aliased.id)
43
46
  end
47
+
48
+ # Move references to this instance to the newly aliased one
49
+ Alias.where("aliased_type = ? AND aliased_id = ?", self.class.to_s, self.id).update_all(aliased_id: aliased.id)
50
+
51
+ # Poof!
44
52
  self.destroy
45
- a
53
+ return a
46
54
  end
47
55
  end
48
56
  end
@@ -4,6 +4,7 @@ describe "ActsAsAliased" do
4
4
 
5
5
  let(:company1) { Company.create(name: "Foo LLC") }
6
6
  let(:company2) { Company.create(name: "Foo") }
7
+ let(:company3) { Company.create(name: "Company Foo") }
7
8
  let(:department1) { Department.create(title: "Technical Staff") }
8
9
  let(:department2) { Department.create(title: "Techies") }
9
10
  let(:project1) { Project.create(name: "Project 1", company: company1, department: department1) }
@@ -72,6 +73,19 @@ describe "ActsAsAliased" do
72
73
  Department.lookup("Techies").should == department1
73
74
  end
74
75
  end
76
+
77
+ context "recursively" do
78
+ before(:each) do
79
+ clean_database
80
+ company3.to_alias!(company2)
81
+ company2.to_alias!(company1)
82
+ end
83
+
84
+ it "should reassign previsou alias" do
85
+ Company.lookup("Company Foo").should == company1
86
+ Company.lookup("Foo LLC").should == company1
87
+ end
88
+ end
75
89
  end
76
90
 
77
91
  context "lookup" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_aliased
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-23 00:00:00.000000000 Z
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -125,7 +125,7 @@ files:
125
125
  - lib/generators/acts_as_aliased/templates/migration.rb
126
126
  - spec/acts_as_aliased_spec.rb
127
127
  - spec/spec_helper.rb
128
- homepage: http://github.com/trusche/acts_as_aliased
128
+ homepage: http://github.com/legitscript/acts_as_aliased
129
129
  licenses:
130
130
  - MIT
131
131
  post_install_message:
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  segments:
142
142
  - 0
143
- hash: -3303482588023467799
143
+ hash: 1765874677565596583
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 1.8.21
152
+ rubygems_version: 1.8.24
153
153
  signing_key:
154
154
  specification_version: 3
155
155
  summary: Alias names for your models