objectreload-permalinks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gemspec
2
+ pkg/
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "objectreload-permalinks"
8
+ gem.summary = "Simple way to create permalinks."
9
+ gem.email = "gems@objectreload.com"
10
+ gem.homepage = "http://github.com/objectreload/permalinks"
11
+ gem.authors = ["Mateusz Drozdzynski", "Ewa Limanowka"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION')
46
+ version = File.read('VERSION')
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "permalinks_gem #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require File.dirname(__FILE__) + '/lib/permalinks'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/permalinks.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Permalinks
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def has_permalink(field = :name)
8
+ define_method(:to_param) do
9
+ "#{id}-#{send(field).to_s.downcase.gsub(/[^[:alnum:]]/,'-')}".gsub(/-{2,}/, '-').gsub(/(^-)|(-$)/ ,'')
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveRecord::Base.send(:include, Permalinks)
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{objectreload-permalinks}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mateusz Drozdzynski", "Ewa Limanowka"]
12
+ s.date = %q{2009-10-20}
13
+ s.email = %q{gems@objectreload.com}
14
+ s.extra_rdoc_files = [
15
+ "README"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "init.rb",
23
+ "install.rb",
24
+ "lib/permalinks.rb",
25
+ "objectreload-permalinks.gemspec",
26
+ "test/permalinks_test.rb",
27
+ "test/test_helper.rb",
28
+ "uninstall.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/objectreload/permalinks}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{Simple way to create permalinks.}
35
+ s.test_files = [
36
+ "test/permalinks_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ else
46
+ end
47
+ else
48
+ end
49
+ end
50
+
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class CountryTest < Test::Unit::TestCase
4
+ context "Country model" do
5
+ setup do
6
+ @country = Country.new :name => "United Kingdom"
7
+ @country.save!
8
+ end
9
+ subject { @country }
10
+
11
+ context "regular country name" do
12
+ should "return permalink" do
13
+ assert_equal "#{@country.id}-united-kingdom", @country.to_param
14
+ end
15
+ end
16
+
17
+ context "country name with a lot of spaces" do
18
+ should "return permalink" do
19
+ @country.name = "United Kingdom "
20
+ @country.save
21
+ assert_equal "#{@country.id}-united-kingdom", @country.to_param
22
+ end
23
+ end
24
+
25
+ context "country name with capital letters" do
26
+ should "return permalink" do
27
+ @country.name = " USA "
28
+ @country.save
29
+ assert_equal "#{@country.id}-usa", @country.to_param
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ class PostTest < Test::Unit::TestCase
36
+ context "Post model" do
37
+ setup do
38
+ @post = Post.new :title => "Something cool"
39
+ @post.save!
40
+ end
41
+ subject { @post }
42
+
43
+ context "regular post title" do
44
+ should "return permalink" do
45
+ assert_equal "#{@post.id}-something-cool", @post.to_param
46
+ end
47
+ end
48
+
49
+ context "post title with a lot of white spaces" do
50
+ should "return permalink" do
51
+ @post.title = " Snow is cold "
52
+ @post.save!
53
+ assert_equal "#{@post.id}-snow-is-cold", @post.to_param
54
+ end
55
+ end
56
+
57
+ context "post title with capital letters" do
58
+ should "return permalink" do
59
+ @post.title = " SOMETHING i really like to DO is sleeping "
60
+ @post.save!
61
+ assert_equal "#{@post.id}-something-i-really-like-to-do-is-sleeping", @post.to_param
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'activerecord'
3
+ require File.dirname(__FILE__)+'/../lib/permalinks'
4
+ require 'shoulda'
5
+ require 'logger'
6
+
7
+ ActiveRecord::Base.configurations = {'sqlite3' => {:adapter => 'sqlite3', :database => ':memory:'}}
8
+ ActiveRecord::Base.establish_connection('sqlite3')
9
+
10
+ ActiveRecord::Base.logger = Logger.new(STDERR)
11
+ ActiveRecord::Base.logger.level = Logger::WARN
12
+
13
+ ActiveRecord::Schema.define(:version => 0) do
14
+ create_table :countries do |t|
15
+ t.string :name, :default => ''
16
+ end
17
+
18
+ create_table :posts do |t|
19
+ t.string :title, :default => ''
20
+ end
21
+ end
22
+
23
+ class Country < ActiveRecord::Base
24
+ has_permalink
25
+ end
26
+
27
+ class Post < ActiveRecord::Base
28
+ has_permalink :title
29
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: objectreload-permalinks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Drozdzynski
8
+ - Ewa Limanowka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-20 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: gems@objectreload.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README
25
+ files:
26
+ - .gitignore
27
+ - README
28
+ - Rakefile
29
+ - VERSION
30
+ - init.rb
31
+ - install.rb
32
+ - lib/permalinks.rb
33
+ - objectreload-permalinks.gemspec
34
+ - test/permalinks_test.rb
35
+ - test/test_helper.rb
36
+ - uninstall.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/objectreload/permalinks
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Simple way to create permalinks.
65
+ test_files:
66
+ - test/permalinks_test.rb
67
+ - test/test_helper.rb