muck-raker 0.1.36 → 0.1.37
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/VERSION +1 -1
- data/app/controllers/muck/feed_previews_controller.rb +1 -1
- data/app/controllers/muck/feeds_controller.rb +5 -1
- data/app/controllers/muck/opmls_controller.rb +1 -2
- data/app/models/feed.rb +2 -1
- data/app/models/google_feed_request.rb +22 -3
- data/app/models/service.rb +1 -1
- data/muck-raker.gemspec +1 -1
- data/test/rails_root/test/functional/feeds_controller_test.rb +40 -29
- data/test/rails_root/test/functional/opmls_controller_test.rb +1 -1
- data/test/rails_root/test/test_helper.rb +18 -0
- data/test/rails_root/test/unit/google_feed_request_test.rb +21 -5
- data/test/rails_root/test/unit/service_test.rb +13 -5
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.37
|
@@ -15,7 +15,7 @@ class Muck::FeedPreviewsController < ApplicationController
|
|
15
15
|
|
16
16
|
def select_feeds
|
17
17
|
@feed = Feed.new(params[:feed])
|
18
|
-
@feeds = Feed.gather_information(@feed.uri)
|
18
|
+
@feeds = Feed.gather_information(@feed.uri).compact
|
19
19
|
respond_to do |format|
|
20
20
|
format.pjs do
|
21
21
|
render_as_html do
|
@@ -2,7 +2,8 @@ class Muck::FeedsController < ApplicationController
|
|
2
2
|
|
3
3
|
unloadable
|
4
4
|
|
5
|
-
before_filter :
|
5
|
+
before_filter :login_required, :except => ['index', 'show']
|
6
|
+
before_filter :get_owner, :except => ['index', 'show']
|
6
7
|
|
7
8
|
def index
|
8
9
|
@feeds = Feed.find(:all, :conditions => 'status >= 0', :order => (params[:order] || 'title') + (params[:asc] == 'false' ? ' DESC' : ' ASC') + ', title', :include => [:default_language]).paginate(:page => @page, :per_page => @per_page)
|
@@ -99,6 +100,9 @@ class Muck::FeedsController < ApplicationController
|
|
99
100
|
end
|
100
101
|
|
101
102
|
def has_permission_to_add_feed(user, parent)
|
103
|
+
return false if user.blank?
|
104
|
+
return true if user.admin?
|
105
|
+
return false if parent.blank?
|
102
106
|
user == parent || parent.can_add_feed?(user)
|
103
107
|
end
|
104
108
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class Muck::OpmlsController < ApplicationController
|
2
|
-
|
3
2
|
unloadable
|
4
3
|
|
5
4
|
def index
|
@@ -13,7 +12,7 @@ class Muck::OpmlsController < ApplicationController
|
|
13
12
|
@terms = params[:terms]
|
14
13
|
respond_to do |format|
|
15
14
|
format.html { render :template => 'opmls/index' }
|
16
|
-
format.opml { render
|
15
|
+
format.opml { render :template => 'opmls/index' }
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
data/app/models/feed.rb
CHANGED
@@ -144,13 +144,14 @@ class Feed < ActiveRecord::Base
|
|
144
144
|
feeds = []
|
145
145
|
@available_feeds = discover_feeds(uri)
|
146
146
|
@available_feeds.each do |feed|
|
147
|
-
feeds << from_feedzirra(Feedzirra::Feed.fetch_and_parse(feed.url))
|
147
|
+
feeds << from_feedzirra(Feedzirra::Feed.fetch_and_parse(feed.url)) unless feed.blank?
|
148
148
|
end
|
149
149
|
feeds
|
150
150
|
end
|
151
151
|
|
152
152
|
# Turns a feed from feedzirra into a muck feed
|
153
153
|
def self.from_feedzirra(feed)
|
154
|
+
return if feed.blank?
|
154
155
|
Feed.new(:short_title => feed.title,
|
155
156
|
:title => feed.title,
|
156
157
|
:display_uri => feed.url,
|
@@ -1,3 +1,9 @@
|
|
1
|
+
# Google ajax feed api reference:
|
2
|
+
# http://code.google.com/apis/ajaxfeeds/documentation/reference.html
|
3
|
+
#
|
4
|
+
# Google code playground:
|
5
|
+
# http://code.google.com/apis/ajax/playground/?exp=search#load_feed
|
6
|
+
#
|
1
7
|
class GoogleFeedRequest
|
2
8
|
include HTTParty
|
3
9
|
format :json
|
@@ -9,6 +15,14 @@ class GoogleFeedRequest
|
|
9
15
|
@api_key_id = api_key_id
|
10
16
|
end
|
11
17
|
|
18
|
+
def self.lookup_feed(uri)
|
19
|
+
get('http://ajax.googleapis.com/ajax/services/feed/lookup', :query => build_google_query({:q => uri}))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.load_feed(uri)
|
23
|
+
get('http://ajax.googleapis.com/ajax/services/feed/load', :query => build_google_query({:q => uri}))
|
24
|
+
end
|
25
|
+
|
12
26
|
# Search for feeds using google. This will return
|
13
27
|
# a collection of 'Feed' objects
|
14
28
|
def self.find_feeds(query)
|
@@ -18,9 +32,7 @@ class GoogleFeedRequest
|
|
18
32
|
# Search for feeds using google. This will return
|
19
33
|
# a hash with the results
|
20
34
|
def self.find_google_feeds(query)
|
21
|
-
|
22
|
-
query_options[:key] = GlobalConfig.google_ajax_api_key if GlobalConfig.google_ajax_api_key
|
23
|
-
get('http://ajax.googleapis.com/ajax/services/feed/find', :query => query_options)
|
35
|
+
get('http://ajax.googleapis.com/ajax/services/feed/find', :query => build_google_query({:q => query}))
|
24
36
|
end
|
25
37
|
|
26
38
|
# convert the result of a google query to 'Feed' objects
|
@@ -33,4 +45,11 @@ class GoogleFeedRequest
|
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
48
|
+
# Add standard items to the google query
|
49
|
+
def self.build_google_query(query_options)
|
50
|
+
query_options[:v] = '1.0'
|
51
|
+
query_options[:key] = GlobalConfig.google_ajax_api_key if GlobalConfig.google_ajax_api_key
|
52
|
+
query_options
|
53
|
+
end
|
54
|
+
|
36
55
|
end
|
data/app/models/service.rb
CHANGED
@@ -142,7 +142,7 @@ class Service < ActiveRecord::Base
|
|
142
142
|
# attempts to find a service using a uri
|
143
143
|
def self.find_service_by_uri(uri)
|
144
144
|
@services ||= Service.all
|
145
|
-
service = @services.detect { |service| service.uri && service.uri.length > 0 && uri.include?(service.uri) }
|
145
|
+
service = @services.detect { |service| service.uri && service.uri.length > 0 && (uri.include?(service.uri) || service.uri.include?(uri)) }
|
146
146
|
service ||= Service.find_by_name('rss') # this will return the default rss service
|
147
147
|
service
|
148
148
|
end
|
data/muck-raker.gemspec
CHANGED
@@ -25,42 +25,53 @@ class Muck::FeedsControllerTest < ActionController::TestCase
|
|
25
25
|
should_render_template :show
|
26
26
|
end
|
27
27
|
|
28
|
-
context "
|
28
|
+
context "logged in" do
|
29
29
|
setup do
|
30
|
-
|
30
|
+
@admin = Factory(:user)
|
31
|
+
@admin_role = Factory(:role, :rolename => 'administrator')
|
32
|
+
@admin.roles << @admin_role
|
33
|
+
activate_authlogic
|
34
|
+
login_as @admin
|
31
35
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
|
37
|
+
context "GET new" do
|
38
|
+
setup do
|
39
|
+
get :new
|
40
|
+
end
|
41
|
+
should_not_set_the_flash
|
42
|
+
should_respond_with :success
|
43
|
+
should_render_template :new
|
44
|
+
end
|
45
|
+
|
46
|
+
context "GET new_extended" do
|
47
|
+
setup do
|
48
|
+
get :new_extended
|
49
|
+
end
|
50
|
+
should_not_set_the_flash
|
51
|
+
should_respond_with :success
|
52
|
+
should_render_template :new_extended
|
40
53
|
end
|
41
|
-
should_not_set_the_flash
|
42
|
-
should_respond_with :success
|
43
|
-
should_render_template :new_extended
|
44
|
-
end
|
45
54
|
|
46
|
-
|
47
|
-
|
48
|
-
|
55
|
+
context "POST create (simple)" do
|
56
|
+
setup do
|
57
|
+
post :create, :feed => { :uri => TEST_RSS_URI }
|
58
|
+
end
|
59
|
+
should_set_the_flash_to(I18n.t('muck.raker.feed_successfully_created', :uri => TEST_RSS_URI))
|
49
60
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
|
62
|
+
context "POST create (advanced)" do
|
63
|
+
setup do
|
64
|
+
post :create, :feed => { :uri => TEST_RSS_URI,
|
65
|
+
:display_uri => 'http://www.example.com',
|
66
|
+
:title => 'test feed long',
|
67
|
+
:short_title => 'test feed',
|
68
|
+
:description => 'foo bar' }
|
69
|
+
end
|
70
|
+
should_set_the_flash_to(I18n.t('muck.raker.feed_successfully_created', :uri => TEST_RSS_URI))
|
60
71
|
end
|
61
|
-
should_set_the_flash_to(I18n.t('muck.raker.feed_successfully_created', :uri => TEST_RSS_URI))
|
62
|
-
end
|
63
72
|
|
73
|
+
end
|
74
|
+
|
64
75
|
end
|
65
76
|
|
66
77
|
end
|
@@ -7,6 +7,7 @@ gem 'thoughtbot-factory_girl' # from github
|
|
7
7
|
require 'factory_girl'
|
8
8
|
require 'mocha'
|
9
9
|
require 'authlogic/test_case'
|
10
|
+
require 'active_record/fixtures'
|
10
11
|
require 'redgreen' rescue LoadError
|
11
12
|
require File.expand_path(File.dirname(__FILE__) + '/factories')
|
12
13
|
require File.join(File.dirname(__FILE__), 'shoulda_macros', 'controller')
|
@@ -56,3 +57,20 @@ class ActsAsSolr::Post
|
|
56
57
|
true
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
|
62
|
+
# load in the default data required to run the app
|
63
|
+
def bootstrap_services
|
64
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
65
|
+
|
66
|
+
ServiceCategory.delete_all
|
67
|
+
yml = File.join(File.dirname(__FILE__), '..', '..', '..', 'db', 'bootstrap',"service_categories")
|
68
|
+
Fixtures.new(Service.connection,"service_categories",ServiceCategory,yml).insert_fixtures
|
69
|
+
|
70
|
+
Service.delete_all
|
71
|
+
yml = File.join(File.dirname(__FILE__), '..', '..', '..', 'db', 'bootstrap',"services")
|
72
|
+
Fixtures.new(Service.connection,"services",Service,yml).insert_fixtures
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
bootstrap_services
|
@@ -3,10 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
3
3
|
class GoogleFeedRequestTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
context "google feed requests" do
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
context "find_feeds" do
|
6
|
+
|
7
|
+
context "find feeds" do
|
10
8
|
setup do
|
11
9
|
@feeds = GoogleFeedRequest.find_feeds('ruby')
|
12
10
|
end
|
@@ -18,7 +16,7 @@ class GoogleFeedRequestTest < ActiveSupport::TestCase
|
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
context "
|
19
|
+
context "find feeds (raw results)" do
|
22
20
|
setup do
|
23
21
|
@feeds = GoogleFeedRequest.find_google_feeds('ruby')
|
24
22
|
end
|
@@ -27,6 +25,24 @@ class GoogleFeedRequestTest < ActiveSupport::TestCase
|
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
28
|
+
context "lookup feed" do
|
29
|
+
setup do
|
30
|
+
@result = GoogleFeedRequest.lookup_feed('http://www.justinball.com')
|
31
|
+
end
|
32
|
+
should "discover rss feed using uri" do
|
33
|
+
assert_equal 'http://www.justinball.com/feed/', @result['responseData']['url']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "load feed" do
|
38
|
+
setup do
|
39
|
+
@entries = GoogleFeedRequest.load_feed('http://www.justinball.com')
|
40
|
+
end
|
41
|
+
should "get entries from feed" do
|
42
|
+
assert @entries.length > 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
30
46
|
end
|
31
47
|
|
32
48
|
end
|
@@ -84,10 +84,10 @@ class ServiceTest < ActiveSupport::TestCase
|
|
84
84
|
feeds = Service.build_feeds(@user, tag)
|
85
85
|
assert feeds.any?{|feed| feed.display_uri == (@uri_template.sub('{tag}', tag))}
|
86
86
|
end
|
87
|
-
should "build a feed for every service" do
|
87
|
+
should "build a feed for every tag service" do
|
88
88
|
tag = 'cycling'
|
89
89
|
feeds = Service.build_feeds(@user, tag)
|
90
|
-
assert_equal Service.
|
90
|
+
assert_equal Service.tag_services.length, feeds.length
|
91
91
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
92
92
|
end
|
93
93
|
should "build a limited number of feeds for tag" do
|
@@ -96,10 +96,10 @@ class ServiceTest < ActiveSupport::TestCase
|
|
96
96
|
assert_equal 1, feeds.length
|
97
97
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
98
98
|
end
|
99
|
-
should "create a feed for every service" do
|
99
|
+
should "create a feed for every tag service" do
|
100
100
|
tag = 'physics'
|
101
101
|
feeds = Service.create_feeds(@user, tag)
|
102
|
-
assert_equal Service.
|
102
|
+
assert_equal Service.tag_services.length, feeds.length
|
103
103
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
104
104
|
end
|
105
105
|
should "create a limited number of feeds for tag" do
|
@@ -138,12 +138,20 @@ class ServiceTest < ActiveSupport::TestCase
|
|
138
138
|
|
139
139
|
context "Find service by uri" do
|
140
140
|
setup do
|
141
|
+
Service.delete_all
|
141
142
|
@service = Factory(:service, :uri => 'http://www.example.com')
|
142
143
|
end
|
143
|
-
|
144
|
+
after do
|
145
|
+
bootstrap_services
|
146
|
+
end
|
147
|
+
should "find service when uri is shorter" do
|
144
148
|
service = Service.find_service_by_uri('example.com')
|
145
149
|
assert_equal @service, service
|
146
150
|
end
|
151
|
+
should "find service uri is longer" do
|
152
|
+
service = Service.find_service_by_uri('http://www.example.com/other_stuff')
|
153
|
+
assert_equal @service, service
|
154
|
+
end
|
147
155
|
end
|
148
156
|
|
149
157
|
end
|