shortener 0.0.2 → 0.1.0

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.
Files changed (59) hide show
  1. data/.gitignore +3 -24
  2. data/README.rdoc +40 -11
  3. data/Rakefile +7 -21
  4. data/app/controllers/shortener/shortened_urls_controller.rb +22 -23
  5. data/app/helpers/shortener/shortener_helper.rb +6 -21
  6. data/app/models/shortener/shortened_url.rb +66 -74
  7. data/lib/generators/shortener/templates/migration.rb +17 -14
  8. data/lib/shortener.rb +22 -11
  9. data/lib/shortener/active_record_extension.rb +5 -0
  10. data/lib/shortener/engine.rb +3 -7
  11. data/lib/shortener/railtie.rb +10 -0
  12. data/lib/shortener/version.rb +2 -2
  13. data/shortener.gemspec +7 -5
  14. data/spec/controllers/shortened_urls_controller_spec.rb +19 -0
  15. data/spec/dummy/.gitignore +1 -0
  16. data/{test → spec}/dummy/Rakefile +0 -0
  17. data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
  18. data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  19. data/spec/dummy/app/models/user.rb +3 -0
  20. data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  21. data/{test → spec}/dummy/config.ru +0 -0
  22. data/{test → spec}/dummy/config/application.rb +0 -1
  23. data/{test → spec}/dummy/config/boot.rb +0 -0
  24. data/{test → spec}/dummy/config/database.yml +0 -0
  25. data/{test → spec}/dummy/config/environment.rb +0 -0
  26. data/{test → spec}/dummy/config/environments/development.rb +0 -3
  27. data/{test → spec}/dummy/config/environments/test.rb +0 -5
  28. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  29. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  30. data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  31. data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  32. data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  33. data/{test → spec}/dummy/config/locales/en.yml +0 -0
  34. data/spec/dummy/config/routes.rb +4 -0
  35. data/{test/dummy/public/stylesheets → spec/dummy/db}/.gitkeep +0 -0
  36. data/spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb +25 -0
  37. data/spec/dummy/db/migrate/20120214023758_create_users.rb +8 -0
  38. data/spec/dummy/db/schema.rb +34 -0
  39. data/{test → spec}/dummy/public/favicon.ico +0 -0
  40. data/{test → spec}/dummy/script/rails +0 -0
  41. data/spec/helpers/shortener_helper_spec.rb +12 -0
  42. data/spec/models/shortened_url_spec.rb +68 -0
  43. data/spec/spec_helper.rb +12 -0
  44. metadata +71 -49
  45. data/test/dummy/config/environments/production.rb +0 -49
  46. data/test/dummy/config/routes.rb +0 -58
  47. data/test/dummy/public/404.html +0 -26
  48. data/test/dummy/public/422.html +0 -26
  49. data/test/dummy/public/500.html +0 -26
  50. data/test/dummy/public/javascripts/application.js +0 -2
  51. data/test/dummy/public/javascripts/controls.js +0 -965
  52. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  53. data/test/dummy/public/javascripts/effects.js +0 -1123
  54. data/test/dummy/public/javascripts/prototype.js +0 -6001
  55. data/test/dummy/public/javascripts/rails.js +0 -191
  56. data/test/integration/navigation_test.rb +0 -7
  57. data/test/shortener_test.rb +0 -7
  58. data/test/support/integration_case.rb +0 -5
  59. data/test/test_helper.rb +0 -22
@@ -0,0 +1,5 @@
1
+ module Shortener::ActiveRecordExtension
2
+ def has_shortened_urls
3
+ has_many :shortened_urls, :class_name => ::Shortener::ShortenedUrl, :as => :owner
4
+ end
5
+ end
@@ -1,10 +1,6 @@
1
1
  require "rails/engine"
2
2
  require "shortener"
3
3
 
4
- module Shortener
5
-
6
- class ShortenerEngine < Rails::Engine
7
-
8
- end
9
-
10
- end
4
+ class Shortener::Engine < ::Rails::Engine #:nodoc:
5
+ config.shortener = Shortener
6
+ end
@@ -0,0 +1,10 @@
1
+ require "rails/railtie"
2
+ require "shortener"
3
+
4
+ class Shortener::Railtie < ::Rails::Railtie #:nodoc:
5
+ initializer "shortener.register.active.record.extension" do
6
+ ActiveSupport.on_load :active_record do
7
+ extend Shortener::ActiveRecordExtension
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Shortener
2
- VERSION = "0.0.2"
3
- end
2
+ VERSION = "0.1.0"
3
+ end
data/shortener.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path("../lib/shortener/version", __FILE__)
4
4
  # project in your rails apps through git.
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "shortener"
7
- s.summary = "Shortener makes it easy to create shortened URLs for your rails application."
8
- s.description = "Shortener is a Rails Engine that allows you to generate and store shortened URLs and serve them up for your own application."
7
+ s.summary = "Shortener is a Rails Engine that makes it easy to create shortened URLs for your rails application."
8
+ s.description = "Shortener is a Rails Engine Gem that makes it easy to create and interpret shortened URLs on your own domain from within your Rails application. Once installed Shortener will generate, store URLS and \"unshorten\" shortened URLs for your applications visitors, all whilst collecting basic usage metrics."
9
9
  s.files = `git ls-files`.split("\n")
10
10
  s.version = Shortener::VERSION
11
11
  s.platform = Gem::Platform::RUBY
@@ -14,8 +14,10 @@ Gem::Specification.new do |s|
14
14
  s.homepage = "http://jamespmcgrath.com/projects/shortener"
15
15
  s.rubyforge_project = "shortener"
16
16
  s.required_rubygems_version = "> 1.3.6"
17
- s.add_dependency "activesupport" , ">= 3.0.7"
18
- s.add_dependency "rails" , ">= 3.0.7"
17
+ s.add_dependency "rails", ">= 3.0.7"
18
+ s.add_development_dependency "sqlite3"
19
+ s.add_development_dependency "rspec-rails"
20
+ s.add_development_dependency "shoulda-matchers"
19
21
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
20
22
  s.require_path = 'lib'
21
- end
23
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Shortener::ShortenedUrlsController do
5
+ let(:short_url) { Shortener::ShortenedUrl.generate("www.doorkeeperhq.com") }
6
+
7
+ describe "GET show with good code" do
8
+ it "redirects to actual url" do
9
+ get :show, :id => short_url.unique_key
10
+ response.should redirect_to("http://www.doorkeeperhq.com/")
11
+ end
12
+ end
13
+ describe "GET show with wrong code" do
14
+ it "redirects to actual url" do
15
+ get :show, :id => "testing"
16
+ response.should redirect_to("/")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ db/*.sqlite3
File without changes
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ has_shortened_urls
3
+ end
File without changes
@@ -4,7 +4,6 @@ require "active_model/railtie"
4
4
  require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_view/railtie"
7
- require "action_mailer/railtie"
8
7
 
9
8
  Bundler.require
10
9
  require "shortener"
File without changes
File without changes
File without changes
@@ -14,9 +14,6 @@ Dummy::Application.configure do
14
14
  config.action_view.debug_rjs = true
15
15
  config.action_controller.perform_caching = false
16
16
 
17
- # Don't care if the mailer can't send
18
- config.action_mailer.raise_delivery_errors = false
19
-
20
17
  # Print deprecation notices to the Rails logger
21
18
  config.active_support.deprecation = :log
22
19
 
@@ -20,11 +20,6 @@ Dummy::Application.configure do
20
20
  # Disable request forgery protection in test environment
21
21
  config.action_controller.allow_forgery_protection = false
22
22
 
23
- # Tell Action Mailer not to deliver emails to the real world.
24
- # The :test delivery method accumulates sent emails in the
25
- # ActionMailer::Base.deliveries array.
26
- config.action_mailer.delivery_method = :test
27
-
28
23
  # Use SQL instead of Active Record's schema dumper when creating the test database.
29
24
  # This is necessary if your schema can't be completely dumped by the schema dumper,
30
25
  # like if you have constraints or database-specific column types
File without changes
@@ -0,0 +1,4 @@
1
+ Dummy::Application.routes.draw do
2
+ match '/:id' => "shortener/shortened_urls#show"
3
+ root :to => "application_controller#show"
4
+ end
@@ -0,0 +1,25 @@
1
+ class CreateShortenedUrlsTable < ActiveRecord::Migration
2
+ def change
3
+ create_table :shortened_urls do |t|
4
+ # we can link this to a user for interesting things
5
+ t.integer :owner_id
6
+ t.string :owner_type, :limit => 20
7
+
8
+ # the real url that we will redirect to
9
+ t.string :url, :null => false
10
+
11
+ # the unique key
12
+ t.string :unique_key, :limit => 10, :null => false
13
+
14
+ # how many times the link has been clicked
15
+ t.integer :use_count, :null => false, :default => 0
16
+
17
+ t.timestamps
18
+ end
19
+
20
+ # we will lookup the links in the db by key and owners.
21
+ # also make sure the unique keys are actually unique
22
+ add_index :shortened_urls, :unique_key, :unique => true
23
+ add_index :shortened_urls, [:owner_id, :owner_type]
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120214023758) do
15
+
16
+ create_table "shortened_urls", :force => true do |t|
17
+ t.integer "owner_id"
18
+ t.string "owner_type", :limit => 20
19
+ t.string "url", :null => false
20
+ t.string "unique_key", :limit => 10, :null => false
21
+ t.integer "use_count", :default => 0, :null => false
22
+ t.datetime "created_at", :null => false
23
+ t.datetime "updated_at", :null => false
24
+ end
25
+
26
+ add_index "shortened_urls", ["owner_id", "owner_type"], :name => "index_shortened_urls_on_owner_id_and_owner_type"
27
+ add_index "shortened_urls", ["unique_key"], :name => "index_shortened_urls_on_unique_key", :unique => true
28
+
29
+ create_table "users", :force => true do |t|
30
+ t.datetime "created_at", :null => false
31
+ t.datetime "updated_at", :null => false
32
+ end
33
+
34
+ end
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Shortener::ShortenerHelper do
5
+ before { @short_url = Shortener::ShortenedUrl.generate("www.doorkeeperhq.com") }
6
+
7
+ describe "short_url" do
8
+ it "should shorten the url" do
9
+ helper.short_url("www.doorkeeperhq.com").should == "http://test.host/#{@short_url.unique_key}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Shortener::ShortenedUrl do
5
+ it { should belong_to :owner }
6
+ it { should validate_presence_of :url }
7
+
8
+ shared_examples_for "shortened url" do
9
+ let(:short_url) { Shortener::ShortenedUrl.generate!(long_url, owner) }
10
+ it "should be shortened" do
11
+ short_url.should_not be_nil
12
+ short_url.url.should == expected_long_url
13
+ short_url.unique_key.length.should == 5
14
+ short_url.owner.should == owner
15
+ end
16
+ end
17
+
18
+ context "shortened url" do
19
+ let(:long_url) { "http://www.doorkeeperhq.com/" }
20
+ let(:expected_long_url) { long_url }
21
+ let(:owner) { nil }
22
+ it_should_behave_like "shortened url"
23
+ end
24
+
25
+ context "shortened url with partial URL" do
26
+ let(:long_url) { "www.doorkeeperhq.com" }
27
+ let(:expected_long_url) { "http://www.doorkeeperhq.com/" }
28
+ let(:owner) { nil }
29
+ it_should_behave_like "shortened url"
30
+ end
31
+
32
+ context "shortened url with i18n path" do
33
+ let(:long_url) { "http://www.doorkeeper.jp/%E6%97%A5%E6%9C%AC%E8%AA%9E" }
34
+ let(:expected_long_url) { long_url }
35
+ let(:owner) { nil }
36
+ it_should_behave_like "shortened url"
37
+ end
38
+
39
+ context "shortened url with user" do
40
+ let(:long_url) { "http://www.doorkeeperhq.com/" }
41
+ let(:expected_long_url) { long_url }
42
+ let(:owner) { User.create }
43
+ it_should_behave_like "shortened url"
44
+ end
45
+
46
+ context "existing shortened URL" do
47
+ before { @existing = Shortener::ShortenedUrl.generate!("http://www.doorkeeperhq.com/") }
48
+ it "should look up exsiting URL" do
49
+ Shortener::ShortenedUrl.generate!("http://www.doorkeeperhq.com/").should == @existing
50
+ Shortener::ShortenedUrl.generate!("www.doorkeeperhq.com").should == @existing
51
+ end
52
+ it "should generate different one for different" do
53
+ Shortener::ShortenedUrl.generate!("www.doorkeeper.jp").should_not == @existing
54
+ end
55
+
56
+ context "duplicate unique key" do
57
+ before do
58
+ Shortener::ShortenedUrl.any_instance.stub(:generate_unique_key).
59
+ and_return(@existing.unique_key, "ABCDEF")
60
+ end
61
+ it "should try until it finds a non-dup key" do
62
+ short_url = Shortener::ShortenedUrl.generate!("client.doorkeeper.jp")
63
+ short_url.should_not be_nil
64
+ short_url.unique_key.should == "ABCDEF"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,12 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'shortener'
5
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
+ require 'rspec/rails'
7
+ require 'shoulda/matchers/integrations/rspec'
8
+
9
+ Rails.backtrace_cleaner.remove_silencers!
10
+
11
+ # Run any available migration
12
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-01 00:00:00.000000000Z
12
+ date: 2012-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: &10296620 !ruby/object:Gem::Requirement
15
+ name: rails
16
+ requirement: &18262700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,20 +21,44 @@ dependencies:
21
21
  version: 3.0.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10296620
24
+ version_requirements: *18262700
25
25
  - !ruby/object:Gem::Dependency
26
- name: rails
27
- requirement: &10296020 !ruby/object:Gem::Requirement
26
+ name: sqlite3
27
+ requirement: &18262320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 3.0.7
33
- type: :runtime
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *18262320
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &18261860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *18261860
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda-matchers
49
+ requirement: &18261440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
34
56
  prerelease: false
35
- version_requirements: *10296020
36
- description: Shortener is a Rails Engine that allows you to generate and store shortened
37
- URLs and serve them up for your own application.
57
+ version_requirements: *18261440
58
+ description: Shortener is a Rails Engine Gem that makes it easy to create and interpret
59
+ shortened URLs on your own domain from within your Rails application. Once installed
60
+ Shortener will generate, store URLS and "unshorten" shortened URLs for your applications
61
+ visitors, all whilst collecting basic usage metrics.
38
62
  email:
39
63
  - gems@jamespmcgrath.com
40
64
  executables: []
@@ -53,44 +77,41 @@ files:
53
77
  - lib/generators/shortener/shortener_generator.rb
54
78
  - lib/generators/shortener/templates/migration.rb
55
79
  - lib/shortener.rb
80
+ - lib/shortener/active_record_extension.rb
56
81
  - lib/shortener/engine.rb
82
+ - lib/shortener/railtie.rb
57
83
  - lib/shortener/version.rb
58
84
  - shortener.gemspec
59
- - test/dummy/Rakefile
60
- - test/dummy/app/controllers/application_controller.rb
61
- - test/dummy/app/helpers/application_helper.rb
62
- - test/dummy/app/views/layouts/application.html.erb
63
- - test/dummy/config.ru
64
- - test/dummy/config/application.rb
65
- - test/dummy/config/boot.rb
66
- - test/dummy/config/database.yml
67
- - test/dummy/config/environment.rb
68
- - test/dummy/config/environments/development.rb
69
- - test/dummy/config/environments/production.rb
70
- - test/dummy/config/environments/test.rb
71
- - test/dummy/config/initializers/backtrace_silencers.rb
72
- - test/dummy/config/initializers/inflections.rb
73
- - test/dummy/config/initializers/mime_types.rb
74
- - test/dummy/config/initializers/secret_token.rb
75
- - test/dummy/config/initializers/session_store.rb
76
- - test/dummy/config/locales/en.yml
77
- - test/dummy/config/routes.rb
78
- - test/dummy/public/404.html
79
- - test/dummy/public/422.html
80
- - test/dummy/public/500.html
81
- - test/dummy/public/favicon.ico
82
- - test/dummy/public/javascripts/application.js
83
- - test/dummy/public/javascripts/controls.js
84
- - test/dummy/public/javascripts/dragdrop.js
85
- - test/dummy/public/javascripts/effects.js
86
- - test/dummy/public/javascripts/prototype.js
87
- - test/dummy/public/javascripts/rails.js
88
- - test/dummy/public/stylesheets/.gitkeep
89
- - test/dummy/script/rails
90
- - test/integration/navigation_test.rb
91
- - test/shortener_test.rb
92
- - test/support/integration_case.rb
93
- - test/test_helper.rb
85
+ - spec/controllers/shortened_urls_controller_spec.rb
86
+ - spec/dummy/.gitignore
87
+ - spec/dummy/Rakefile
88
+ - spec/dummy/app/controllers/application_controller.rb
89
+ - spec/dummy/app/helpers/application_helper.rb
90
+ - spec/dummy/app/models/user.rb
91
+ - spec/dummy/app/views/layouts/application.html.erb
92
+ - spec/dummy/config.ru
93
+ - spec/dummy/config/application.rb
94
+ - spec/dummy/config/boot.rb
95
+ - spec/dummy/config/database.yml
96
+ - spec/dummy/config/environment.rb
97
+ - spec/dummy/config/environments/development.rb
98
+ - spec/dummy/config/environments/test.rb
99
+ - spec/dummy/config/initializers/backtrace_silencers.rb
100
+ - spec/dummy/config/initializers/inflections.rb
101
+ - spec/dummy/config/initializers/mime_types.rb
102
+ - spec/dummy/config/initializers/secret_token.rb
103
+ - spec/dummy/config/initializers/session_store.rb
104
+ - spec/dummy/config/locales/en.yml
105
+ - spec/dummy/config/routes.rb
106
+ - spec/dummy/db/.gitkeep
107
+ - spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb
108
+ - spec/dummy/db/migrate/20120214023758_create_users.rb
109
+ - spec/dummy/db/schema.rb
110
+ - spec/dummy/public/favicon.ico
111
+ - spec/dummy/script/rails
112
+ - spec/helpers/shortener_helper_spec.rb
113
+ - spec/models/shortened_url_spec.rb
114
+ - spec/spec_helper.rb
94
115
  homepage: http://jamespmcgrath.com/projects/shortener
95
116
  licenses: []
96
117
  post_install_message:
@@ -111,8 +132,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
132
  version: 1.3.6
112
133
  requirements: []
113
134
  rubyforge_project: shortener
114
- rubygems_version: 1.8.6
135
+ rubygems_version: 1.8.10
115
136
  signing_key:
116
137
  specification_version: 3
117
- summary: Shortener makes it easy to create shortened URLs for your rails application.
138
+ summary: Shortener is a Rails Engine that makes it easy to create shortened URLs for
139
+ your rails application.
118
140
  test_files: []