solarsearch 0.0.6

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 (70) hide show
  1. data/.gitignore +23 -0
  2. data/.specification +294 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +76 -0
  6. data/Solarsearch.gemspec +176 -0
  7. data/VERSION +1 -0
  8. data/app/controllers/article_controller.rb +30 -0
  9. data/app/controllers/article_statuses_controller.rb +12 -0
  10. data/app/controllers/infosources_controller.rb +143 -0
  11. data/app/controllers/search_keywords_controller.rb +99 -0
  12. data/app/controllers/user_sessions_controller.rb +48 -0
  13. data/app/controllers/users_controller.rb +62 -0
  14. data/app/helpers/article_helper.rb +25 -0
  15. data/app/helpers/article_statuses_helper.rb +2 -0
  16. data/app/helpers/infosources_helper.rb +2 -0
  17. data/app/helpers/layout_helper.rb +22 -0
  18. data/app/helpers/search_keywords_helper.rb +2 -0
  19. data/app/helpers/site_helper.rb +2 -0
  20. data/app/helpers/user_sessions_helper.rb +2 -0
  21. data/app/helpers/users_helper.rb +2 -0
  22. data/app/models/article.rb +74 -0
  23. data/app/models/article_status.rb +20 -0
  24. data/app/models/infosource.rb +83 -0
  25. data/app/models/role.rb +2 -0
  26. data/app/models/roles_users.rb +2 -0
  27. data/app/models/search_keyword.rb +14 -0
  28. data/app/models/user.rb +132 -0
  29. data/app/models/user_mailer.rb +12 -0
  30. data/app/models/user_session.rb +2 -0
  31. data/config/locales/hu.yml +111 -0
  32. data/config/locales/sk.yml +111 -0
  33. data/init.rb +1 -0
  34. data/install.rb +1 -0
  35. data/lib/solarsearch.rb +9 -0
  36. data/lib/solarsearch/locales.rb +3 -0
  37. data/lib/solarsearch/routing.rb +31 -0
  38. data/rails/init.rb +1 -0
  39. data/solarsearch.gemspec +178 -0
  40. data/tasks/solarsearch_tasks.rake +4 -0
  41. data/test/blueprints.rb +34 -0
  42. data/test/blueprints/articles.rb +37 -0
  43. data/test/blueprints/infosources.rb +53 -0
  44. data/test/blueprints/infosources_files/pretty.html +17 -0
  45. data/test/blueprints/infosources_files/ugly.html +399 -0
  46. data/test/blueprints/search_keywords.rb +13 -0
  47. data/test/blueprints/users.rb +17 -0
  48. data/test/content_scrapper.rb +13 -0
  49. data/test/database.yml +7 -0
  50. data/test/functional/article_controller_test.rb +40 -0
  51. data/test/functional/email_controller_test.rb +9 -0
  52. data/test/functional/infosources_controller_test.rb +65 -0
  53. data/test/functional/restricted_logged_exceptions_controller_test.rb +38 -0
  54. data/test/functional/search_keywords_controller_test.rb +108 -0
  55. data/test/functional/user_sessions_controller_test.rb +39 -0
  56. data/test/functional/users_controller_test.rb +109 -0
  57. data/test/schema.rb +92 -0
  58. data/test/test_helper.rb +48 -0
  59. data/test/unit/article_test.rb +56 -0
  60. data/test/unit/helpers/article_helper_test.rb +20 -0
  61. data/test/unit/helpers/email_helper_test.rb +4 -0
  62. data/test/unit/helpers/user_sessions_helper_test.rb +4 -0
  63. data/test/unit/helpers/users_helper_test.rb +4 -0
  64. data/test/unit/infosource_test.rb +132 -0
  65. data/test/unit/role_test.rb +6 -0
  66. data/test/unit/roles_users_test.rb +6 -0
  67. data/test/unit/user_mailer_test.rb +24 -0
  68. data/test/unit/user_test.rb +103 -0
  69. data/uninstall.rb +1 -0
  70. metadata +297 -0
@@ -0,0 +1,7 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :database: vendor/plugins/solarsearch/test/solarsearch_plugin.sqlite.db
4
+
5
+ sqlite3:
6
+ :adapter: sqlite3
7
+ :database: vendor/plugins/solarsearch/test/solarsearch_plugin.sqlite3.db
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class ArticleControllerTest < ActionController::TestCase
4
+
5
+ context "for logged in user" do
6
+
7
+ setup do
8
+ activate_authlogic
9
+ UserSession.create(@user = User.make)
10
+ end
11
+
12
+ context "on GET to show" do
13
+ setup { get :show, :id => Article.make }
14
+ should_respond_with :success
15
+ should "have article value set" do
16
+ assert_not_nil assigns(:article)
17
+ end
18
+ should_render_template :show
19
+ end
20
+
21
+ context "on GET to search" do
22
+ setup do
23
+ Sunspot.remove_all!
24
+ 2.times { Article.make }
25
+ (Article::per_page + 1).times { Article.make(:accent_in_body) }
26
+ Sunspot.commit
27
+ get :search, :q => Sham.accented_word
28
+ end
29
+ should_respond_with :success
30
+ should "have articles value set" do
31
+ articles = assigns(:articles)
32
+ assert_not_nil assigns(:articles)
33
+ assert_equal 1, articles.current_page
34
+ assert_equal Article::per_page + 1, articles.total_entries
35
+ end
36
+ should_render_template :search
37
+ end
38
+ #TODO should be tested for cases when the user is not logged in
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class EmailControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ #FIXME test for email are missing
6
+ test "the truth" do
7
+ assert true
8
+ end
9
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ class InfosourcesControllerTest < ActionController::TestCase
4
+
5
+ context "for logged in user" do
6
+
7
+ setup do
8
+ activate_authlogic
9
+ @user = User.make
10
+ @user.has_role!(:admin)
11
+ UserSession.create(@user)
12
+ end
13
+
14
+ context "on GET to index" do
15
+ setup { get :index }
16
+ should_respond_with :success
17
+ should "have infosources set" do
18
+ assert_not_nil assigns(:infosources)
19
+ end
20
+ should_render_template :index
21
+ end
22
+
23
+ context "on GET to new" do
24
+ setup { get :new }
25
+ should_respond_with :success
26
+ should_render_template :new
27
+ end
28
+
29
+ context "on POST to create" do
30
+ setup { post :create, :infosource => Infosource.plan }
31
+ should_change('the number of infosources', :by => 1) { Infosource.count }
32
+ should_redirect_to("the newly created infosource") { infosource_path(assigns(:infosource)) }
33
+ end
34
+
35
+ context "on POST to create invalid infosource" do
36
+ setup { post :create, :infosource => Infosource.plan(
37
+ :sourcename => 'x' * (Infosource::MIN_SOURCENAME_SIZE-1))}
38
+ should_not_change('the number of infosources') { Infosource.count }
39
+ should_render_template :new
40
+ end
41
+
42
+ context "on GET to show" do
43
+ setup { get :show, :id => Infosource.make }
44
+ should_respond_with :success
45
+ end
46
+
47
+ context "on GET to edit" do
48
+ setup { get :edit, :id => Infosource.make }
49
+ should_respond_with :success
50
+ end
51
+
52
+ context "on PUT to update" do
53
+ setup { put :update, :id => Infosource.make, :infosource => Infosource.plan }
54
+ should_redirect_to("the updated infosource") { infosource_path(assigns(:infosource)) }
55
+ end
56
+
57
+ context "on DELETE after destroy action" do
58
+ setup { delete :destroy, :id => (@infosource = Infosource.make) }
59
+ should "not find the destroyed infosource" do
60
+ assert !Infosource.exists?(@infosource)
61
+ end
62
+ should_redirect_to("the list of infosources") { infosources_path }
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,38 @@
1
+
2
+ require 'test_helper'
3
+
4
+ class LoggedExceptionsControllerTest < ActionController::TestCase
5
+
6
+ #FIXME test the tests for the LoggedExceptionsControlledTest
7
+ =begin
8
+ context "for not-admin user" do
9
+
10
+ setup do
11
+ activate_authlogic
12
+ UserSession.create(@user = User.make)
13
+ end
14
+
15
+ context "to show logged exception" do
16
+ setup { get :index }
17
+ should_respond_with :redirect
18
+ should_redirect_to('the default page') { root_url }
19
+ #should_set_the_flash_to /prístup/
20
+ end
21
+ end
22
+ =end
23
+ context "for admin user" do
24
+
25
+ setup do
26
+ activate_authlogic
27
+ @user = User.make
28
+ @user.has_role!(:admin)
29
+ UserSession.create(@user)
30
+ end
31
+
32
+ context "to show logged exception" do
33
+ setup { get :index }
34
+ should_respond_with :success
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,108 @@
1
+ require 'test_helper'
2
+
3
+ class SearchKeywordsControllerTest < ActionController::TestCase
4
+
5
+ context "authenticated" do
6
+
7
+ setup do
8
+ activate_authlogic
9
+ @user = User.make
10
+ @user_searchkeyword = SearchKeyword.make(:user => @user)
11
+ end
12
+
13
+ context "with non-admin access" do
14
+
15
+ setup { UserSession.create(@user) }
16
+
17
+ context "on GET to index action" do
18
+ setup { get :index }
19
+ should_render_template :index
20
+ should("render the search keywords") do
21
+ assert_match(@user_searchkeyword.query, @response.body)
22
+ end
23
+ should_not_set_the_flash
24
+ end
25
+
26
+ context "on unathorized GET to index action for a different user" do
27
+ setup { get :index, :user_id => User.make.username }
28
+ should("render the search keywords of the logged in user") do
29
+ assert_match(@user_searchkeyword.query, @response.body)
30
+ end
31
+ should_set_the_flash_to I18n.t(:access_denied_flash)
32
+ end
33
+
34
+ context "on GET to new action" do
35
+ setup { get :new }
36
+ should_render_template :new
37
+ end
38
+
39
+ context "on POST to valid search keyword creation should redirect to show keywords view" do
40
+ setup { post :create, :search_keyword => @search_keyword = SearchKeyword.plan }
41
+ should_redirect_to("the created search keyword show view") { search_keyword_url(assigns(:search_keyword)) }
42
+ should "the created search keyword exist" do
43
+ assert_not_nil SearchKeyword.find_by_query(@search_keyword[:query])
44
+ end
45
+ end
46
+
47
+ context "on POST to create action with invalid inputs" do
48
+ setup { post :create, :search_keyword => SearchKeyword.plan(:query => '') }
49
+ should_render_template :new
50
+ end
51
+
52
+ context "for an existing search keyword" do
53
+ setup { @search_keyword = SearchKeyword.make(:user => @user) }
54
+
55
+ context "on GET to edit action" do
56
+ setup { get :edit, :id => @search_keyword }
57
+ should_render_template :edit
58
+ end
59
+
60
+ context "on PUT to update action when model is valid" do
61
+ setup {
62
+ put :update, :id => @search_keyword.id,
63
+ :search_keyword => @search_keyword.attributes.merge('query' => (@new_query = Sham.query) ) }
64
+ should_redirect_to("search keywords show view") { search_keyword_url(assigns(:search_keyword)) }
65
+ should "the changed keyword become changed" do
66
+ assert_equal @new_query, SearchKeyword.find(@search_keyword).query
67
+ end
68
+ end
69
+
70
+ context "on PUT to update action when model is invalid" do
71
+ setup { put :update, :id => @search_keyword.id,
72
+ :search_keyword => @search_keyword.attributes.merge('query' => '') }
73
+ should_render_template :edit
74
+ end
75
+
76
+ context "on GET to show action" do
77
+ setup { get :show, :id => @search_keyword }
78
+ should_render_template :show
79
+ end
80
+
81
+ context "on DELETE to destroy action" do
82
+ setup { delete :destroy, :id => @search_keyword }
83
+ should_redirect_to("keywords index page") { search_keywords_url }
84
+ should "the deleted search keyword by removed from the database" do
85
+ assert !SearchKeyword.exists?(@search_keyword.id)
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ context "with administrative access" do
92
+ setup do
93
+ @adminuser = User.make
94
+ @adminuser.has_role!(:admin)
95
+ UserSession.create(@adminuser)
96
+ end
97
+
98
+ context "on GET to show action for any user" do
99
+ setup { get :index, :user_id => @user.username }
100
+ should "see the other user's search keyword listed" do
101
+ assert_match(@user_searchkeyword.query, @response.body)
102
+ end
103
+ end
104
+ end
105
+
106
+ #FIXME tests for unauthorized access should follow
107
+ end
108
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class UserSessionsControllerTest < ActionController::TestCase
4
+ context "on GET for login screen" do
5
+ setup do
6
+ get :new
7
+ end
8
+ should_render_template :new
9
+ end
10
+
11
+ context "authentication" do
12
+
13
+ setup do
14
+ activate_authlogic
15
+ @user = User.make
16
+ end
17
+
18
+ context "on GET for login by username" do
19
+ setup do
20
+ get :create, :user_session => { :username => @user.username, :password => @user.password }
21
+ end
22
+ should_set_the_flash_to I18n.t(:login_successful_flash)
23
+ end
24
+
25
+ context "on GET for login by email address" do
26
+ setup do
27
+ get :create, :user_session => { :username => @user.email, :password => @user.password }
28
+ end
29
+ should_set_the_flash_to I18n.t(:login_successful_flash)
30
+ end
31
+
32
+ context "on GET for login by email address not responding to any user" do
33
+ setup do
34
+ get :create, :user_session => { :username => @user.email, :password => '@@' }
35
+ end
36
+ should_render_template :new
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class UsersControllerTest < ActionController::TestCase
4
+
5
+ #TODO I dont trust to this get, put way of testing, should use webrat or alike instead OR UNDERSTAND how get,put, post work!!
6
+ #TODO find out how to ask for can_do_somebody_somethigs with acl9 or anything else
7
+
8
+ =begin
9
+ context "on GET for user registration" do
10
+ setup { get :create, :user => User.plan }
11
+ should_set_the_flash_to I18n.t(:login_please_flash)
12
+ end
13
+
14
+ context "on GET for user edition" do
15
+ setup { get :edit, :id => User.make.username }
16
+ should_set_the_flash_to I18n.t(:login_please_flash)
17
+ end
18
+
19
+ context "authorization" do
20
+ setup do
21
+ activate_authlogic
22
+ @users = Array.new
23
+ (0..1).each { |i| @users[i] = User.make }
24
+ end
25
+
26
+ context "for admin" do
27
+ setup do
28
+ @adminuser = User.make
29
+ @adminuser.has_role!(:admin)
30
+ UserSession.create(@adminuser)
31
+ end
32
+
33
+ context "on GET action for listing the existing users" do
34
+ setup { get :index }
35
+ should "list users" do
36
+ assert_match(@users[0].username, @response.body)
37
+ end
38
+ should_not_set_the_flash
39
+ end
40
+
41
+ context "on GET action for editing other users" do
42
+ setup { get :edit, :id => @users[0].username }
43
+ should_not_set_the_flash
44
+ should "show form for the user" do
45
+ assert_match(@users[0].username, @response.body)
46
+ end
47
+ end
48
+
49
+ context "on PUT action for updating other users" do
50
+ setup do
51
+ put :update, 'id' => { :email => (@changed_email = Sham.email)}
52
+ end
53
+ should_set_the_flash_to I18n.t(:profil_change_success_flash)
54
+ should "change the user attributes" do
55
+ changed_user = User.find_by_username(@users[0].username)
56
+ assert_equal(@changed_email, changed_user.email )
57
+ end
58
+ end
59
+
60
+ context "on GET for user registration" do
61
+ setup { get :create, :user => (@user_plan = User.plan) }
62
+ should_set_the_flash_to I18n.t(:registration_successful_flash)
63
+ should 'have created the new user' do
64
+ assert_not_nil User.find_by_username(@user_plan[:username])
65
+ end
66
+ end
67
+ end
68
+
69
+ context "for non-admin" do
70
+ setup do
71
+ UserSession.create(@users[0])
72
+ end
73
+
74
+ context "on GET action for listing the existing users" do
75
+ setup { get :index }
76
+ should_set_the_flash_to I18n.t(:access_denied_flash)
77
+ end
78
+
79
+ context "on GET action for editing other user" do
80
+ setup { get :edit, :id => @users[1].username }
81
+ should_set_the_flash_to I18n.t(:access_denied_flash)
82
+ should "show form for the logged in user" do
83
+ assert_match(@users[0].username, @response.body)
84
+ assert_no_match(Regexp.new(@users[1].username), @response.body)
85
+ end
86
+ end
87
+
88
+ context "on PUT action for updating other users" do
89
+ setup { put :update,
90
+ :user => @users[1].attributes.merge('email' => (@changed_email = Sham.email)) }
91
+ should_set_the_flash_to I18n.t(:access_denied_flash)
92
+ should "not change the user attributes" do
93
+ changed_user = User.find_by_username(@users[1].username)
94
+ assert_not_equal(@changed_email, changed_user.email )
95
+ end
96
+ end
97
+
98
+ context "on PUT action for updating the own profile" do
99
+ setup { put :update,
100
+ 'id' => @users[0].attributes.merge('email' => (@changed_email = Sham.email)) }
101
+ should_set_the_flash_to I18n.t(:profil_change_success_flash)
102
+ should "change the user's own attributes" do
103
+ assert_equal(@changed_email, User.find(@users[0].id).email )
104
+ end
105
+ end
106
+ end
107
+ end
108
+ =end
109
+ end
@@ -0,0 +1,92 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of Active Record to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 20091127111337) do
13
+
14
+ create_table "article_statuses", :force => true do |t|
15
+ t.integer "article_id"
16
+ t.integer "user_id"
17
+ t.integer "status"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "articles", :force => true do |t|
23
+ t.integer "infosource_id"
24
+ t.string "author"
25
+ t.text "title"
26
+ t.text "summary"
27
+ t.text "body"
28
+ t.string "url"
29
+ t.date "published_at"
30
+ t.string "guid"
31
+ t.datetime "created_at"
32
+ t.datetime "updated_at"
33
+ end
34
+
35
+ create_table "infosources", :force => true do |t|
36
+ t.string "sourcename"
37
+ t.string "sourcefeed"
38
+ t.datetime "created_at"
39
+ t.datetime "updated_at"
40
+ end
41
+
42
+ create_table "logged_exceptions", :force => true do |t|
43
+ t.string "exception_class"
44
+ t.string "controller_name"
45
+ t.string "action_name"
46
+ t.text "message"
47
+ t.text "backtrace"
48
+ t.text "environment"
49
+ t.text "request"
50
+ t.datetime "created_at"
51
+ end
52
+
53
+ create_table "roles", :force => true do |t|
54
+ t.string "name", :limit => 40
55
+ t.string "authorizable_type", :limit => 40
56
+ t.integer "authorizable_id"
57
+ t.datetime "created_at"
58
+ t.datetime "updated_at"
59
+ end
60
+
61
+ add_index "roles", ["authorizable_id"], :name => "index_roles_on_authorizable_id"
62
+ add_index "roles", ["authorizable_type"], :name => "index_roles_on_authorizable_type"
63
+ add_index "roles", ["name", "authorizable_id", "authorizable_type"], :name => "index_roles_on_name_and_authorizable_id_and_authorizable_type", :unique => true
64
+ add_index "roles", ["name"], :name => "index_roles_on_name"
65
+
66
+ create_table "roles_users", :id => false, :force => true do |t|
67
+ t.integer "user_id"
68
+ t.integer "role_id"
69
+ t.datetime "created_at"
70
+ t.datetime "updated_at"
71
+ end
72
+
73
+ add_index "roles_users", ["role_id"], :name => "index_roles_users_on_role_id"
74
+ add_index "roles_users", ["user_id", "role_id"], :name => "index_roles_users_on_user_id_and_role_id", :unique => true
75
+ add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
76
+
77
+ create_table "search_keywords", :force => true do |t|
78
+ t.integer "user_id"
79
+ t.string "query"
80
+ t.datetime "created_at"
81
+ t.datetime "updated_at"
82
+ end
83
+
84
+ create_table "users", :force => true do |t|
85
+ t.string "username"
86
+ t.string "email"
87
+ t.string "crypted_password"
88
+ t.string "password_salt"
89
+ t.string "persistence_token"
90
+ end
91
+
92
+ end