firefly 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ describe "Base62 encoding/decoding" do
13
13
  it "should encode #{input} correctly to #{output}" do
14
14
  Firefly::Base62.encode(input).should eql(output)
15
15
  end
16
-
16
+
17
17
  it "should decode correctly" do
18
18
  Firefly::Base62.decode(output).should eql(input)
19
19
  end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "CodeFactory" do
4
+
5
+ describe "next!" do
6
+ it "should return the next code_count" do
7
+ current_count = Firefly::CodeFactory.first.count
8
+ expected_code = Firefly::Base62.encode(current_count + 1)
9
+ Firefly::CodeFactory.next_code!.should eql(expected_code)
10
+ end
11
+ end
12
+ end
@@ -6,13 +6,13 @@ describe "Firefly" do
6
6
  def app
7
7
  @@app
8
8
  end
9
-
9
+
10
10
  describe "/" do
11
11
  it "should respond ok" do
12
12
  get '/'
13
13
  last_response.should be_ok
14
14
  end
15
- end
15
+ end
16
16
 
17
17
 
18
18
  if defined? Barby
@@ -41,33 +41,33 @@ describe "Firefly" do
41
41
  describe "redirecting" do
42
42
  it "should redirect to the original URL" do
43
43
  fake = Firefly::Url.create(:url => 'http://example.com/123', :code => 'alpha')
44
-
44
+
45
45
  get '/alpha'
46
46
  follow_redirect!
47
-
47
+
48
48
  last_request.url.should eql('http://example.com/123')
49
49
  end
50
-
50
+
51
51
  it "should increase the visits counter" do
52
52
  fake = Firefly::Url.create(:url => 'http://example.com/123', :code => 'alpha')
53
53
  Firefly::Url.should_receive(:first).and_return(fake)
54
-
54
+
55
55
  lambda {
56
56
  get '/alpha'
57
57
  }.should change(fake, :clicks).by(1)
58
58
  end
59
-
59
+
60
60
  it "should redirect with a 301 Permanent redirect" do
61
61
  fake = Firefly::Url.create(:url => 'http://example.com/123', :code => 'alpha')
62
-
62
+
63
63
  get '/alpha'
64
-
64
+
65
65
  last_response.status.should eql(301)
66
66
  end
67
-
67
+
68
68
  it "should throw a 404 when the code is unknown" do
69
69
  get '/some_random_code_that_does_not_exist'
70
-
70
+
71
71
  last_response.status.should eql(404)
72
72
  end
73
73
  end
@@ -1,37 +1,37 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Url" do
4
-
4
+
5
5
  describe "shortening" do
6
6
  it "should generate a code after create" do
7
7
  url = Firefly::Url.shorten("http://example.com/")
8
8
  Firefly::Url.first(:url => "http://example.com/").code.should_not be_nil
9
9
  end
10
-
10
+
11
11
  it "should set a clicks count of 0 for newly shortened urls" do
12
12
  url = Firefly::Url.shorten("http://example.com/")
13
13
  Firefly::Url.first(:url => "http://example.com/").clicks.should eql(0)
14
14
  end
15
-
15
+
16
16
  it "should create a new Firefly::Url with a new long_url" do
17
17
  lambda {
18
18
  Firefly::Url.shorten("http://example.com/")
19
19
  }.should change(Firefly::Url, :count).by(1)
20
20
  end
21
-
21
+
22
22
  it "should return an existing Firefly::Url if the long_url exists" do
23
23
  Firefly::Url.shorten("http://example.com/")
24
24
  lambda {
25
25
  Firefly::Url.shorten("http://example.com/")
26
26
  }.should_not change(Firefly::Url, :count)
27
27
  end
28
-
28
+
29
29
  it "should normalize urls correctly" do
30
30
  # Note the trailing '/'
31
31
  Firefly::Url.shorten("http://example.com/")
32
32
  lambda {
33
33
  Firefly::Url.shorten("http://example.com")
34
- }.should_not change(Firefly::Url, :count)
34
+ }.should_not change(Firefly::Url, :count)
35
35
  end
36
36
 
37
37
  it "should shortend urls containing spaces" do
@@ -55,8 +55,18 @@ describe "Url" do
55
55
  url = Firefly::Url.shorten("http://example.com/?a=\11\15")
56
56
  url.url.should eql("http://example.com/?a=%09%0D")
57
57
  end
58
+
59
+ it "should automatically forward code to prevent duplicates" do
60
+ url = Firefly::Url.shorten("http://example.com/")
61
+ the_code = url.code.next
62
+ Firefly::Url.create(:url => "http://example.com/blah", :code => the_code)
63
+
64
+ url_correct = Firefly::Url.shorten("http://example.com/testit")
65
+ url_correct.code.should_not eql(the_code)
66
+ url_correct.code.should eql(the_code.next)
67
+ end
58
68
  end
59
-
69
+
60
70
  describe "long url validation" do
61
71
  [ "http://ariejan.net",
62
72
  "https://ariejan.net",
@@ -68,18 +78,20 @@ describe "Url" do
68
78
  Firefly::Url.shorten(url).should_not be_nil
69
79
  end
70
80
  end
71
-
81
+
72
82
  [ "ftp://ariejan.net",
73
83
  "irc://freenode.org/rails",
74
84
  "skype:adevroom",
75
85
  "ariejan.net",
76
86
  ].each do |url|
77
87
  it "should not accept #{url}" do
78
- Firefly::Url.shorten(url).should be_nil
88
+ lambda {
89
+ Firefly::Url.shorten(url).should be_nil
90
+ }.should raise_error(Firefly::InvalidUrlError)
79
91
  end
80
- end
92
+ end
81
93
  end
82
-
94
+
83
95
  describe "clicking" do
84
96
  before(:each) do
85
97
  Firefly::Url.create(
@@ -89,7 +101,7 @@ describe "Url" do
89
101
  )
90
102
  @url = Firefly::Url.first(:code => 'alpha')
91
103
  end
92
-
104
+
93
105
  it "should increase the click count" do
94
106
  lambda {
95
107
  @url.register_click!
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'lib', 'firefly.rb')
2
2
 
3
3
  require 'rubygems'
4
+ require "bundler/setup"
5
+
4
6
  require 'sinatra'
5
7
  require 'rack/test'
6
8
  require 'spec'
@@ -17,7 +19,7 @@ set :logging, false
17
19
  @@app = Firefly::Server.new do
18
20
  set :hostname, "test.host"
19
21
  set :api_key, "test"
20
- set :database, "sqlite3://#{Dir.pwd}/firefly_test.sqlite3"
22
+ set :database, "mysql://root@localhost/firefly_test"
21
23
  end
22
24
 
23
25
  Spec::Runner.configure do |config|
@@ -34,6 +36,7 @@ Spec::Runner.configure do |config|
34
36
  config.before(:each) do
35
37
  repository do |r|
36
38
  transaction = DataMapper::Transaction.new(r)
39
+ Firefly::CodeFactory.first.update(:count => 0)
37
40
  transaction.begin
38
41
  r.adapter.push_transaction(transaction)
39
42
  end
data/views/error.haml ADDED
@@ -0,0 +1,11 @@
1
+ %h1 Whoops!
2
+
3
+ %p
4
+ There was an error processing your request:
5
+
6
+ %p
7
+ %blockquote
8
+ = @result
9
+
10
+ %p
11
+ %a(href='/') Go back
data/views/index.haml CHANGED
@@ -1,5 +1,4 @@
1
1
  - if @authenticated
2
-
3
2
  .sidebox
4
3
  %h2 Bookmarklet
5
4
 
@@ -7,9 +6,9 @@
7
6
  Drag the following link to your bookmarks. Click it to shorten the URL to the page you're currently viewing.
8
7
  %p
9
8
  %a{ :href => "javascript:var%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:('%22'+enc(s)+'%22')),key=enc('#{@config[:api_key]}'),f='http://#{@config[:hostname]}/api/add',l=d.location,p='?visual=1&api_key='+key+'&url='+enc(l.href),u=f+p;try{if(!/^(.*\.)?tumblrzzz[^.]*$/.test(l.host))throw(0);tstbklt();}catch(z){a%20=function(){if(!w.open(u))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();}void(0)" } Shorten with #{@config[:hostname]}
10
-
9
+
11
10
  %h1 How about shortening a URL?
12
-
11
+
13
12
  .the_form
14
13
  %form{ :action => '/api/add', :method => 'post' }
15
14
  %input{ :type => "hidden", :name => "visual", :value => "1" }
@@ -19,18 +18,10 @@
19
18
  %input.big_url{ :type => 'text', :placeholder => "Optional short code", :name => 'short', :id => 'short', :size => 20, :autocomplete => "off", :spellcheck => 'false' }
20
19
  %p
21
20
  %input.big_url{ :type => 'submit', :name => 'submit', :id => 'submit', :value => "Make it short!" }
22
-
23
- - if @error
24
- %h2 Whoops!
25
-
26
- %p
27
- The URL you posted is invalid. Please post a valid HTTP url, including the protocol (http://) prefix.
28
21
 
29
- %p= @url
30
-
31
22
  - if @highlight
32
23
  %h2 Your short URL
33
-
24
+
34
25
  %table
35
26
  %tr
36
27
  %td.label Short URL
@@ -60,14 +51,14 @@
60
51
  - @urls.each do |url|
61
52
  %tr{ :class => is_highlighted?(url) ? 'highlighted' : '' }
62
53
  %td.value
63
- %input{ :type => "text", :value => short_url(url), :class => 'short_url', :size => 21 }
54
+ %input{ :type => "text", :value => short_url(url), :class => 'short_url', :size => 31 }
64
55
  %td.value.fill <a href="#{url.url}">#{url.url}</a>
65
56
  %td.value.center= url.clicks
66
57
  %td.value= url.created_at.strftime("%Y-%m-%d %H:%M")
67
58
  %td.value
68
59
  %a{ :href => "http://twitter.com/home?status=#{tweet(short_url(url))}" }
69
60
  %img.twitter{ :src => "/images/twitter.png", :width => "16", :height => "16" }
70
-
61
+
71
62
  :javascript
72
63
  $(document).ready(function() {
73
64
  $('input.short_url').each(function(index) {
data/views/info.haml CHANGED
@@ -9,7 +9,7 @@
9
9
  %td.label Full URL
10
10
  %td.label Clicks
11
11
  %td.label Shortened at
12
-
12
+
13
13
  %tr
14
14
  %td.value
15
15
  %input{ :type => "text", :value => short_url(@url), :class => 'short_url', :size => 21 }
@@ -21,6 +21,6 @@
21
21
  $(document).ready(function() {
22
22
  $('input.short_url').each(function(index) {
23
23
  $(this).mouseup(function() { $(this).select(); });
24
- });
24
+ });
25
25
  });
26
-
26
+
data/views/layout.haml CHANGED
@@ -8,13 +8,11 @@
8
8
  %script{ :type => "text/javascript", :src => u('jquery-1.4.2.min.js') }
9
9
  %body
10
10
  .header
11
- %ul.nav
12
- %li.current
13
- %a{ :href => '/' } #{@title}
14
-
11
+ %h1= @title
12
+
15
13
  #main
16
14
  = yield
17
-
15
+
18
16
  #footer
19
17
  %p
20
- Powered by <a href="http://github.com/ariejan/firefly">Firefly</a> v#{Firefly::Version} | <a href="http://github.com/ariejan/firefly/tree/v#{Firefly::Version}">Source</a> | <a href="http://github.com/ariejan/firefly/issues">Issues</a> | Export <a href="/api/export.csv">CSV</a>, <a href="/api/export.yml">YAML</a> or <a href="/api/export.xml">XML</a>
18
+ Powered by <a href="http://github.com/ariejan/firefly">Firefly</a> v#{Firefly::VERSION} | <a href="http://github.com/ariejan/firefly/tree/v#{Firefly::VERSION}">Source</a> | <a href="http://github.com/ariejan/firefly/issues">Issues</a> | Export <a href="/api/export.csv">CSV</a>, <a href="/api/export.yml">YAML</a> or <a href="/api/export.xml">XML</a>
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 2
10
- version: 1.2.2
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ariejan de Vroom
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-28 00:00:00 +01:00
18
+ date: 2011-02-01 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -98,7 +98,7 @@ dependencies:
98
98
  type: :runtime
99
99
  version_requirements: *id005
100
100
  - !ruby/object:Gem::Dependency
101
- name: dm-sqlite-adapter
101
+ name: dm-mysql-adapter
102
102
  prerelease: false
103
103
  requirement: &id006 !ruby/object:Gem::Requirement
104
104
  none: false
@@ -162,16 +162,18 @@ dependencies:
162
162
  type: :development
163
163
  version_requirements: *id009
164
164
  description: FireFly is a simple URL shortner for personal use. It's powered by Sinatra and can be run with any Rack-capable web server.
165
- email: ariejan@ariejan.net
165
+ email:
166
+ - ariejan@ariejan.net
166
167
  executables: []
167
168
 
168
169
  extensions: []
169
170
 
170
- extra_rdoc_files:
171
- - LICENSE
172
- - README.md
171
+ extra_rdoc_files: []
172
+
173
173
  files:
174
174
  - .gitignore
175
+ - Gemfile
176
+ - Gemfile.lock
175
177
  - HISTORY
176
178
  - LICENSE
177
179
  - README.md
@@ -179,8 +181,10 @@ files:
179
181
  - VERSION
180
182
  - config.ru.example
181
183
  - firefly.gemspec
184
+ - firefly_test.sqlite3-journal
182
185
  - lib/firefly.rb
183
186
  - lib/firefly/base62.rb
187
+ - lib/firefly/code_factory.rb
184
188
  - lib/firefly/config.rb
185
189
  - lib/firefly/server.rb
186
190
  - lib/firefly/url.rb
@@ -195,11 +199,13 @@ files:
195
199
  - spec/files/export.yml
196
200
  - spec/firefly/api_spec.rb
197
201
  - spec/firefly/base62_spec.rb
202
+ - spec/firefly/code_factory_spec.rb
198
203
  - spec/firefly/server_spec.rb
199
204
  - spec/firefly/url_spec.rb
200
205
  - spec/fixtures/urls.yml
201
206
  - spec/spec.opts
202
207
  - spec/spec_helper.rb
208
+ - views/error.haml
203
209
  - views/index.haml
204
210
  - views/info.haml
205
211
  - views/layout.haml
@@ -208,8 +214,8 @@ homepage: http://github.com/ariejan/firefly
208
214
  licenses: []
209
215
 
210
216
  post_install_message:
211
- rdoc_options:
212
- - --charset=UTF-8
217
+ rdoc_options: []
218
+
213
219
  require_paths:
214
220
  - lib
215
221
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -238,8 +244,14 @@ signing_key:
238
244
  specification_version: 3
239
245
  summary: FireFly is a simple URL shortner for personal use
240
246
  test_files:
247
+ - spec/files/export.csv
248
+ - spec/files/export.xml
249
+ - spec/files/export.yml
241
250
  - spec/firefly/api_spec.rb
242
251
  - spec/firefly/base62_spec.rb
252
+ - spec/firefly/code_factory_spec.rb
243
253
  - spec/firefly/server_spec.rb
244
254
  - spec/firefly/url_spec.rb
255
+ - spec/fixtures/urls.yml
256
+ - spec/spec.opts
245
257
  - spec/spec_helper.rb