enju_news 0.0.2

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 (108) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +47 -0
  4. data/app/controllers/news_feeds_controller.rb +101 -0
  5. data/app/controllers/news_posts_controller.rb +98 -0
  6. data/app/helpers/news_feeds_helper.rb +2 -0
  7. data/app/helpers/news_posts_helper.rb +2 -0
  8. data/app/models/news_feed.rb +83 -0
  9. data/app/models/news_feed_sweeper.rb +12 -0
  10. data/app/models/news_post.rb +15 -0
  11. data/app/views/news_feeds/_content.html.erb +9 -0
  12. data/app/views/news_feeds/_content_atom.html.erb +16 -0
  13. data/app/views/news_feeds/_content_rss.html.erb +16 -0
  14. data/app/views/news_feeds/_form.html.erb +14 -0
  15. data/app/views/news_feeds/_list.html.erb +7 -0
  16. data/app/views/news_feeds/edit.html.erb +29 -0
  17. data/app/views/news_feeds/index.html.erb +42 -0
  18. data/app/views/news_feeds/new.html.erb +28 -0
  19. data/app/views/news_feeds/show.html.erb +34 -0
  20. data/app/views/news_posts/_form.html.erb +44 -0
  21. data/app/views/news_posts/edit.html.erb +13 -0
  22. data/app/views/news_posts/index.atom.builder +11 -0
  23. data/app/views/news_posts/index.html.erb +42 -0
  24. data/app/views/news_posts/index.rss.builder +32 -0
  25. data/app/views/news_posts/new.html.erb +12 -0
  26. data/app/views/news_posts/show.html.erb +49 -0
  27. data/config/locales/translation_en.yml +28 -0
  28. data/config/locales/translation_ja.yml +28 -0
  29. data/config/routes.rb +4 -0
  30. data/db/migrate/20081031033632_create_news_feeds.rb +13 -0
  31. data/db/migrate/20090126071155_create_news_posts.rb +18 -0
  32. data/db/migrate/20110220103937_add_url_to_news_post.rb +9 -0
  33. data/lib/enju_news.rb +6 -0
  34. data/lib/enju_news/engine.rb +12 -0
  35. data/lib/enju_news/expire_editable_fragment.rb +15 -0
  36. data/lib/enju_news/version.rb +3 -0
  37. data/lib/tasks/enju_news_tasks.rake +4 -0
  38. data/spec/cassette_library/NewsFeed.yml +1998 -0
  39. data/spec/controllers/news_feeds_controller_spec.rb +445 -0
  40. data/spec/controllers/news_posts_controller_spec.rb +443 -0
  41. data/spec/dummy/Rakefile +7 -0
  42. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  43. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  44. data/spec/dummy/app/controllers/application_controller.rb +52 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  46. data/spec/dummy/app/models/ability.rb +22 -0
  47. data/spec/dummy/app/models/library_group.rb +86 -0
  48. data/spec/dummy/app/models/role.rb +46 -0
  49. data/spec/dummy/app/models/user.rb +94 -0
  50. data/spec/dummy/app/models/user_group.rb +40 -0
  51. data/spec/dummy/app/models/user_has_role.rb +5 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  53. data/spec/dummy/app/views/page/403.html.erb +9 -0
  54. data/spec/dummy/app/views/page/403.mobile.erb +5 -0
  55. data/spec/dummy/app/views/page/403.xml.erb +4 -0
  56. data/spec/dummy/app/views/page/404.html.erb +9 -0
  57. data/spec/dummy/app/views/page/404.mobile.erb +5 -0
  58. data/spec/dummy/app/views/page/404.xml.erb +4 -0
  59. data/spec/dummy/config.ru +4 -0
  60. data/spec/dummy/config/application.rb +47 -0
  61. data/spec/dummy/config/boot.rb +10 -0
  62. data/spec/dummy/config/database.yml +25 -0
  63. data/spec/dummy/config/environment.rb +5 -0
  64. data/spec/dummy/config/environments/development.rb +30 -0
  65. data/spec/dummy/config/environments/production.rb +60 -0
  66. data/spec/dummy/config/environments/test.rb +39 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/devise.rb +205 -0
  69. data/spec/dummy/config/initializers/inflections.rb +10 -0
  70. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  71. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  72. data/spec/dummy/config/initializers/session_store.rb +8 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy/config/locales/en.yml +5 -0
  75. data/spec/dummy/config/routes.rb +60 -0
  76. data/spec/dummy/db/migrate/077_create_user_groups.rb +16 -0
  77. data/spec/dummy/db/migrate/080_create_library_groups.rb +20 -0
  78. data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +9 -0
  79. data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +13 -0
  80. data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
  81. data/spec/dummy/db/migrate/20111201155456_create_users.rb +16 -0
  82. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +44 -0
  83. data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
  84. data/spec/dummy/db/schema.rb +116 -0
  85. data/spec/dummy/db/test.sqlite3 +0 -0
  86. data/spec/dummy/lib/master_model.rb +19 -0
  87. data/spec/dummy/lib/url_validator.rb +10 -0
  88. data/spec/dummy/public/404.html +26 -0
  89. data/spec/dummy/public/422.html +26 -0
  90. data/spec/dummy/public/500.html +26 -0
  91. data/spec/dummy/public/favicon.ico +0 -0
  92. data/spec/dummy/script/rails +6 -0
  93. data/spec/factories/news_feed.rb +6 -0
  94. data/spec/factories/news_post.rb +7 -0
  95. data/spec/factories/user.rb +37 -0
  96. data/spec/fixtures/library_groups.yml +33 -0
  97. data/spec/fixtures/news_feeds.yml +11 -0
  98. data/spec/fixtures/news_posts.yml +13 -0
  99. data/spec/fixtures/roles.yml +21 -0
  100. data/spec/fixtures/user_has_roles.yml +41 -0
  101. data/spec/fixtures/users.yml +93 -0
  102. data/spec/models/news_feed_spec.rb +31 -0
  103. data/spec/models/news_post_spec.rb +5 -0
  104. data/spec/spec_helper.rb +42 -0
  105. data/spec/support/controller_macros.rb +46 -0
  106. data/spec/support/devise.rb +4 -0
  107. data/spec/support/vcr.rb +9 -0
  108. metadata +430 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :news_feed do |f|
3
+ f.sequence(:title){|n| "news_feed_#{n}"}
4
+ f.sequence(:url){|n| "http://www.example.com/feed/#{n}"}
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :news_post do |f|
3
+ f.sequence(:title){|n| "news_post_#{n}"}
4
+ f.sequence(:body){|n| "news_post_#{n}"}
5
+ f.user{FactoryGirl.create(:librarian)}
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ FactoryGirl.define do
2
+ factory :admin, :class => User do |f|
3
+ f.sequence(:username){|n| "admin_#{n}"}
4
+ f.sequence(:email){|n| "admin_#{n}@example.jp"}
5
+ f.role {Role.find_by_name('Administrator')}
6
+ f.password 'adminpassword'
7
+ f.password_confirmation 'adminpassword'
8
+ f.user_group {UserGroup.first}
9
+ f.required_role {Role.find_by_name('User')}
10
+ f.sequence(:user_number){|n| "user_number_#{n}"}
11
+ end
12
+
13
+ factory :librarian, :class => User do |f|
14
+ f.sequence(:username){|n| "librarian_#{n}"}
15
+ f.sequence(:email){|n| "librarian_#{n}@example.jp"}
16
+ f.role {Role.find_by_name('Librarian')}
17
+ f.password 'librarianpassword'
18
+ f.password_confirmation 'librarianpassword'
19
+ f.user_group {UserGroup.first}
20
+ f.required_role {Role.find_by_name('User')}
21
+ f.sequence(:user_number){|n| "user_number_#{n}"}
22
+ end
23
+
24
+ factory :user, :class => User do |f|
25
+ f.sequence(:username){|n| "user_#{n}"}
26
+ f.sequence(:email){|n| "user_#{n}@example.jp"}
27
+ f.role {Role.find_by_name('User')}
28
+ f.password 'userpassword'
29
+ f.password_confirmation 'userpassword'
30
+ f.user_group {UserGroup.first}
31
+ f.required_role {Role.find_by_name('User')}
32
+ f.sequence(:user_number){|n| "user_number_#{n}"}
33
+ end
34
+
35
+ factory :invalid_user, :class => User do |f|
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ name: enju_library
5
+ display_name: "<%= I18n.locale %>: Enju Library"
6
+ short_name: enju
7
+ email: next-l@library.example.jp
8
+ note:
9
+ my_networks: 0.0.0.0/0
10
+ url: "http://localhost:3000/"
11
+
12
+
13
+ # == Schema Information
14
+ #
15
+ # Table name: library_groups
16
+ #
17
+ # id :integer not null, primary key
18
+ # name :string(255) not null
19
+ # display_name :text
20
+ # short_name :string(255) not null
21
+ # email :string(255)
22
+ # my_networks :text
23
+ # login_banner :text
24
+ # note :text
25
+ # country_id :integer
26
+ # created_at :datetime not null
27
+ # updated_at :datetime not null
28
+ # admin_networks :text
29
+ # allow_bookmark_external_url :boolean default(FALSE), not null
30
+ # position :integer
31
+ # url :string(255) default("http://localhost:3000/")
32
+ #
33
+
@@ -0,0 +1,11 @@
1
+ news_feed_00001:
2
+ id: 1
3
+ title: NDL
4
+ url: http://iss.ndl.go.jp/information/feed/
5
+ position: 1
6
+
7
+ news_feed_00002:
8
+ id: 2
9
+ title: invalid feed
10
+ url: http://example.com/invalid_feed
11
+ position: 2
@@ -0,0 +1,13 @@
1
+ news_post_00001:
2
+ id: 1
3
+ title: お知らせ
4
+ body: お知らせの内容
5
+ user_id: 1
6
+ position: 1
7
+
8
+ news_post_00002:
9
+ id: 2
10
+ title: お知らせ
11
+ body: お知らせの内容
12
+ user_id: 1
13
+ position: 2
@@ -0,0 +1,21 @@
1
+ ---
2
+ role_00001:
3
+ name: Guest
4
+ display_name: Guest
5
+ id: 1
6
+ note:
7
+ role_00002:
8
+ name: User
9
+ display_name: User
10
+ id: 2
11
+ note:
12
+ role_00003:
13
+ name: Librarian
14
+ display_name: Librarian
15
+ id: 3
16
+ note:
17
+ role_00004:
18
+ name: Administrator
19
+ display_name: Administrator
20
+ id: 4
21
+ note:
@@ -0,0 +1,41 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ admin:
4
+ user_id: 1
5
+ role_id: 4
6
+
7
+ librarian1:
8
+ user_id: 2
9
+ role_id: 3
10
+
11
+ user1:
12
+ user_id: 3
13
+ role_id: 2
14
+
15
+ librarian2:
16
+ user_id: 4
17
+ role_id: 3
18
+
19
+ user2:
20
+ user_id: 5
21
+ role_id: 2
22
+
23
+ user3:
24
+ user_id: 6
25
+ role_id: 2
26
+
27
+ user4:
28
+ user_id: 7
29
+ role_id: 2
30
+
31
+ # == Schema Information
32
+ #
33
+ # Table name: user_has_roles
34
+ #
35
+ # id :integer not null, primary key
36
+ # user_id :integer
37
+ # role_id :integer
38
+ # created_at :datetime
39
+ # updated_at :datetime
40
+ #
41
+
@@ -0,0 +1,93 @@
1
+ ---
2
+ admin:
3
+ updated_at: 2008-05-31 13:16:30.163731 +09:00
4
+ encrypted_password: $2a$10$vHohD1WflnTIqAa8zMkF9evwAgIZRw3XuR4d3bi29M.jph/MB/AJi
5
+ user_group_id: 2
6
+ id: 1
7
+ note:
8
+ username: admin
9
+ library_id: 2
10
+ email: tanabe@kamata.lib.teu.ac.jp
11
+ created_at: 2007-11-19 16:58:32.111941 +09:00
12
+ required_role_id: 4
13
+ user_number: "00001"
14
+ locale: "ja"
15
+ librarian1:
16
+ updated_at: 2008-05-31 12:41:16.337474 +09:00
17
+ encrypted_password: $2a$10$9O2VuTccN4gHq36ARg0QReSrb1D7WrBBhZZ759RM9moHbB0W5zCzS
18
+ user_group_id: 1
19
+ id: 2
20
+ note:
21
+ username: librarian1
22
+ library_id: 1
23
+ email: librarian1@kamata.lib.teu.ac.jp
24
+ created_at: 2007-11-19 16:58:33.172441 +09:00
25
+ required_role_id: 1
26
+ user_number: "00002"
27
+ locale: "ja"
28
+ user1:
29
+ updated_at: 2008-05-31 13:02:25.101261 +09:00
30
+ encrypted_password: $2a$10$JthS59A0BNkDOoFpCXM0V.GhhffKaoWKbzpPahYp/vTFrOyM7h/uW
31
+ user_group_id: 1
32
+ id: 3
33
+ note:
34
+ username: user1
35
+ library_id: 2
36
+ email: user1@kamata.lib.teu.ac.jp
37
+ created_at: 2007-11-19 16:58:34.637413 +09:00
38
+ required_role_id: 3
39
+ user_number: "00003"
40
+ locale: "ja"
41
+ librarian2:
42
+ updated_at: 2008-05-31 12:42:23.340575 +09:00
43
+ encrypted_password: $2a$10$YmmTGrYQ1Ir6oc7wXnp.GuNeO1eYLoP3sv8wMSIrTdaGw2BPwRrpS
44
+ user_group_id: 1
45
+ id: 4
46
+ note:
47
+ username: librarian2
48
+ library_id: 2
49
+ email: librarian2@library.example.jp
50
+ created_at: 2008-01-18 12:24:04.222344 +09:00
51
+ required_role_id: 1
52
+ user_number: "00004"
53
+ locale: "ja"
54
+ user2:
55
+ updated_at: 2008-05-31 12:42:44.711117 +09:00
56
+ encrypted_password: $2a$10$i7UjJhLVrJM/J7qaTwW39OXw1NiwowUEbtNHVDV0sqMLjX9.UO9ca
57
+ user_group_id: 1
58
+ id: 5
59
+ note:
60
+ username: user2
61
+ library_id: 1
62
+ email: user2@library.example.jp
63
+ created_at: 2008-01-18 13:29:06.922728 +09:00
64
+ required_role_id: 2
65
+ # user_number: '00005'
66
+ locale: "ja"
67
+ user3:
68
+ updated_at: 2008-05-31 13:02:25.101261 +09:00
69
+ encrypted_password: cc53de0c2d9a1a228daa9a673ec824473747e17507a6c3c4f7e5eff8821f531d4b9e23616b3ddc66fe17006b2298a556fbd567ac080e87f00f37eef8cee6c417
70
+ user_group_id: 1
71
+ id: 6
72
+ note:
73
+ username: user3
74
+ library_id: 2
75
+ email: user3@kamata.lib.teu.ac.jp
76
+ created_at: 2007-11-19 16:58:34.637413 +09:00
77
+ required_role_id: 3
78
+ user_number: "00006"
79
+ locale: "ja"
80
+ user4:
81
+ updated_at: 2008-05-31 13:02:25.101261 +09:00
82
+ encrypted_password: cc53de0c2d9a1a228daa9a673ec824473747e17507a6c3c4f7e5eff8821f531d4b9e23616b3ddc66fe17006b2298a556fbd567ac080e87f00f37eef8cee6c417
83
+ user_group_id: 1
84
+ id: 7
85
+ note:
86
+ username: user4
87
+ library_id: 2
88
+ email: user4@kamata.lib.teu.ac.jp
89
+ created_at: 2007-11-19 16:58:34.637413 +09:00
90
+ required_role_id: 3
91
+ user_number: "00007"
92
+ locale: "ja"
93
+ locked_at: <%= 1.day.ago %>
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe NewsFeed do
5
+ fixtures :news_feeds
6
+ use_vcr_cassette :record => :new_episodes
7
+
8
+ it "should expire cache" do
9
+ news_feeds(:news_feed_00001).expire_cache.should be_true
10
+ end
11
+
12
+ it "should expire fragment cache" do
13
+ news_feeds(:news_feed_00001).expire_fragment_cache.should be_true
14
+ end
15
+
16
+ it "should get content" do
17
+ news_feeds(:news_feed_00001).content.should be_true
18
+ end
19
+
20
+ it "should not get content if the feed is invalid" do
21
+ news_feeds(:news_feed_00002).content.should be_nil
22
+ end
23
+
24
+ it "should reload content" do
25
+ news_feeds(:news_feed_00001).force_reload.should be_true
26
+ end
27
+
28
+ it "should fetch feeds" do
29
+ NewsFeed.fetch_feeds.should be_true
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe NewsPost do
5
+ end
@@ -0,0 +1,42 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../spec/dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+ require 'factory_girl'
7
+ require 'vcr'
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc,
10
+ # in spec/support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+ #Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+ # ## Mock Framework
16
+ #
17
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
18
+ #
19
+ # config.mock_with :mocha
20
+ # config.mock_with :flexmock
21
+ # config.mock_with :rr
22
+
23
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
24
+ config.fixture_path = "#{::Rails.root}/../../spec/fixtures"
25
+
26
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
27
+ # examples within a transaction, remove the following line or assign false
28
+ # instead of true.
29
+ config.use_transactional_fixtures = true
30
+
31
+ # If true, the base class of anonymous controllers will be inferred
32
+ # automatically. This will be the default behavior in future versions of
33
+ # rspec-rails.
34
+ config.infer_base_class_for_anonymous_controllers = false
35
+
36
+ config.extend ControllerMacros, :type => :controller
37
+
38
+ config.extend VCR::RSpec::Macros
39
+ end
40
+
41
+ FactoryGirl.definition_file_paths << "#{::Rails.root}/../../spec/factories"
42
+ FactoryGirl.find_definitions
@@ -0,0 +1,46 @@
1
+ module ControllerMacros
2
+ def login_admin
3
+ before(:each) do
4
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
5
+ sign_in FactoryGirl.create(:admin)
6
+ end
7
+ end
8
+
9
+ def login_librarian
10
+ before(:each) do
11
+ @request.env["devise.mapping"] = Devise.mappings[:librarian]
12
+ sign_in FactoryGirl.create(:librarian)
13
+ end
14
+ end
15
+
16
+ def login_user
17
+ before(:each) do
18
+ @request.env["devise.mapping"] = Devise.mappings[:user]
19
+ sign_in FactoryGirl.create(:user)
20
+ end
21
+ end
22
+
23
+ def login_fixture_admin
24
+ before(:each) do
25
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
26
+ @user = users(:admin)
27
+ sign_in @user
28
+ end
29
+ end
30
+
31
+ def login_fixture_librarian
32
+ before(:each) do
33
+ @request.env["devise.mapping"] = Devise.mappings[:librarian]
34
+ @user = users(:librarian1)
35
+ sign_in @user
36
+ end
37
+ end
38
+
39
+ def login_fixture_user
40
+ before(:each) do
41
+ @request.env["devise.mapping"] = Devise.mappings[:user]
42
+ @user = users(:user1)
43
+ sign_in @user
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ RSpec.configure do |config|
2
+ config.include Devise::TestHelpers, :type => :controller
3
+ config.include Devise::TestHelpers, :type => :view
4
+ end