acts_as_featureable 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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +83 -9
  5. data/Rakefile +20 -3
  6. data/acts_as_featureable.gemspec +20 -20
  7. data/app/controllers/.keep +0 -0
  8. data/app/controllers/features_controller.rb +90 -0
  9. data/app/helpers/.keep +0 -0
  10. data/app/helpers/features_helper.rb +9 -0
  11. data/app/models/.keep +0 -0
  12. data/{lib/acts_as_featureable → app/models}/feature.rb +17 -3
  13. data/app/views/.keep +0 -0
  14. data/app/views/features/_feature.html.erb +5 -0
  15. data/app/views/features/_features.html.erb +3 -0
  16. data/app/views/features/_form.html.erb +19 -0
  17. data/app/views/features/edit.html.erb +1 -0
  18. data/app/views/features/index.html.erb +3 -0
  19. data/app/views/features/new.html.erb +1 -0
  20. data/app/views/features/show.html.erb +1 -0
  21. data/bin/rails +8 -0
  22. data/lib/acts_as_featureable/config.rb +30 -0
  23. data/lib/acts_as_featureable/engine.rb +9 -0
  24. data/lib/acts_as_featureable/feature_methods.rb +11 -0
  25. data/lib/acts_as_featureable/version.rb +1 -1
  26. data/lib/acts_as_featureable.rb +5 -19
  27. data/lib/generators/templates/create_features.rb +1 -0
  28. data/lib/generators/templates/initializer.rb +5 -0
  29. data/spec/controllers/features_controller_spec.rb +158 -0
  30. data/spec/dummy/README.rdoc +28 -0
  31. data/spec/dummy/Rakefile +6 -0
  32. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  34. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  35. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  37. data/spec/dummy/app/mailers/.keep +0 -0
  38. data/spec/dummy/app/models/.keep +0 -0
  39. data/spec/dummy/app/models/concerns/.keep +0 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/bin/bundle +3 -0
  42. data/spec/dummy/bin/rails +4 -0
  43. data/spec/dummy/bin/rake +4 -0
  44. data/spec/dummy/config/application.rb +23 -0
  45. data/spec/dummy/config/boot.rb +5 -0
  46. data/spec/dummy/config/database.yml +25 -0
  47. data/spec/dummy/config/environment.rb +5 -0
  48. data/spec/dummy/config/environments/development.rb +29 -0
  49. data/spec/dummy/config/environments/production.rb +80 -0
  50. data/spec/dummy/config/environments/test.rb +36 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  53. data/spec/dummy/config/initializers/inflections.rb +16 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  56. data/spec/dummy/config/initializers/session_store.rb +3 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +23 -0
  59. data/spec/dummy/config/routes.rb +5 -0
  60. data/spec/dummy/config.ru +4 -0
  61. data/spec/dummy/lib/assets/.keep +0 -0
  62. data/spec/dummy/log/.keep +0 -0
  63. data/spec/dummy/log/test.log +34618 -0
  64. data/spec/dummy/public/404.html +58 -0
  65. data/spec/dummy/public/422.html +58 -0
  66. data/spec/dummy/public/500.html +57 -0
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/extra/schema.rb +1 -0
  69. data/spec/factories/topics.rb +6 -0
  70. data/spec/helpers/features_helper_spec.rb +24 -0
  71. data/spec/models/feature_spec.rb +131 -0
  72. data/spec/spec_helper.rb +17 -2
  73. metadata +136 -58
  74. data/spec/feature_spec.rb +0 -71
  75. /data/spec/{featureable_spec.rb → models/featureable_spec.rb} +0 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
data/spec/extra/schema.rb CHANGED
@@ -4,6 +4,7 @@ ActiveRecord::Schema.define :version => 0 do
4
4
  t.string :title
5
5
  t.text :summary
6
6
  t.integer :position, :null => false
7
+ t.string :category
7
8
  t.timestamps
8
9
  end
9
10
 
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :topic do
3
+ title "Title"
4
+ summary "Summary"
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe FeaturesHelper do
4
+ before :each do
5
+ @topic = Topic.create!
6
+ end
7
+
8
+ describe "features_form_for" do
9
+ it "should render the form for a new feature" do
10
+ helper.feature_form_for(@topic).should =~ /id="new_feature"/
11
+ end
12
+ end
13
+
14
+ describe "features_for" do
15
+ it "should be empty if there are no features for the featureable" do
16
+ helper.features_for(@topic).should be_blank
17
+ end
18
+
19
+ it "should render a list of features" do
20
+ @topic.features.create!
21
+ helper.features_for(@topic).should =~ /class="feature"/
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Feature do
4
+ before :each do
5
+ Feature.delete_all
6
+ @topic = Topic.create!
7
+ end
8
+
9
+ subject { @topic.features.create! }
10
+
11
+ it { should be_valid }
12
+ it { should belong_to :featureable }
13
+ it { should validate_numericality_of :position }
14
+ it { should validate_presence_of :featureable_id }
15
+ it { should validate_presence_of :featureable_type }
16
+
17
+ ## ENSURE CATEGORIES ##
18
+ it "should allow any categories by default" do
19
+ @topic.features.create!(category: 'anything').errors.count.should eql 0
20
+ end
21
+
22
+ describe "with category limits" do
23
+ before :each do
24
+ ActsAsFeatureable.categories = [:default]
25
+ end
26
+
27
+ it "should allow a category that is in the list" do
28
+ @topic.features.create(category: :default).errors.count.should eq 0
29
+ end
30
+
31
+ it "should not allow a category that is not in the list" do
32
+ feature = @topic.features.create(category: :foo)
33
+
34
+ feature.errors.count.should eq 1
35
+ feature.errors.messages.keys.should include(:category)
36
+ end
37
+
38
+ ## CREATE SCOPES ##
39
+ it "should create scopes for the default categories" do
40
+ Feature.default
41
+ end
42
+
43
+ it "should return all the features of the scope for the deafult categories" do
44
+ @topic.features.create!(category: :default)
45
+
46
+ Feature.default.size.should eq 1
47
+ end
48
+ end
49
+
50
+ ## LIMIT VALIDATION ##
51
+ it "should only allow the default number of features to be made" do
52
+ limit = ActsAsFeatureable.feature_limit
53
+
54
+ # Create the limit of features
55
+ limit.times do
56
+ @topic.features.create!
57
+ end
58
+
59
+ # Attempt to create an additional feature
60
+ expect { @topic.features.create! }.to raise_error ActiveRecord::RecordInvalid
61
+ end
62
+
63
+ describe "with category limits" do
64
+ before :each do
65
+ ActsAsFeatureable.categories = [:one, :two]
66
+
67
+ limit = ActsAsFeatureable.feature_limit
68
+
69
+ # Create the limit of features
70
+ limit.times do
71
+ @topic.features.create!(category: :one)
72
+ end
73
+ end
74
+
75
+ it "should only allow the default number of features per category to be made" do
76
+ # Attempt to create an additional feature
77
+ expect { @topic.features.create!(category: :one) }.to raise_error ActiveRecord::RecordInvalid
78
+ end
79
+
80
+ it "should allow more features to be made of other categories when one is full" do
81
+ expect { @topic.features.create!(category: :two) }.to_not raise_error ActiveRecord::RecordInvalid
82
+ end
83
+ end
84
+
85
+ ## TITLE ##
86
+ describe "with featureable" do
87
+ before :each do
88
+ @topic = Topic.create!(:title => 'Title')
89
+ end
90
+
91
+ it "should assign associated model's title" do
92
+ feature = @topic.features.create!(:featureable => @topic)
93
+
94
+ feature.title.should eql @topic.title
95
+ end
96
+
97
+ it "should overwrite associated model's title" do
98
+ feature = @topic.features.create!(:featureable => @topic, :title => 'New Title')
99
+
100
+ feature.title.should eql 'New Title'
101
+ end
102
+
103
+ ## SUMMARY ##
104
+ it "should assign associated model's summary" do
105
+ feature = @topic.features.create!(:featureable => @topic)
106
+
107
+ feature.summary.should eql @topic.summary
108
+ end
109
+
110
+ it "should overwrite associated model's summary" do
111
+ feature = @topic.features.create!(:featureable => @topic, :summary => 'New Summary')
112
+
113
+ feature.summary.should eql 'New Summary'
114
+ end
115
+ end
116
+
117
+ ## POSITION ##
118
+ it "should assign a default position" do
119
+ subject.position.should_not be_nil
120
+ end
121
+
122
+ it "should assign a default position of 1 if there are none existing" do
123
+ subject.position.should eql 1
124
+ end
125
+
126
+ it "should assign the next position in line if it already exists" do
127
+ subject
128
+ @topic.features.create!(:position => 1).position.should eql 2
129
+ end
130
+ end
131
+
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,21 @@
1
- require 'active_record'
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
2
6
  require 'shoulda-matchers'
3
- require 'acts_as_featureable'
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rspec
15
+ config.use_transactional_fixtures = true
16
+ config.infer_base_class_for_anonymous_controllers = false
17
+ config.order = "random"
18
+ end
4
19
 
5
20
  ActiveRecord::Base.establish_connection(
6
21
  :adapter => "sqlite3",