rspec-rails 2.0.0.beta.22 → 2.6.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.
- data/.gitignore +10 -4
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/History.md +1 -33
- data/License.txt +23 -0
- data/{README.markdown → README.md} +27 -7
- data/README_DEV.md +43 -0
- data/Rakefile +105 -35
- data/Thorfile +40 -0
- data/Upgrade.md +1 -0
- data/features/.nav +34 -0
- data/features/Autotest.md +24 -0
- data/features/Changelog.md +151 -0
- data/features/Generators.md +8 -0
- data/features/GettingStarted.md +84 -0
- data/features/README.md +58 -0
- data/features/Upgrade.md +117 -0
- data/features/controller_specs/README.md +45 -0
- data/features/controller_specs/anonymous_controller.feature +7 -7
- data/features/controller_specs/controller_spec.feature +18 -0
- data/features/controller_specs/isolation_from_views.feature +55 -8
- data/features/controller_specs/render_views.feature +63 -52
- data/features/helper_specs/helper_spec.feature +40 -6
- data/features/mailer_specs/url_helpers.feature +4 -4
- data/features/matchers/README.md +4 -0
- data/features/matchers/new_record_matcher.feature +6 -48
- data/features/matchers/redirect_to_matcher.feature +5 -6
- data/features/matchers/render_template_matcher.feature +13 -10
- data/features/mocks/mock_model.feature +29 -13
- data/features/mocks/stub_model.feature +4 -4
- data/features/model_specs/README.md +21 -0
- data/features/model_specs/errors_on.feature +2 -2
- data/features/model_specs/transactional_examples.feature +14 -9
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +17 -0
- data/features/{matchers → routing_specs}/be_routable_matcher.feature +25 -25
- data/features/routing_specs/named_routes.feature +18 -0
- data/features/routing_specs/route_to_matcher.feature +58 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/support/env.rb +14 -6
- data/features/view_specs/inferred_controller_path.feature +6 -6
- data/features/view_specs/stub_template.feature +51 -0
- data/features/view_specs/view_spec.feature +23 -42
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/base.rb +58 -0
- data/gemfiles/rails-3-0-stable +6 -0
- data/gemfiles/rails-3.0.0 +5 -0
- data/gemfiles/rails-3.0.1 +5 -0
- data/gemfiles/rails-3.0.2 +5 -0
- data/gemfiles/rails-3.0.3 +5 -0
- data/gemfiles/rails-3.0.4 +5 -0
- data/gemfiles/rails-3.0.5 +5 -0
- data/gemfiles/rails-3.0.6 +5 -0
- data/gemfiles/rails-3.0.7 +5 -0
- data/gemfiles/rails-3.1.0.beta1 +5 -0
- data/gemfiles/rails-master +7 -0
- data/lib/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +4 -4
- data/lib/generators/rspec/helper/helper_generator.rb +3 -3
- data/lib/generators/rspec/install/install_generator.rb +0 -8
- data/lib/generators/rspec/integration/integration_generator.rb +15 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +7 -1
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -2
- data/lib/generators/rspec/model/model_generator.rb +1 -1
- data/lib/generators/rspec/observer/observer_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +40 -11
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +90 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +15 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +7 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +14 -7
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +7 -2
- data/lib/generators/rspec/view/view_generator.rb +1 -1
- data/lib/rspec/rails/example/controller_example_group.rb +25 -34
- data/lib/rspec/rails/example/helper_example_group.rb +5 -11
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -14
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/rails_example_group.rb +0 -2
- data/lib/rspec/rails/example/request_example_group.rb +5 -30
- data/lib/rspec/rails/example/routing_example_group.rb +3 -5
- data/lib/rspec/rails/example/view_example_group.rb +20 -11
- data/lib/rspec/rails/example.rb +31 -1
- data/lib/rspec/rails/extensions/active_record/base.rb +28 -32
- data/lib/rspec/rails/fixture_support.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +5 -0
- data/lib/rspec/rails/matchers/redirect_to.rb +6 -2
- data/lib/rspec/rails/matchers/render_template.rb +5 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +24 -3
- data/lib/rspec/rails/matchers.rb +1 -1
- data/lib/rspec/rails/mocks.rb +118 -79
- data/lib/rspec/rails/module_inclusion.rb +17 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +29 -0
- data/lib/rspec/rails/vendor/webrat.rb +33 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +23 -4
- data/lib/rspec/rails/view_rendering.rb +50 -13
- data/lib/rspec/rails.rb +7 -10
- data/lib/rspec-rails.rb +4 -2
- data/rspec-rails.gemspec +11 -39
- data/spec/autotest/rails_rspec2_spec.rb +25 -14
- data/spec/rspec/rails/configuration_spec.rb +26 -0
- data/spec/rspec/rails/deprecations_spec.rb +18 -0
- data/spec/rspec/rails/example/controller_example_group_spec.rb +47 -5
- data/spec/rspec/rails/example/helper_example_group_spec.rb +19 -1
- data/spec/rspec/rails/example/request_example_group_spec.rb +2 -0
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
- data/spec/rspec/rails/extensions/active_record/records_spec.rb +9 -0
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +17 -0
- data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +67 -8
- data/spec/rspec/rails/matchers/render_template_spec.rb +67 -10
- data/spec/rspec/rails/matchers/route_to_spec.rb +77 -31
- data/spec/rspec/rails/mocks/ar_classes.rb +17 -25
- data/spec/rspec/rails/mocks/mock_model_spec.rb +50 -13
- data/spec/rspec/rails/mocks/stub_model_spec.rb +121 -67
- data/spec/rspec/rails/view_rendering_spec.rb +105 -0
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +10 -2
- data/templates/run_specs.rb +2 -2
- metadata +141 -79
- data/Gemfile +0 -24
- data/Gotchas.markdown +0 -14
- data/Upgrade.markdown +0 -31
- data/autotest/discover.rb +0 -1
- data/features/README.markdown +0 -12
- data/features/controller_specs/readers.feature +0 -18
- data/features/routing_specs/access_to_named_routes.feature +0 -15
- data/lib/generators/rspec/install/templates/autotest/discover.rb +0 -2
- data/lib/rspec/rails/browser_simulators.rb +0 -30
- data/spec/rspec/rails/example/view_rendering_spec.rb +0 -110
- data/specs.watchr +0 -59
- data/templates/Gemfile +0 -18
|
@@ -1,20 +1,79 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
|
-
require "
|
|
2
|
+
require "active_support/test_case"
|
|
3
3
|
|
|
4
4
|
describe "redirect_to" do
|
|
5
5
|
include RSpec::Rails::Matchers::RedirectTo
|
|
6
6
|
|
|
7
|
+
let(:response) { ActionController::TestResponse.new }
|
|
8
|
+
|
|
7
9
|
it "delegates to assert_redirected_to" do
|
|
8
10
|
self.should_receive(:assert_redirected_to).with("destination")
|
|
9
11
|
"response".should redirect_to("destination")
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
context "with should" do
|
|
15
|
+
context "when assert_redirected_to passes" do
|
|
16
|
+
it "passes" do
|
|
17
|
+
self.stub!(:assert_redirected_to)
|
|
18
|
+
expect do
|
|
19
|
+
response.should redirect_to("destination")
|
|
20
|
+
end.to_not raise_exception
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when assert_redirected_to fails" do
|
|
25
|
+
it "uses failure message from assert_redirected_to" do
|
|
26
|
+
self.stub!(:assert_redirected_to) do
|
|
27
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
|
28
|
+
end
|
|
29
|
+
expect do
|
|
30
|
+
response.should redirect_to("destination")
|
|
31
|
+
end.to raise_error("this message")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "when fails due to some other exception" do
|
|
36
|
+
it "raises that exception" do
|
|
37
|
+
self.stub!(:assert_redirected_to) do
|
|
38
|
+
raise "oops"
|
|
39
|
+
end
|
|
40
|
+
expect do
|
|
41
|
+
response.should redirect_to("destination")
|
|
42
|
+
end.to raise_exception("oops")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "with should_not" do
|
|
48
|
+
context "when assert_redirected_to fails" do
|
|
49
|
+
it "passes" do
|
|
50
|
+
self.stub!(:assert_redirected_to) do
|
|
51
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
|
52
|
+
end
|
|
53
|
+
expect do
|
|
54
|
+
response.should_not redirect_to("destination")
|
|
55
|
+
end.to_not raise_exception
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "when assert_redirected_to passes" do
|
|
60
|
+
it "fails with custom failure message" do
|
|
61
|
+
self.stub!(:assert_redirected_to)
|
|
62
|
+
expect do
|
|
63
|
+
response.should_not redirect_to("destination")
|
|
64
|
+
end.to raise_error(/expected not to redirect to \"destination\", but did/)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "when fails due to some other exception" do
|
|
69
|
+
it "raises that exception" do
|
|
70
|
+
self.stub!(:assert_redirected_to) do
|
|
71
|
+
raise "oops"
|
|
72
|
+
end
|
|
73
|
+
expect do
|
|
74
|
+
response.should_not redirect_to("destination")
|
|
75
|
+
end.to raise_exception("oops")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
19
78
|
end
|
|
20
79
|
end
|
|
@@ -2,15 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "render_template" do
|
|
4
4
|
include RSpec::Rails::Matchers::RenderTemplate
|
|
5
|
-
|
|
6
|
-
it "uses failure message from render_template" do
|
|
7
|
-
self.stub!(:assert_template).and_raise(
|
|
8
|
-
Test::Unit::AssertionFailedError.new("this message"))
|
|
9
|
-
response = ActionController::TestResponse.new
|
|
10
|
-
expect do
|
|
11
|
-
response.should render_template("destination")
|
|
12
|
-
end.to raise_error("this message")
|
|
13
|
-
end
|
|
5
|
+
let(:response) { ActionController::TestResponse.new }
|
|
14
6
|
|
|
15
7
|
context "given a hash" do
|
|
16
8
|
it "delegates to assert_template" do
|
|
@@ -32,5 +24,70 @@ describe "render_template" do
|
|
|
32
24
|
"response".should render_template(:template_name, "this message")
|
|
33
25
|
end
|
|
34
26
|
end
|
|
35
|
-
end
|
|
36
27
|
|
|
28
|
+
context "with should" do
|
|
29
|
+
context "when assert_template passes" do
|
|
30
|
+
it "passes" do
|
|
31
|
+
self.stub!(:assert_template)
|
|
32
|
+
expect do
|
|
33
|
+
response.should render_template("template_name")
|
|
34
|
+
end.to_not raise_exception
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when assert_template fails" do
|
|
39
|
+
it "uses failure message from assert_template" do
|
|
40
|
+
self.stub!(:assert_template) do
|
|
41
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
|
42
|
+
end
|
|
43
|
+
expect do
|
|
44
|
+
response.should render_template("template_name")
|
|
45
|
+
end.to raise_error("this message")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "when fails due to some other exception" do
|
|
50
|
+
it "raises that exception" do
|
|
51
|
+
self.stub!(:assert_template) do
|
|
52
|
+
raise "oops"
|
|
53
|
+
end
|
|
54
|
+
expect do
|
|
55
|
+
response.should render_template("template_name")
|
|
56
|
+
end.to raise_exception("oops")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "with should_not" do
|
|
62
|
+
context "when assert_template fails" do
|
|
63
|
+
it "passes" do
|
|
64
|
+
self.stub!(:assert_template) do
|
|
65
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
|
66
|
+
end
|
|
67
|
+
expect do
|
|
68
|
+
response.should_not render_template("template_name")
|
|
69
|
+
end.to_not raise_exception
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context "when assert_template passes" do
|
|
74
|
+
it "fails with custom failure message" do
|
|
75
|
+
self.stub!(:assert_template)
|
|
76
|
+
expect do
|
|
77
|
+
response.should_not render_template("template_name")
|
|
78
|
+
end.to raise_error(/expected not to render \"template_name\", but did/)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "when fails due to some other exception" do
|
|
83
|
+
it "raises that exception" do
|
|
84
|
+
self.stub!(:assert_template) do
|
|
85
|
+
raise "oops"
|
|
86
|
+
end
|
|
87
|
+
expect do
|
|
88
|
+
response.should_not render_template("template_name")
|
|
89
|
+
end.to raise_exception("oops")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -2,52 +2,98 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "route_to" do
|
|
4
4
|
include RSpec::Rails::Matchers::RoutingMatchers
|
|
5
|
+
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
|
|
5
6
|
|
|
6
|
-
it "
|
|
7
|
-
self.
|
|
8
|
-
|
|
9
|
-
expect do
|
|
10
|
-
{"this" => "path"}.should route_to("these" => "options")
|
|
11
|
-
end.to raise_error("this message")
|
|
7
|
+
it "delegates to assert_recognizes" do
|
|
8
|
+
self.should_receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" })
|
|
9
|
+
{:get => "path"}.should route_to("these" => "options")
|
|
12
10
|
end
|
|
13
|
-
end
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
context "with shortcut syntax" do
|
|
13
|
+
|
|
14
|
+
it "routes with extra options" do
|
|
15
|
+
self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" })
|
|
16
|
+
get("path").should route_to("controller#action", :extra => "options")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "routes without extra options" do
|
|
20
|
+
self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action"}, { :method=> :get, :path=>"path" })
|
|
21
|
+
get("path").should route_to("controller#action")
|
|
22
|
+
end
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
end
|
|
20
25
|
|
|
21
26
|
context "with should" do
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
context "when assert_recognizes passes" do
|
|
28
|
+
it "passes" do
|
|
29
|
+
self.stub!(:assert_recognizes)
|
|
30
|
+
expect do
|
|
31
|
+
{:get => "path"}.should route_to("these" => "options")
|
|
32
|
+
end.to_not raise_exception
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when assert_recognizes fails" do
|
|
37
|
+
it "fails with message from assert_recognizes" do
|
|
38
|
+
self.stub!(:assert_recognizes) do
|
|
39
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
|
40
|
+
end
|
|
41
|
+
expect do
|
|
42
|
+
{:get => "path"}.should route_to("these" => "options")
|
|
43
|
+
end.to raise_error("this message")
|
|
44
|
+
end
|
|
27
45
|
end
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
context "when an exception is raised" do
|
|
48
|
+
it "raises that exception" do
|
|
49
|
+
self.stub!(:assert_recognizes) do
|
|
50
|
+
raise "oops"
|
|
51
|
+
end
|
|
52
|
+
expect do
|
|
53
|
+
{:get => "path"}.should route_to("these" => "options")
|
|
54
|
+
end.to raise_exception("oops")
|
|
55
|
+
end
|
|
34
56
|
end
|
|
35
57
|
end
|
|
36
58
|
|
|
37
59
|
context "with should_not" do
|
|
60
|
+
context "when assert_recognizes passes" do
|
|
61
|
+
it "fails with custom message" do
|
|
62
|
+
self.stub!(:assert_recognizes)
|
|
63
|
+
expect do
|
|
64
|
+
{:get => "path"}.should_not route_to("these" => "options")
|
|
65
|
+
end.to raise_error(/expected .* not to route to .*/)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
38
68
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
69
|
+
context "when assert_recognizes fails" do
|
|
70
|
+
it "passes" do
|
|
71
|
+
self.stub!(:assert_recognizes) do
|
|
72
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
|
73
|
+
end
|
|
74
|
+
expect do
|
|
75
|
+
{:get => "path"}.should_not route_to("these" => "options")
|
|
76
|
+
end.to_not raise_error
|
|
77
|
+
end
|
|
44
78
|
end
|
|
45
79
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
context "when an exception is raised" do
|
|
81
|
+
it "raises that exception" do
|
|
82
|
+
self.stub!(:assert_recognizes) do
|
|
83
|
+
raise "oops"
|
|
84
|
+
end
|
|
85
|
+
expect do
|
|
86
|
+
{:get => "path"}.should_not route_to("these" => "options")
|
|
87
|
+
end.to raise_exception("oops")
|
|
88
|
+
end
|
|
51
89
|
end
|
|
52
90
|
end
|
|
91
|
+
it "uses failure message from assert_recognizes" do
|
|
92
|
+
self.stub!(:assert_recognizes).and_raise(
|
|
93
|
+
ActiveSupport::TestCase::Assertion.new("this message"))
|
|
94
|
+
expect do
|
|
95
|
+
{"this" => "path"}.should route_to("these" => "options")
|
|
96
|
+
end.to raise_error("this message")
|
|
97
|
+
end
|
|
53
98
|
end
|
|
99
|
+
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
ActiveRecord::Base.establish_connection(
|
|
2
|
+
:adapter => 'sqlite3',
|
|
3
|
+
:database => ':memory:'
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
module Connections
|
|
7
|
+
def self.extended(host)
|
|
8
|
+
|
|
9
|
+
host.connection.execute <<-eosql
|
|
10
|
+
CREATE TABLE #{host.table_name} (
|
|
11
|
+
#{host.primary_key} integer PRIMARY KEY AUTOINCREMENT
|
|
12
|
+
)
|
|
13
|
+
eosql
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
class NonActiveRecordModel
|
|
16
18
|
extend ActiveModel::Naming
|
|
19
|
+
include ActiveModel::Conversion
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
class MockableModel < ActiveRecord::Base
|
|
20
|
-
|
|
23
|
+
extend Connections
|
|
21
24
|
has_one :associated_model
|
|
22
25
|
end
|
|
23
26
|
|
|
@@ -25,23 +28,12 @@ class SubMockableModel < MockableModel
|
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
class AssociatedModel < ActiveRecord::Base
|
|
28
|
-
|
|
31
|
+
extend Connections
|
|
29
32
|
belongs_to :mockable_model
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
class AlternatePrimaryKeyModel < ActiveRecord::Base
|
|
33
|
-
include NoConnections
|
|
34
36
|
self.primary_key = :my_id
|
|
37
|
+
extend Connections
|
|
35
38
|
attr_accessor :my_id
|
|
36
39
|
end
|
|
37
|
-
|
|
38
|
-
class ConnectableModel < ActiveRecord::Base
|
|
39
|
-
establish_connection :adapter => 'sqlite3',
|
|
40
|
-
:database => ':memory:'
|
|
41
|
-
|
|
42
|
-
connection.execute <<-eosql
|
|
43
|
-
CREATE TABLE connectable_models (
|
|
44
|
-
id integer PRIMARY KEY AUTOINCREMENT
|
|
45
|
-
)
|
|
46
|
-
eosql
|
|
47
|
-
end
|
|
@@ -41,19 +41,17 @@ describe "mock_model(RealModel)" do
|
|
|
41
41
|
before(:each) do
|
|
42
42
|
@model = mock_model(MockableModel, :id => 1)
|
|
43
43
|
end
|
|
44
|
+
|
|
44
45
|
it "is named using the stubbed id value" do
|
|
45
46
|
@model.instance_variable_get(:@name).should == "MockableModel_1"
|
|
46
47
|
end
|
|
47
|
-
it "returns string of id value for to_param" do
|
|
48
|
-
@model.to_param.should == "1"
|
|
49
|
-
end
|
|
50
48
|
end
|
|
51
49
|
|
|
52
50
|
describe "destroy" do
|
|
53
|
-
it "sets
|
|
51
|
+
it "sets persisted to false" do
|
|
54
52
|
model = mock_model(MockableModel)
|
|
55
53
|
model.destroy
|
|
56
|
-
model.
|
|
54
|
+
model.should_not be_persisted
|
|
57
55
|
end
|
|
58
56
|
end
|
|
59
57
|
|
|
@@ -146,11 +144,34 @@ describe "mock_model(RealModel)" do
|
|
|
146
144
|
MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
|
|
147
145
|
@model = mock_model(MockableModel)
|
|
148
146
|
end
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
|
|
148
|
+
it "accepts two arguments" do
|
|
149
|
+
expect do
|
|
150
|
+
@model.respond_to?("title_before_type_cast", false)
|
|
151
|
+
end.to_not raise_exception
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context "without as_null_object" do
|
|
155
|
+
it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
|
|
156
|
+
@model.respond_to?("column_a").should be(true)
|
|
157
|
+
end
|
|
158
|
+
it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
|
|
159
|
+
@model.respond_to?("column_c").should be(false)
|
|
160
|
+
end
|
|
161
|
+
it "says it will not respond_to?(xxx_before_type_cast)" do
|
|
162
|
+
@model.respond_to?("title_before_type_cast").should be(false)
|
|
163
|
+
end
|
|
151
164
|
end
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
context "with as_null_object" do
|
|
166
|
+
it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
|
|
167
|
+
@model.as_null_object.respond_to?("column_a").should be(true)
|
|
168
|
+
end
|
|
169
|
+
it "says it will respond_to?(key) even if RealModel does not have the attribute 'key'" do
|
|
170
|
+
@model.as_null_object.respond_to?("column_c").should be(true)
|
|
171
|
+
end
|
|
172
|
+
it "says it will not respond_to?(xxx_before_type_cast)" do
|
|
173
|
+
@model.as_null_object.respond_to?("title_before_type_cast").should be(false)
|
|
174
|
+
end
|
|
154
175
|
end
|
|
155
176
|
end
|
|
156
177
|
|
|
@@ -159,6 +180,12 @@ describe "mock_model(RealModel)" do
|
|
|
159
180
|
model = NonActiveRecordModel.new
|
|
160
181
|
model.should respond_to(:to_param)
|
|
161
182
|
end
|
|
183
|
+
context "with as_null_object" do
|
|
184
|
+
it "says it will not respond_to?(xxx_before_type_cast)" do
|
|
185
|
+
model = NonActiveRecordModel.new.as_null_object
|
|
186
|
+
model.respond_to?("title_before_type_cast").should be(false)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
162
189
|
end
|
|
163
190
|
end
|
|
164
191
|
|
|
@@ -181,26 +208,25 @@ describe "mock_model(RealModel)" do
|
|
|
181
208
|
end
|
|
182
209
|
|
|
183
210
|
describe "#persisted?" do
|
|
184
|
-
context "with default
|
|
211
|
+
context "with default identifier" do
|
|
185
212
|
it "returns true" do
|
|
186
213
|
mock_model(MockableModel).should be_persisted
|
|
187
214
|
end
|
|
188
215
|
end
|
|
189
216
|
|
|
190
|
-
context "with explicit id" do
|
|
217
|
+
context "with explicit identifier via :id" do
|
|
191
218
|
it "returns true" do
|
|
192
219
|
mock_model(MockableModel, :id => 37).should be_persisted
|
|
193
220
|
end
|
|
194
221
|
end
|
|
195
222
|
|
|
196
|
-
context "with id nil" do
|
|
223
|
+
context "with id => nil" do
|
|
197
224
|
it "returns false" do
|
|
198
225
|
mock_model(MockableModel, :id => nil).should_not be_persisted
|
|
199
226
|
end
|
|
200
227
|
end
|
|
201
228
|
end
|
|
202
229
|
|
|
203
|
-
|
|
204
230
|
describe "#valid?" do
|
|
205
231
|
context "default" do
|
|
206
232
|
it "returns true" do
|
|
@@ -220,6 +246,11 @@ describe "mock_model(RealModel)" do
|
|
|
220
246
|
m.as_new_record.should be_new_record
|
|
221
247
|
end
|
|
222
248
|
|
|
249
|
+
it "says it is not persisted" do
|
|
250
|
+
m = mock_model(MockableModel)
|
|
251
|
+
m.as_new_record.should_not be_persisted
|
|
252
|
+
end
|
|
253
|
+
|
|
223
254
|
it "has a nil id" do
|
|
224
255
|
mock_model(MockableModel).as_new_record.id.should be(nil)
|
|
225
256
|
end
|
|
@@ -229,6 +260,12 @@ describe "mock_model(RealModel)" do
|
|
|
229
260
|
end
|
|
230
261
|
end
|
|
231
262
|
|
|
263
|
+
describe "#blank?" do
|
|
264
|
+
it "is false" do
|
|
265
|
+
mock_model(MockableModel).should_not be_blank
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
232
269
|
describe "ActiveModel Lint tests" do
|
|
233
270
|
require 'test/unit/assertions'
|
|
234
271
|
require 'active_model/lint'
|