acts_as_word_cloud 0.0.1 → 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.
- data/CHANGELOG +5 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +8 -9
- data/README.rdoc +19 -87
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/acts_as_word_cloud.gemspec +13 -18
- data/lib/acts_as_word_cloud/config.rb +6 -2
- data/lib/acts_as_word_cloud/railtie.rb +1 -0
- data/lib/acts_as_word_cloud/word_cloud.rb +108 -188
- data/lib/generators/acts_as_word_cloud/templates/config.rb +9 -4
- data/spec/acts_as_word_cloud_spec.rb +162 -99
- data/spec/dummy/app/models/article.rb +7 -5
- data/spec/dummy/app/models/article_reader.rb +10 -0
- data/spec/dummy/app/models/author.rb +5 -2
- data/spec/dummy/app/models/publisher.rb +5 -4
- data/spec/dummy/app/models/reader.rb +7 -4
- data/spec/dummy/db/migrate/20121107162154_create_system.rb +2 -28
- data/spec/dummy/db/schema.rb +14 -44
- data/spec/integration_spec.rb +123 -0
- data/spec/spec_helper.rb +18 -3
- data/spec/{dummy/features/support → support}/blueprints.rb +6 -21
- metadata +13 -17
- data/features/acts_as_word_cloud.feature +0 -9
- data/features/step_definitions/acts_as_word_cloud_steps.rb +0 -0
- data/features/support/env.rb +0 -13
- data/lib/model_methods_helper.rb +0 -87
- data/spec/dummy/app/models/following.rb +0 -5
- data/spec/dummy/app/models/site.rb +0 -8
- data/spec/dummy/lib/model_methods_helper.rb +0 -87
@@ -1,7 +1,10 @@
|
|
1
1
|
class Author < ActiveRecord::Base
|
2
|
-
acts_as_word_cloud
|
2
|
+
acts_as_word_cloud
|
3
3
|
|
4
4
|
has_many :articles
|
5
5
|
belongs_to :publisher
|
6
|
-
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
"Author #{id}"
|
9
|
+
end
|
7
10
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Publisher < ActiveRecord::Base
|
2
|
-
acts_as_word_cloud :methods_to_use => [:name], :excluded_models => [], :skipped_attributes => [], :depth => 1
|
3
|
-
|
4
|
-
has_one :site
|
5
|
-
has_many :articles
|
6
2
|
has_many :authors
|
3
|
+
has_many :articles, :through => :authors
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
"Publisher #{id}"
|
7
|
+
end
|
7
8
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
class Reader < ActiveRecord::Base
|
2
|
-
acts_as_word_cloud
|
2
|
+
acts_as_word_cloud
|
3
3
|
|
4
|
-
has_many :
|
5
|
-
has_many :articles, :through => :
|
6
|
-
|
4
|
+
has_many :article_readers
|
5
|
+
has_many :articles, :through => :article_readers
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
"Reader #{id}"
|
9
|
+
end
|
7
10
|
end
|
@@ -2,29 +2,19 @@ class CreateSystem < ActiveRecord::Migration
|
|
2
2
|
def change
|
3
3
|
create_table :articles do |t|
|
4
4
|
t.integer :author_id
|
5
|
-
t.integer :publisher_id
|
6
|
-
t.integer :site_id
|
7
5
|
t.string :title
|
8
6
|
t.string :genre
|
9
7
|
t.text :content
|
10
8
|
|
11
9
|
t.timestamps
|
12
10
|
end
|
13
|
-
add_index :articles, :author_id
|
14
|
-
add_index :articles, :publisher_id
|
15
|
-
add_index :articles, :site_id
|
16
11
|
|
17
12
|
create_table :authors do |t|
|
18
13
|
t.integer :publisher_id
|
19
|
-
t.integer :site_id
|
20
14
|
t.string :name
|
21
|
-
t.string :genre
|
22
|
-
t.integer :age
|
23
15
|
|
24
16
|
t.timestamps
|
25
17
|
end
|
26
|
-
add_index :authors, :publisher_id
|
27
|
-
add_index :authors, :site_id
|
28
18
|
|
29
19
|
create_table :publishers do |t|
|
30
20
|
t.string :name
|
@@ -34,31 +24,15 @@ class CreateSystem < ActiveRecord::Migration
|
|
34
24
|
end
|
35
25
|
|
36
26
|
create_table :readers do |t|
|
37
|
-
t.
|
38
|
-
t.string :username
|
27
|
+
t.string :name
|
39
28
|
t.integer :age
|
40
29
|
|
41
30
|
t.timestamps
|
42
31
|
end
|
43
|
-
add_index :readers, :site_id
|
44
32
|
|
45
|
-
create_table :
|
46
|
-
t.string :special_name
|
33
|
+
create_table :article_readers do |t|
|
47
34
|
t.integer :article_id
|
48
35
|
t.integer :reader_id
|
49
36
|
end
|
50
|
-
add_index :followings, :article_id
|
51
|
-
add_index :followings, :reader_id
|
52
|
-
|
53
|
-
create_table :sites do |t|
|
54
|
-
t.integer :publisher_id
|
55
|
-
t.string :name
|
56
|
-
t.string :domain
|
57
|
-
t.string :genre
|
58
|
-
|
59
|
-
t.timestamps
|
60
|
-
end
|
61
|
-
add_index :sites, :publisher_id
|
62
|
-
|
63
37
|
end
|
64
38
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -13,69 +13,39 @@
|
|
13
13
|
|
14
14
|
ActiveRecord::Schema.define(:version => 20121107162154) do
|
15
15
|
|
16
|
+
create_table "article_readers", :force => true do |t|
|
17
|
+
t.integer "article_id"
|
18
|
+
t.integer "reader_id"
|
19
|
+
end
|
20
|
+
|
16
21
|
create_table "articles", :force => true do |t|
|
17
22
|
t.integer "author_id"
|
18
|
-
t.integer "publisher_id"
|
19
|
-
t.integer "site_id"
|
20
23
|
t.string "title"
|
21
24
|
t.string "genre"
|
22
25
|
t.text "content"
|
23
|
-
t.datetime "created_at"
|
24
|
-
t.datetime "updated_at"
|
26
|
+
t.datetime "created_at"
|
27
|
+
t.datetime "updated_at"
|
25
28
|
end
|
26
29
|
|
27
|
-
add_index "articles", ["author_id"], :name => "index_articles_on_author_id"
|
28
|
-
add_index "articles", ["publisher_id"], :name => "index_articles_on_publisher_id"
|
29
|
-
add_index "articles", ["site_id"], :name => "index_articles_on_site_id"
|
30
|
-
|
31
30
|
create_table "authors", :force => true do |t|
|
32
31
|
t.integer "publisher_id"
|
33
|
-
t.integer "site_id"
|
34
32
|
t.string "name"
|
35
|
-
t.
|
36
|
-
t.
|
37
|
-
t.datetime "created_at", :null => false
|
38
|
-
t.datetime "updated_at", :null => false
|
39
|
-
end
|
40
|
-
|
41
|
-
add_index "authors", ["publisher_id"], :name => "index_authors_on_publisher_id"
|
42
|
-
add_index "authors", ["site_id"], :name => "index_authors_on_site_id"
|
43
|
-
|
44
|
-
create_table "followings", :force => true do |t|
|
45
|
-
t.string "special_name"
|
46
|
-
t.integer "article_id"
|
47
|
-
t.integer "reader_id"
|
33
|
+
t.datetime "created_at"
|
34
|
+
t.datetime "updated_at"
|
48
35
|
end
|
49
36
|
|
50
|
-
add_index "followings", ["article_id"], :name => "index_followings_on_article_id"
|
51
|
-
add_index "followings", ["reader_id"], :name => "index_followings_on_reader_id"
|
52
|
-
|
53
37
|
create_table "publishers", :force => true do |t|
|
54
38
|
t.string "name"
|
55
39
|
t.string "location"
|
56
|
-
t.datetime "created_at"
|
57
|
-
t.datetime "updated_at"
|
40
|
+
t.datetime "created_at"
|
41
|
+
t.datetime "updated_at"
|
58
42
|
end
|
59
43
|
|
60
44
|
create_table "readers", :force => true do |t|
|
61
|
-
t.integer "site_id"
|
62
|
-
t.string "username"
|
63
|
-
t.integer "age"
|
64
|
-
t.datetime "created_at", :null => false
|
65
|
-
t.datetime "updated_at", :null => false
|
66
|
-
end
|
67
|
-
|
68
|
-
add_index "readers", ["site_id"], :name => "index_readers_on_site_id"
|
69
|
-
|
70
|
-
create_table "sites", :force => true do |t|
|
71
|
-
t.integer "publisher_id"
|
72
45
|
t.string "name"
|
73
|
-
t.
|
74
|
-
t.
|
75
|
-
t.datetime "
|
76
|
-
t.datetime "updated_at", :null => false
|
46
|
+
t.integer "age"
|
47
|
+
t.datetime "created_at"
|
48
|
+
t.datetime "updated_at"
|
77
49
|
end
|
78
50
|
|
79
|
-
add_index "sites", ["publisher_id"], :name => "index_sites_on_publisher_id"
|
80
|
-
|
81
51
|
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Integration tests" do
|
4
|
+
describe "mixin" do
|
5
|
+
it "should set default values if called with no arguments" do
|
6
|
+
reader = Reader.new
|
7
|
+
reader.word_cloud_attributes[:included_methods].should == []
|
8
|
+
reader.word_cloud_attributes[:excluded_methods].should == []
|
9
|
+
reader.word_cloud_attributes[:excluded_models].should == []
|
10
|
+
reader.word_cloud_attributes[:depth].should == ActsAsWordCloud.config.default_search_depth
|
11
|
+
reader.word_cloud_attributes[:object_name_methods].should == ActsAsWordCloud.config.object_name_methods
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set attributes included in the mixin call" do
|
15
|
+
article = Article.new
|
16
|
+
article.word_cloud_attributes[:included_methods].should == [:truncated_title]
|
17
|
+
article.word_cloud_attributes[:excluded_methods].should == [:genre]
|
18
|
+
article.word_cloud_attributes[:excluded_models].should == [ArticleReader, Reader]
|
19
|
+
article.word_cloud_attributes[:depth].should == 2
|
20
|
+
article.word_cloud_attributes[:object_name_methods].should == [:title]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "included methods" do
|
25
|
+
before(:each) do
|
26
|
+
@publisher = Publisher.make(:name => "Cloudhouse")
|
27
|
+
@author = Author.make(:publisher => @publisher, :name => "Jeremiah Hemphill")
|
28
|
+
@article = Article.make(:author => @author)
|
29
|
+
|
30
|
+
@word_cloud_output = @article.word_cloud(:array)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return database attributes" do
|
34
|
+
expected_word_cloud_output = [
|
35
|
+
@article.title,
|
36
|
+
@article.content
|
37
|
+
]
|
38
|
+
expected_word_cloud_output.each do |str|
|
39
|
+
@word_cloud_output.should include str
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return associated object names" do
|
44
|
+
expected_word_cloud_output = [
|
45
|
+
@author.name,
|
46
|
+
@publisher.name,
|
47
|
+
]
|
48
|
+
expected_word_cloud_output.each do |str|
|
49
|
+
@word_cloud_output.should include str
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return included methods" do
|
54
|
+
expected_word_cloud_output = [
|
55
|
+
@article.truncated_title
|
56
|
+
]
|
57
|
+
expected_word_cloud_output.each do |str|
|
58
|
+
@word_cloud_output.should include str
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "excluded methods" do
|
64
|
+
before(:each) do
|
65
|
+
@article = Article.make
|
66
|
+
@word_cloud_output = @article.word_cloud(:array)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not include database attributes in excluded methods" do
|
70
|
+
@word_cloud_output.should_not include @article.genre
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "excluded_models" do
|
75
|
+
before(:each) do
|
76
|
+
@article = Article.make
|
77
|
+
@reader = Reader.make(:name => "Alfredo Uribe")
|
78
|
+
@article_reader = ArticleReader.make(:article => @article, :reader => @reader)
|
79
|
+
@word_cloud_output = @article.word_cloud(:array)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should not include excluded models with an association to the current model" do
|
83
|
+
@word_cloud_output.should_not include @article_reader.name
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not include children of excluded models if the depth is set to 2" do
|
87
|
+
@word_cloud_output.should_not include @reader.name
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "depth" do
|
92
|
+
before(:each) do
|
93
|
+
@publisher = Publisher.make(:name => "Cloudhouse")
|
94
|
+
@author = Author.make(:publisher => @publisher, :name => "Jeremiah Hemphill")
|
95
|
+
@article = Article.make(:author => @author)
|
96
|
+
@reader = Reader.make(:name => "Alfredo Uribe")
|
97
|
+
@article_reader = ArticleReader.make(:article => @article, :reader => @reader)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return a single level of associations if the depth is set to 1" do
|
101
|
+
@word_cloud_output = @article_reader.word_cloud(:array)
|
102
|
+
|
103
|
+
expected_word_cloud_output = [ @article.title, @reader.name ]
|
104
|
+
expected_word_cloud_output.each { |str| @word_cloud_output.should include str }
|
105
|
+
|
106
|
+
unexpected_word_cloud_output = [ @publisher.name, @author.name ]
|
107
|
+
unexpected_word_cloud_output.each { |str| @word_cloud_output.should_not include str }
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return multiple levels of associations if the depth is set to 2" do
|
112
|
+
@word_cloud_output = @article.word_cloud(:array)
|
113
|
+
|
114
|
+
expected_word_cloud_output = [
|
115
|
+
@author.name,
|
116
|
+
@publisher.name,
|
117
|
+
]
|
118
|
+
expected_word_cloud_output.each do |str|
|
119
|
+
@word_cloud_output.should include str
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,12 +3,14 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
|
4
4
|
ENV["RAILS_ENV"] = 'test'
|
5
5
|
require File.expand_path("../dummy/config/environment", __FILE__)
|
6
|
-
require File.expand_path("../dummy/features/support/blueprints", __FILE__)
|
7
|
-
require File.expand_path("../dummy/lib/model_methods_helper", __FILE__)
|
8
6
|
|
9
|
-
require '
|
7
|
+
# require 'rails/test_help'
|
8
|
+
require 'rspec/rails'
|
10
9
|
require 'acts_as_word_cloud'
|
10
|
+
require 'database_cleaner'
|
11
11
|
|
12
|
+
# Run any available migration
|
13
|
+
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
12
14
|
|
13
15
|
# Requires supporting files with custom matchers and macros, etc,
|
14
16
|
# in ./support/ and its subdirectories.
|
@@ -17,5 +19,18 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
17
19
|
RSpec.configure do |config|
|
18
20
|
|
19
21
|
config.mock_with :rspec
|
22
|
+
|
23
|
+
config.before(:suite) do
|
24
|
+
DatabaseCleaner.strategy = :transaction
|
25
|
+
DatabaseCleaner.clean_with(:truncation)
|
26
|
+
end
|
27
|
+
|
28
|
+
config.before(:each) do
|
29
|
+
DatabaseCleaner.start
|
30
|
+
end
|
31
|
+
|
32
|
+
config.after(:each) do
|
33
|
+
DatabaseCleaner.clean
|
34
|
+
end
|
20
35
|
|
21
36
|
end
|
@@ -14,22 +14,15 @@ def generate_tiny_text
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Article.blueprint do
|
17
|
-
author
|
18
|
-
author_id { author.id }
|
19
|
-
publisher_id { author.publisher.id }
|
20
|
-
site_id { author.site.id }
|
17
|
+
author { Author.make }
|
21
18
|
title { generate_tiny_text }
|
22
19
|
genre { generate_tiny_text }
|
23
20
|
content { generate_text }
|
24
21
|
end
|
25
22
|
|
26
23
|
Author.blueprint do
|
27
|
-
|
28
|
-
site_id { site.id }
|
29
|
-
publisher_id { site.publisher.id }
|
24
|
+
publisher { Publisher.make }
|
30
25
|
name { generate_tiny_text }
|
31
|
-
genre { generate_tiny_text }
|
32
|
-
age { generate_age }
|
33
26
|
end
|
34
27
|
|
35
28
|
Publisher.blueprint do
|
@@ -37,21 +30,13 @@ Publisher.blueprint do
|
|
37
30
|
location { generate_tiny_text }
|
38
31
|
end
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
reader_id { Reader.make }
|
33
|
+
ArticleReader.blueprint do
|
34
|
+
article { Article.make }
|
35
|
+
reader { Reader.make }
|
44
36
|
end
|
45
37
|
|
46
38
|
Reader.blueprint do
|
47
|
-
|
48
|
-
username { generate_tiny_text }
|
39
|
+
name { generate_tiny_text }
|
49
40
|
age { generate_age }
|
50
41
|
end
|
51
42
|
|
52
|
-
Site.blueprint do
|
53
|
-
publisher_id { Publisher.make }
|
54
|
-
name { generate_tiny_text }
|
55
|
-
domain { generate_tiny_text }
|
56
|
-
genre { generate_tiny_text }
|
57
|
-
end
|
metadata
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
name: acts_as_word_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremiah Hemphill
|
9
|
+
- Alfredo Uribe
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date: 2013-02-
|
14
|
+
date: 2013-02-21 00:00:00 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rails
|
@@ -46,24 +47,24 @@ dependencies:
|
|
46
47
|
prerelease: false
|
47
48
|
version_requirements: *id003
|
48
49
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
50
|
+
name: rspec-rails
|
50
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
51
52
|
none: false
|
52
53
|
requirements:
|
53
|
-
- -
|
54
|
+
- - ">="
|
54
55
|
- !ruby/object:Gem::Version
|
55
|
-
version: "
|
56
|
+
version: "0"
|
56
57
|
type: :development
|
57
58
|
prerelease: false
|
58
59
|
version_requirements: *id004
|
59
60
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
61
|
+
name: database_cleaner
|
61
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
62
63
|
none: false
|
63
64
|
requirements:
|
64
|
-
- -
|
65
|
+
- - ~>
|
65
66
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
+
version: 0.6.7
|
67
68
|
type: :development
|
68
69
|
prerelease: false
|
69
70
|
version_requirements: *id005
|
@@ -122,9 +123,6 @@ files:
|
|
122
123
|
- Rakefile
|
123
124
|
- VERSION
|
124
125
|
- acts_as_word_cloud.gemspec
|
125
|
-
- features/acts_as_word_cloud.feature
|
126
|
-
- features/step_definitions/acts_as_word_cloud_steps.rb
|
127
|
-
- features/support/env.rb
|
128
126
|
- lib/acts_as_word_cloud.rb
|
129
127
|
- lib/acts_as_word_cloud/config.rb
|
130
128
|
- lib/acts_as_word_cloud/engine.rb
|
@@ -132,7 +130,6 @@ files:
|
|
132
130
|
- lib/acts_as_word_cloud/word_cloud.rb
|
133
131
|
- lib/generators/acts_as_word_cloud/install_generator.rb
|
134
132
|
- lib/generators/acts_as_word_cloud/templates/config.rb
|
135
|
-
- lib/model_methods_helper.rb
|
136
133
|
- spec/acts_as_word_cloud_spec.rb
|
137
134
|
- spec/dummy/README.rdoc
|
138
135
|
- spec/dummy/Rakefile
|
@@ -143,11 +140,10 @@ files:
|
|
143
140
|
- spec/dummy/app/mailers/.gitkeep
|
144
141
|
- spec/dummy/app/models/.gitkeep
|
145
142
|
- spec/dummy/app/models/article.rb
|
143
|
+
- spec/dummy/app/models/article_reader.rb
|
146
144
|
- spec/dummy/app/models/author.rb
|
147
|
-
- spec/dummy/app/models/following.rb
|
148
145
|
- spec/dummy/app/models/publisher.rb
|
149
146
|
- spec/dummy/app/models/reader.rb
|
150
|
-
- spec/dummy/app/models/site.rb
|
151
147
|
- spec/dummy/app/views/layouts/application.html.erb
|
152
148
|
- spec/dummy/config.ru
|
153
149
|
- spec/dummy/config/application.rb
|
@@ -167,16 +163,16 @@ files:
|
|
167
163
|
- spec/dummy/config/routes.rb
|
168
164
|
- spec/dummy/db/migrate/20121107162154_create_system.rb
|
169
165
|
- spec/dummy/db/schema.rb
|
170
|
-
- spec/dummy/features/support/blueprints.rb
|
171
166
|
- spec/dummy/lib/assets/.gitkeep
|
172
|
-
- spec/dummy/lib/model_methods_helper.rb
|
173
167
|
- spec/dummy/log/.gitkeep
|
174
168
|
- spec/dummy/public/404.html
|
175
169
|
- spec/dummy/public/422.html
|
176
170
|
- spec/dummy/public/500.html
|
177
171
|
- spec/dummy/public/favicon.ico
|
178
172
|
- spec/dummy/script/rails
|
173
|
+
- spec/integration_spec.rb
|
179
174
|
- spec/spec_helper.rb
|
175
|
+
- spec/support/blueprints.rb
|
180
176
|
homepage: http://github.com/jeremiahishere/acts_as_word_cloud
|
181
177
|
licenses:
|
182
178
|
- MIT
|
@@ -190,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
186
|
requirements:
|
191
187
|
- - ">="
|
192
188
|
- !ruby/object:Gem::Version
|
193
|
-
hash:
|
189
|
+
hash: 2660284366431254682
|
194
190
|
segments:
|
195
191
|
- 0
|
196
192
|
version: "0"
|
File without changes
|
data/features/support/env.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
begin
|
3
|
-
Bundler.setup(:default, :development)
|
4
|
-
rescue Bundler::BundlerError => e
|
5
|
-
$stderr.puts e.message
|
6
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
-
exit e.status_code
|
8
|
-
end
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
11
|
-
require 'acts_as_word_cloud'
|
12
|
-
|
13
|
-
require 'rspec/expectations'
|
data/lib/model_methods_helper.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'find'
|
2
|
-
class ModelMethodsHelper
|
3
|
-
|
4
|
-
# finds or makes a model based on the given attributes
|
5
|
-
# @param [Constant] model_name The name of the model
|
6
|
-
# @param [Hash] attributes The attributes to find the model or add to the new one
|
7
|
-
def self.find_or_make_by_attributes(model_name, attributes)
|
8
|
-
instances = model_name.where(attributes)
|
9
|
-
if instances.empty?
|
10
|
-
return model_name.make(attributes)
|
11
|
-
else
|
12
|
-
return instances.first
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Uses the descendants_of method to determine the model structure
|
17
|
-
# Then tableizes and converts to symbol
|
18
|
-
#
|
19
|
-
# Load all models must be run for accurate descendants list
|
20
|
-
# it is now being called every time this method is called
|
21
|
-
# for now it works because this is only called one time when the authorization config is loaded on initialize
|
22
|
-
# if this ever changes, this code may need to be update (2-15-2012)
|
23
|
-
#
|
24
|
-
# @return [Array] Array with file names underscored and pluralized in the format [:users, :case_placements, :roles, :job_locations, ... ]
|
25
|
-
def self.get_model_symbol_array
|
26
|
-
# Old method:
|
27
|
-
# Major redesign of this method that finds namespaced models
|
28
|
-
# Finds all files in the given folder, tries to find the ruby files
|
29
|
-
# Then processes the names to get the names we need for the code
|
30
|
-
#
|
31
|
-
# @return [Array] Array with file names underscored and pluralized in the format [:users, :case_placements, :roles, :job_locations, ... ]
|
32
|
-
#model_array = []
|
33
|
-
#Find.find("#{Rails.root.to_s}/app/models") do |model_path|
|
34
|
-
# if model_path.match(/\.rb$/)
|
35
|
-
# model_path = model_path.gsub("#{Rails.root.to_s}/app/models/", "")
|
36
|
-
# model_path = model_path.gsub("/","_")
|
37
|
-
# model_path = model_path.gsub(/\.rb$/, "")
|
38
|
-
# model_array.push model_path.pluralize.to_sym
|
39
|
-
# end
|
40
|
-
#end
|
41
|
-
#return model_array
|
42
|
-
|
43
|
-
# new method
|
44
|
-
self.load_all_models
|
45
|
-
# returns the table name if there is one or tableizes the model name if not
|
46
|
-
# our permissions system generally uses table names for model permissions
|
47
|
-
return self.descendants_of(ActiveRecord::Base).map{ |m| m.abstract_class ? m.to_s.tableize.to_sym : m.table_name.to_sym }
|
48
|
-
end
|
49
|
-
|
50
|
-
# Requires all models so that they are visible in the object space
|
51
|
-
# This is only necessary when we are not caching classes
|
52
|
-
def self.load_all_models
|
53
|
-
if !::Rails.application.config.cache_classes
|
54
|
-
Dir[Rails.root.join("app/models/**/*.rb")].each {|f| require f}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Return a list of descendants of the given model.
|
59
|
-
#
|
60
|
-
# If direct is set to true, only return immediate descendants
|
61
|
-
# The load_all_models must be called before this is called or the result may not be correct
|
62
|
-
#
|
63
|
-
# @param [Constant] parent_class The parent class to look for descendants for
|
64
|
-
# @param [Boolean] direct Whether to look for all descendants or immediate descendants
|
65
|
-
# @return [Array] An array of class constants that satisfy the conditions of the parameters
|
66
|
-
def self.descendants_of(parent_class, direct = false)
|
67
|
-
classes = []
|
68
|
-
ObjectSpace.each_object(::Class).each do |klass|
|
69
|
-
if direct
|
70
|
-
classes << klass if klass.superclass == parent_class
|
71
|
-
else
|
72
|
-
classes << klass if klass < parent_class
|
73
|
-
end
|
74
|
-
end
|
75
|
-
return classes
|
76
|
-
end
|
77
|
-
|
78
|
-
# Convenience method to return the results of descendants_of with direct set to true
|
79
|
-
#
|
80
|
-
# The load_all_models must be called before this is called or the result may not be correct
|
81
|
-
#
|
82
|
-
# @param [Constant] parent_class The parent class to look for descendants for
|
83
|
-
# @return [Array] An array of class constants that satisfy the conditions of the parameters
|
84
|
-
def self.direct_descendants_of(parent_class)
|
85
|
-
return self.descendants_of(parent_class, true)
|
86
|
-
end
|
87
|
-
end
|