draper 1.0.0.beta6 → 1.0.0

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 (59) hide show
  1. data/.travis.yml +6 -0
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +20 -0
  4. data/Gemfile +11 -0
  5. data/README.md +14 -17
  6. data/Rakefile +5 -3
  7. data/draper.gemspec +2 -2
  8. data/lib/draper.rb +2 -1
  9. data/lib/draper/automatic_delegation.rb +50 -0
  10. data/lib/draper/collection_decorator.rb +26 -7
  11. data/lib/draper/decoratable.rb +71 -32
  12. data/lib/draper/decorated_association.rb +11 -7
  13. data/lib/draper/decorator.rb +114 -148
  14. data/lib/draper/delegation.rb +13 -0
  15. data/lib/draper/finders.rb +9 -6
  16. data/lib/draper/helper_proxy.rb +4 -3
  17. data/lib/draper/lazy_helpers.rb +10 -6
  18. data/lib/draper/railtie.rb +5 -4
  19. data/lib/draper/tasks/test.rake +22 -0
  20. data/lib/draper/test/devise_helper.rb +34 -0
  21. data/lib/draper/test/minitest_integration.rb +2 -3
  22. data/lib/draper/test/rspec_integration.rb +4 -59
  23. data/lib/draper/test_case.rb +33 -0
  24. data/lib/draper/version.rb +1 -1
  25. data/lib/draper/view_helpers.rb +4 -3
  26. data/lib/generators/decorator/templates/decorator.rb +7 -25
  27. data/lib/generators/mini_test/decorator_generator.rb +20 -0
  28. data/lib/generators/mini_test/templates/decorator_spec.rb +4 -0
  29. data/lib/generators/mini_test/templates/decorator_test.rb +4 -0
  30. data/lib/generators/test_unit/templates/decorator_test.rb +1 -1
  31. data/spec/draper/collection_decorator_spec.rb +25 -3
  32. data/spec/draper/decorated_association_spec.rb +18 -7
  33. data/spec/draper/decorator_spec.rb +125 -165
  34. data/spec/draper/finders_spec.rb +0 -13
  35. data/spec/dummy/app/controllers/localized_urls.rb +1 -1
  36. data/spec/dummy/app/controllers/posts_controller.rb +3 -9
  37. data/spec/dummy/app/decorators/post_decorator.rb +4 -1
  38. data/spec/dummy/config/application.rb +3 -3
  39. data/spec/dummy/config/environments/development.rb +4 -4
  40. data/spec/dummy/config/environments/test.rb +2 -2
  41. data/spec/dummy/lib/tasks/test.rake +10 -0
  42. data/spec/dummy/mini_test/mini_test_integration_test.rb +46 -0
  43. data/spec/dummy/spec/decorators/post_decorator_spec.rb +2 -2
  44. data/spec/dummy/spec/decorators/rspec_integration_spec.rb +19 -0
  45. data/spec/dummy/spec/mailers/post_mailer_spec.rb +2 -2
  46. data/spec/dummy/spec/spec_helper.rb +0 -1
  47. data/spec/generators/decorator/decorator_generator_spec.rb +43 -2
  48. data/spec/integration/integration_spec.rb +2 -2
  49. data/spec/spec_helper.rb +17 -21
  50. data/spec/support/active_record.rb +0 -13
  51. data/spec/support/dummy_app.rb +4 -3
  52. metadata +26 -23
  53. data/lib/draper/security.rb +0 -48
  54. data/lib/draper/tasks/tu.rake +0 -5
  55. data/lib/draper/test/test_unit_integration.rb +0 -18
  56. data/spec/draper/security_spec.rb +0 -158
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  58. data/spec/dummy/lib/tasks/spec.rake +0 -5
  59. data/spec/minitest-rails/spec_type_spec.rb +0 -63
@@ -1,48 +0,0 @@
1
- module Draper
2
- class Security
3
- def initialize
4
- @methods = []
5
- end
6
-
7
- def denies(*methods)
8
- apply_strategy :denies
9
- add_methods methods
10
- end
11
-
12
- def denies_all
13
- apply_strategy :denies_all
14
- end
15
-
16
- def allows(*methods)
17
- apply_strategy :allows
18
- add_methods methods
19
- end
20
-
21
- def allow?(method)
22
- case strategy
23
- when :allows
24
- methods.include?(method)
25
- when :denies
26
- !methods.include?(method)
27
- when :denies_all
28
- false
29
- when nil
30
- true
31
- end
32
- end
33
-
34
- private
35
-
36
- attr_reader :methods, :strategy
37
-
38
- def apply_strategy(new_strategy)
39
- raise ArgumentError, "Use only one of 'allows', 'denies', or 'denies_all'." if strategy && strategy != new_strategy
40
- @strategy = new_strategy
41
- end
42
-
43
- def add_methods(new_methods)
44
- raise ArgumentError, "Specify at least one method when using #{strategy}" if new_methods.empty?
45
- @methods += new_methods.map(&:to_sym)
46
- end
47
- end
48
- end
@@ -1,5 +0,0 @@
1
- if Rake::Task.task_defined?('test:run')
2
- Rake::Task['test:run'].enhance do
3
- Rake::Task['test:decorators'].invoke
4
- end
5
- end
@@ -1,18 +0,0 @@
1
- require "rake/testtask"
2
-
3
- klass = nil
4
-
5
- if Rails.version[0,3] == "3.0"
6
- require 'rails/test_unit/railtie'
7
- klass = Rake::TestTask
8
- else
9
- require "rails/test_unit/sub_test_task"
10
- klass = Rails::SubTestTask
11
- end
12
-
13
- namespace :test do
14
- klass.new(:decorators => "test:prepare") do |t|
15
- t.libs << "test"
16
- t.pattern = "test/decorators/**/*_test.rb"
17
- end
18
- end
@@ -1,158 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec::Matchers.define :allow do |method|
4
- match do |subject|
5
- subject.allow?(method)
6
- end
7
- end
8
-
9
- describe Draper::Security do
10
- subject(:security) { Draper::Security.new }
11
-
12
- context "when newly initialized" do
13
- it "allows any method" do
14
- security.should allow :foo
15
- end
16
- end
17
-
18
- describe "#denies" do
19
- it "raises an error when there are no arguments" do
20
- expect{security.denies}.to raise_error ArgumentError
21
- end
22
- end
23
-
24
- context "when using denies" do
25
- before { security.denies :foo, :bar }
26
-
27
- it "denies the listed methods" do
28
- security.should_not allow :foo
29
- security.should_not allow :bar
30
- end
31
-
32
- it "allows other methods" do
33
- security.should allow :baz
34
- end
35
-
36
- it "accepts multiple denies" do
37
- expect{security.denies :baz}.not_to raise_error
38
- end
39
-
40
- it "does not accept denies_all" do
41
- expect{security.denies_all}.to raise_error ArgumentError
42
- end
43
-
44
- it "does not accept allows" do
45
- expect{security.allows :baz}.to raise_error ArgumentError
46
- end
47
-
48
- context "when using mulitple denies" do
49
- before { security.denies :baz }
50
-
51
- it "still denies the original methods" do
52
- security.should_not allow :foo
53
- security.should_not allow :bar
54
- end
55
-
56
- it "denies the additional methods" do
57
- security.should_not allow :baz
58
- end
59
-
60
- it "allows other methods" do
61
- security.should allow :qux
62
- end
63
- end
64
-
65
- context "with strings" do
66
- before { security.denies "baz" }
67
-
68
- it "denies the method" do
69
- security.should_not allow :baz
70
- end
71
- end
72
- end
73
-
74
- context "when using denies_all" do
75
- before { security.denies_all }
76
-
77
- it "denies all methods" do
78
- security.should_not allow :foo
79
- end
80
-
81
- it "accepts multiple denies_all" do
82
- expect{security.denies_all}.not_to raise_error
83
- end
84
-
85
- it "does not accept denies" do
86
- expect{security.denies :baz}.to raise_error ArgumentError
87
- end
88
-
89
- it "does not accept allows" do
90
- expect{security.allows :baz}.to raise_error ArgumentError
91
- end
92
-
93
- context "when using mulitple denies_all" do
94
- before { security.denies_all }
95
-
96
- it "still denies all methods" do
97
- security.should_not allow :foo
98
- end
99
- end
100
- end
101
-
102
- describe "#allows" do
103
- it "raises an error when there are no arguments" do
104
- expect{security.allows}.to raise_error ArgumentError
105
- end
106
- end
107
-
108
- context "when using allows" do
109
- before { security.allows :foo, :bar }
110
-
111
- it "allows the listed methods" do
112
- security.should allow :foo
113
- security.should allow :bar
114
- end
115
-
116
- it "denies other methods" do
117
- security.should_not allow :baz
118
- end
119
-
120
- it "accepts multiple allows" do
121
- expect{security.allows :baz}.not_to raise_error
122
- end
123
-
124
- it "does not accept denies" do
125
- expect{security.denies :baz}.to raise_error ArgumentError
126
- end
127
-
128
- it "does not accept denies_all" do
129
- expect{security.denies_all}.to raise_error ArgumentError
130
- end
131
-
132
- context "when using mulitple allows" do
133
- before { security.allows :baz }
134
-
135
- it "still allows the original methods" do
136
- security.should allow :foo
137
- security.should allow :bar
138
- end
139
-
140
- it "allows the additional methods" do
141
- security.should allow :baz
142
- end
143
-
144
- it "denies other methods" do
145
- security.should_not allow :qux
146
- end
147
- end
148
-
149
- context "with strings" do
150
- before { security.allows "baz" }
151
-
152
- it "allows the method" do
153
- security.should allow :baz
154
- end
155
- end
156
- end
157
-
158
- end
@@ -1,14 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- require 'rspec/core/rake_task'
2
-
3
- RSpec::Core::RakeTask.new
4
-
5
- task "default" => "spec"
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
- require 'minitest/rails/active_support'
3
- require 'draper/test/minitest_integration'
4
-
5
- describe "minitest-rails spec_type Lookup Integration" do
6
- context "ProductDecorator" do
7
- it "resolves constants" do
8
- klass = MiniTest::Spec.spec_type(ProductDecorator)
9
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
10
- end
11
-
12
- it "resolves strings" do
13
- klass = MiniTest::Spec.spec_type("ProductDecorator")
14
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
15
- end
16
- end
17
-
18
- context "WidgetDecorator" do
19
- it "resolves constants" do
20
- klass = MiniTest::Spec.spec_type(WidgetDecorator)
21
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
22
- end
23
-
24
- it "resolves strings" do
25
- klass = MiniTest::Spec.spec_type("WidgetDecorator")
26
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
27
- end
28
- end
29
-
30
- context "decorator strings" do
31
- it "resolves DoesNotExistDecorator" do
32
- klass = MiniTest::Spec.spec_type("DoesNotExistDecorator")
33
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
34
- end
35
-
36
- it "resolves DoesNotExistDecoratorTest" do
37
- klass = MiniTest::Spec.spec_type("DoesNotExistDecoratorTest")
38
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
39
- end
40
-
41
- it "resolves Does Not Exist Decorator" do
42
- klass = MiniTest::Spec.spec_type("Does Not Exist Decorator")
43
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
44
- end
45
-
46
- it "resolves Does Not Exist Decorator Test" do
47
- klass = MiniTest::Spec.spec_type("Does Not Exist Decorator Test")
48
- klass.should == MiniTest::Rails::ActiveSupport::TestCase
49
- end
50
- end
51
-
52
- context "non-decorators" do
53
- it "doesn't resolve constants" do
54
- klass = MiniTest::Spec.spec_type(Draper::HelperSupport)
55
- klass.should == MiniTest::Spec
56
- end
57
-
58
- it "doesn't resolve strings" do
59
- klass = MiniTest::Spec.spec_type("Nothing to see here...")
60
- klass.should == MiniTest::Spec
61
- end
62
- end
63
- end