enju_news 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'ebc38496653c90ed178262961b6dfce7d0e504d7ea0d5f946554451c9923717c6057f56a36b42392c5834bde2023c2d9e8863d888e624574b1a13e5a7ce2262c'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,60 @@
1
+ Dummy::Application.routes.draw do
2
+ devise_for :users
3
+
4
+ # The priority is based upon order of creation:
5
+ # first created -> highest priority.
6
+
7
+ # Sample of regular route:
8
+ # match 'products/:id' => 'catalog#view'
9
+ # Keep in mind you can assign values other than :controller and :action
10
+
11
+ # Sample of named route:
12
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
13
+ # This route can be invoked with purchase_url(:id => product.id)
14
+
15
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
16
+ # resources :products
17
+
18
+ # Sample resource route with options:
19
+ # resources :products do
20
+ # member do
21
+ # get 'short'
22
+ # post 'toggle'
23
+ # end
24
+ #
25
+ # collection do
26
+ # get 'sold'
27
+ # end
28
+ # end
29
+
30
+ # Sample resource route with sub-resources:
31
+ # resources :products do
32
+ # resources :comments, :sales
33
+ # resource :seller
34
+ # end
35
+
36
+ # Sample resource route with more complex sub-resources
37
+ # resources :products do
38
+ # resources :comments
39
+ # resources :sales do
40
+ # get 'recent', :on => :collection
41
+ # end
42
+ # end
43
+
44
+ # Sample resource route within a namespace:
45
+ # namespace :admin do
46
+ # # Directs /admin/products/* to Admin::ProductsController
47
+ # # (app/controllers/admin/products_controller.rb)
48
+ # resources :products
49
+ # end
50
+
51
+ # You can have the root of your site routed with "root"
52
+ # just remember to delete public/index.html.
53
+ # root :to => 'welcome#index'
54
+
55
+ # See how all your routes lay out with "rake routes"
56
+
57
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
58
+ # Note: This route will make all actions in every controller accessible via GET requests.
59
+ # match ':controller(/:action(/:id(.:format)))'
60
+ end
@@ -0,0 +1,16 @@
1
+ class CreateUserGroups < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :user_groups do |t|
4
+ t.string :name, :string, :not_null => true
5
+ t.text :display_name, :string
6
+ t.text :note
7
+ t.integer :position
8
+ t.timestamps
9
+ t.datetime :deleted_at
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :user_groups
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ class CreateLibraryGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :library_groups do |t|
4
+ t.string :name, :null => false
5
+ t.text :display_name
6
+ t.string :short_name, :null => false
7
+ t.string :email
8
+ t.text :my_networks
9
+ t.boolean :use_dsbl, :default => false, :null => false
10
+ t.text :dsbl_list
11
+ t.text :login_banner
12
+ t.text :note
13
+ t.integer :valid_period_for_new_user, :default => 365, :null => false
14
+ t.integer :country_id
15
+
16
+ t.timestamps
17
+ end
18
+ add_index :library_groups, :short_name
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ class AddUrlToLibraryGroup < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :library_groups, :url, :string, :default => 'http://localhost:3000/'
4
+ end
5
+
6
+ def self.down
7
+ remove_column :library_groups, :url
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class AddValidPeriodForNewUserToUserGroup < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :user_groups, :valid_period_for_new_user, :integer, :default => 0, :null => false
4
+ add_column :user_groups, :expired_at, :timestamp
5
+ remove_column :library_groups, :valid_period_for_new_user
6
+ end
7
+
8
+ def self.down
9
+ remove_column :user_groups, :valid_period_for_new_user
10
+ remove_column :user_groups, :expired_at
11
+ add_column :library_groups, :valid_period_for_new_user, :integer, :default => 0, :null => false
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateRoles < ActiveRecord::Migration
2
+ def change
3
+ create_table :roles do |t|
4
+ t.string :name
5
+ t.text :display_name
6
+ t.text :note
7
+ t.integer :position
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.integer :user_group_id
5
+ t.integer :required_role_id
6
+ t.string :username
7
+ t.text :note
8
+ t.string :locale
9
+ t.string :user_number
10
+ t.integer :library_id
11
+ t.datetime :locked_at
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ class AddDeviseToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ change_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ # t.encryptable
23
+ # t.confirmable
24
+ # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
25
+ # t.token_authenticatable
26
+
27
+
28
+ # Uncomment below if timestamps were not included in your original model.
29
+ # t.timestamps
30
+ end
31
+
32
+ add_index :users, :email #, :unique => true
33
+ add_index :users, :reset_password_token, :unique => true
34
+ # add_index :users, :confirmation_token, :unique => true
35
+ # add_index :users, :unlock_token, :unique => true
36
+ # add_index :users, :authentication_token, :unique => true
37
+ end
38
+
39
+ def self.down
40
+ # By default, we don't want to make any assumption about how to roll back a migration when your
41
+ # model already existed. Please edit below which fields you would like to remove in this migration.
42
+ raise ActiveRecord::IrreversibleMigration
43
+ end
44
+ end
@@ -0,0 +1,10 @@
1
+ class CreateUserHasRoles < ActiveRecord::Migration
2
+ def change
3
+ create_table :user_has_roles do |t|
4
+ t.integer :user_id
5
+ t.integer :role_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,116 @@
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 => 20111201163718) do
15
+
16
+ create_table "library_groups", :force => true do |t|
17
+ t.string "name", :null => false
18
+ t.text "display_name"
19
+ t.string "short_name", :null => false
20
+ t.string "email"
21
+ t.text "my_networks"
22
+ t.boolean "use_dsbl", :default => false, :null => false
23
+ t.text "dsbl_list"
24
+ t.text "login_banner"
25
+ t.text "note"
26
+ t.integer "country_id"
27
+ t.datetime "created_at", :null => false
28
+ t.datetime "updated_at", :null => false
29
+ t.string "url", :default => "http://localhost:3000/"
30
+ end
31
+
32
+ add_index "library_groups", ["short_name"], :name => "index_library_groups_on_short_name"
33
+
34
+ create_table "news_feeds", :force => true do |t|
35
+ t.integer "library_group_id", :default => 1, :null => false
36
+ t.string "title"
37
+ t.string "url"
38
+ t.text "body"
39
+ t.integer "position"
40
+ t.datetime "created_at", :null => false
41
+ t.datetime "updated_at", :null => false
42
+ end
43
+
44
+ create_table "news_posts", :force => true do |t|
45
+ t.text "title"
46
+ t.text "body"
47
+ t.integer "user_id"
48
+ t.datetime "start_date"
49
+ t.datetime "end_date"
50
+ t.integer "required_role_id", :default => 1, :null => false
51
+ t.text "note"
52
+ t.integer "position"
53
+ t.boolean "draft", :default => false, :null => false
54
+ t.datetime "created_at", :null => false
55
+ t.datetime "updated_at", :null => false
56
+ t.string "url"
57
+ end
58
+
59
+ add_index "news_posts", ["user_id"], :name => "index_news_posts_on_user_id"
60
+
61
+ create_table "roles", :force => true do |t|
62
+ t.string "name"
63
+ t.text "display_name"
64
+ t.text "note"
65
+ t.integer "position"
66
+ t.datetime "created_at", :null => false
67
+ t.datetime "updated_at", :null => false
68
+ end
69
+
70
+ create_table "user_groups", :force => true do |t|
71
+ t.string "name"
72
+ t.string "string"
73
+ t.text "display_name"
74
+ t.text "note"
75
+ t.integer "position"
76
+ t.datetime "created_at", :null => false
77
+ t.datetime "updated_at", :null => false
78
+ t.datetime "deleted_at"
79
+ t.integer "valid_period_for_new_user", :default => 0, :null => false
80
+ t.datetime "expired_at"
81
+ end
82
+
83
+ create_table "user_has_roles", :force => true do |t|
84
+ t.integer "user_id"
85
+ t.integer "role_id"
86
+ t.datetime "created_at", :null => false
87
+ t.datetime "updated_at", :null => false
88
+ end
89
+
90
+ create_table "users", :force => true do |t|
91
+ t.integer "user_group_id"
92
+ t.integer "required_role_id"
93
+ t.string "username"
94
+ t.text "note"
95
+ t.string "locale"
96
+ t.string "user_number"
97
+ t.integer "library_id"
98
+ t.datetime "locked_at"
99
+ t.datetime "created_at", :null => false
100
+ t.datetime "updated_at", :null => false
101
+ t.string "email", :default => "", :null => false
102
+ t.string "encrypted_password", :default => "", :null => false
103
+ t.string "reset_password_token"
104
+ t.datetime "reset_password_sent_at"
105
+ t.datetime "remember_created_at"
106
+ t.integer "sign_in_count", :default => 0
107
+ t.datetime "current_sign_in_at"
108
+ t.datetime "last_sign_in_at"
109
+ t.string "current_sign_in_ip"
110
+ t.string "last_sign_in_ip"
111
+ end
112
+
113
+ add_index "users", ["email"], :name => "index_users_on_email"
114
+ add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
115
+
116
+ end
@@ -0,0 +1,19 @@
1
+ module MasterModel
2
+ def self.included(base)
3
+ #base.extend ClassMethods
4
+ base.send :include, InstanceMethods
5
+ base.class_eval do
6
+ acts_as_list
7
+ validates_uniqueness_of :name, :case_sensitive => false
8
+ validates_presence_of :name, :display_name
9
+ before_validation :set_display_name, :on => :create
10
+ normalize_attributes :name
11
+ end
12
+ end
13
+
14
+ module InstanceMethods
15
+ def set_display_name
16
+ self.display_name = "#{I18n.locale}: #{self.name}" if self.display_name.blank?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ class UrlValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ url = ::Addressable::URI.parse(value)
4
+ if url
5
+ unless ['http', 'https'].include?(url.scheme)
6
+ record.errors.add(attribute.to_sym)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</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/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</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/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>