riot-rails 0.0.10.pre.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/{test/rails_root/app/views/rendered_templates/foo_bar.html.erb → README.md} +0 -0
  2. data/Rakefile +10 -32
  3. data/VERSION +1 -1
  4. data/init.rb +0 -0
  5. data/install.rb +0 -0
  6. data/lib/generators/riot_rails.rb +10 -0
  7. data/lib/generators/riot_rails/model/model_generator.rb +22 -0
  8. data/lib/generators/riot_rails/model/templates/fixtures.yml +23 -0
  9. data/lib/generators/riot_rails/model/templates/riot_test.rb +5 -0
  10. metadata +26 -155
  11. data/.gitignore +0 -4
  12. data/CHANGELOG +0 -144
  13. data/MIT-LICENSE +0 -20
  14. data/README.markdown +0 -31
  15. data/lib/riot/action_controller.rb +0 -4
  16. data/lib/riot/action_controller/context_macros/asserts_response.rb +0 -15
  17. data/lib/riot/action_controller/context_middleware.rb +0 -45
  18. data/lib/riot/action_controller/http_methods.rb +0 -19
  19. data/lib/riot/active_record.rb +0 -4
  20. data/lib/riot/active_record/assertion_macros.rb +0 -3
  21. data/lib/riot/active_record/context_middleware.rb +0 -15
  22. data/lib/riot/active_record/database_macros.rb +0 -58
  23. data/lib/riot/active_record/reflection_macros.rb +0 -106
  24. data/lib/riot/active_record/transactional_middleware.rb +0 -21
  25. data/lib/riot/active_record/validation_macros.rb +0 -187
  26. data/lib/riot/rails.rb +0 -1
  27. data/rails/init.rb +0 -1
  28. data/riot-rails.gemspec +0 -130
  29. data/test/action_controller/context_macros/asserts_response_test.rb +0 -35
  30. data/test/action_controller/context_middleware_test.rb +0 -66
  31. data/test/action_controller/delete_request_test.rb +0 -45
  32. data/test/action_controller/get_request_test.rb +0 -37
  33. data/test/action_controller/post_request_test.rb +0 -45
  34. data/test/action_controller/put_request_test.rb +0 -45
  35. data/test/action_controller/restful_delete_request_test.rb +0 -28
  36. data/test/action_controller/restful_get_request_test.rb +0 -25
  37. data/test/action_controller/restful_post_request_test.rb +0 -25
  38. data/test/action_controller/restful_put_request_test.rb +0 -28
  39. data/test/active_record/allowing_values_test.rb +0 -64
  40. data/test/active_record/attribute_is_invalid_test.rb +0 -20
  41. data/test/active_record/belongs_to_test.rb +0 -22
  42. data/test/active_record/context_middleware_test.rb +0 -18
  43. data/test/active_record/has_and_belongs_to_many_test.rb +0 -22
  44. data/test/active_record/has_database_index_on_test.rb +0 -73
  45. data/test/active_record/has_many_test.rb +0 -22
  46. data/test/active_record/has_one_test.rb +0 -22
  47. data/test/active_record/validates_length_of_test.rb +0 -31
  48. data/test/active_record/validates_presence_of_test.rb +0 -14
  49. data/test/active_record/validates_uniqueness_of_test.rb +0 -23
  50. data/test/rails_root/app/controllers/gremlins_controller.rb +0 -21
  51. data/test/rails_root/app/controllers/parties_controller.rb +0 -17
  52. data/test/rails_root/app/controllers/rooms_controller.rb +0 -22
  53. data/test/rails_root/config/database.yml +0 -4
  54. data/test/rails_root/config/environment.rb +0 -46
  55. data/test/rails_root/config/routes.rb +0 -7
  56. data/test/rails_root/db/schema.rb +0 -8
  57. data/test/teststrap.rb +0 -84
  58. data/test/transactional_middleware_test.rb +0 -26
@@ -1,25 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "RESTful GET request on resource" do
4
-
5
- context GremlinsController do
6
- setup { get("/gremlins/1") }
7
-
8
- asserts("request method") { request.request_method }.equals("GET")
9
- asserts("controller name") { controller.controller_name }.equals("gremlins")
10
- asserts("action name") { controller.action_name }.equals("show")
11
- asserts("id param") { controller.params["id"] }.equals("1")
12
- asserts("response body") { response.body }.equals("show me the money")
13
- end # on a top level resource
14
-
15
- context PartiesController do
16
- setup { get("/gremlins/1/parties/2") }
17
-
18
- asserts("request method") { request.request_method }.equals("GET")
19
- asserts("controller name") { controller.controller_name }.equals("parties")
20
- asserts("action name") { controller.action_name }.equals("show")
21
- asserts("gremlin_id param") { controller.params["gremlin_id"] }.equals("1")
22
- asserts("id param") { controller.params["id"] }.equals("2")
23
- asserts("response body") { response.body }.equals("woot")
24
- end # on a nested resource
25
- end # RESTful GET request
@@ -1,25 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "RESTful POST request on resource" do
4
-
5
- context GremlinsController do
6
- setup { post("/gremlins", :id => 2) }
7
-
8
- asserts("request method") { request.request_method }.equals("POST")
9
- asserts("controller name") { controller.controller_name }.equals("gremlins")
10
- asserts("action name") { controller.action_name }.equals("create")
11
- asserts("id param") { controller.params["id"] }.equals("2")
12
- asserts("response body") { response.body }.equals("makin' money")
13
- end # on a top level resource
14
-
15
- context PartiesController do
16
- setup { post("/gremlins/2/parties", "id" => 3) }
17
-
18
- asserts("request method") { request.request_method }.equals("POST")
19
- asserts("controller name") { controller.controller_name }.equals("parties")
20
- asserts("action name") { controller.action_name }.equals("create")
21
- asserts("gremlin_id param") { controller.params["gremlin_id"] }.equals("2")
22
- asserts("id param") { controller.params["id"] }.equals("3")
23
- asserts("response body") { response.body }.equals("give this monkey what he wants")
24
- end # on a nested resource
25
- end # RESTful POST request
@@ -1,28 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "RESTful PUT request on resource" do
4
-
5
- context GremlinsController do
6
- setup { put("/gremlins/2") }
7
-
8
- asserts("request method") { request.request_method }.equals("PUT")
9
- asserts("controller name") { controller.controller_name }.equals("gremlins")
10
- asserts("action name") { controller.action_name }.equals("update")
11
- asserts("id param") { controller.params["id"] }.equals("2")
12
- asserts("response body") { response.body }.equals("savin' money")
13
- end # on a top level resource
14
-
15
- context PartiesController do
16
- setup { put("/gremlins/2/parties/3", "foo" => "bar") }
17
-
18
- asserts("request method") { request.request_method }.equals("PUT")
19
- asserts("controller name") { controller.controller_name }.equals("parties")
20
- asserts("action name") { controller.action_name }.equals("update")
21
-
22
- asserts("gremlin_id param") { controller.params["gremlin_id"] }.equals("2")
23
- asserts("id param") { controller.params["id"] }.equals("3")
24
- asserts("foo param") { controller.params["foo"] }.equals("bar")
25
-
26
- asserts("response body") { response.body }.equals("i'll put that over here")
27
- end # on a nested resource
28
- end # RESTful PUT request
@@ -1,64 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The allow_values_for assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("pass when attribute allows a value") do
8
- topic.allows_values_for(:email, "a@b.cd").run(Riot::Situation.new)
9
- end.equals([:pass, ""])
10
-
11
- should("pass when attribute allows multiple values") do
12
- topic.allows_values_for(:email, "a@b.cd", "e@f.gh").run(Riot::Situation.new)
13
- end.equals([:pass, ""])
14
-
15
- should("fail when attribute is provided a valid and an invalid value") do
16
- topic.allows_values_for(:email, "a", "e@f.gh").run(Riot::Situation.new)
17
- end.equals([:fail, %Q{expected :email to allow values ["a"]}, blah, blah])
18
- end # The allow_values_for assertion macro
19
-
20
- context "The does_not_allow_values_for assertion macro" do
21
- setup_test_context
22
- setup { topic.asserts("room") { Room.new } }
23
-
24
- should("pass when attribute does not allow a value") do
25
- topic.does_not_allow_values_for(:email, "a").run(Riot::Situation.new)
26
- end.equals([:pass, ""])
27
-
28
- should("pass when attribute does not allow multiple values") do
29
- topic.does_not_allow_values_for(:email, "a", "e").run(Riot::Situation.new)
30
- end.equals([:pass, ""])
31
-
32
- should("fail when attribute is provided a valid and an invalid value") do
33
- topic.does_not_allow_values_for(:email, "a", "e@f.gh").run(Riot::Situation.new)
34
- end.equals([:fail, %Q{expected :email not to allow values ["e@f.gh"]}, blah, blah])
35
- end # The does_not_allow_values_for assertion macro
36
-
37
- context "The is_invalid_when assertion macro" do
38
- setup_test_context
39
- setup { topic.asserts("room") { Room.new } }
40
-
41
- should("pass when attribute is invalid") do
42
- topic.is_invalid_when(:email, "fake").run(Riot::Situation.new)
43
- end.equals([:pass, %Q{attribute :email is invalid}])
44
-
45
- should("pass when error message equals one in its list of errors") do
46
- topic.is_invalid_when(:email, "fake", "is invalid").run(Riot::Situation.new)
47
- end.equals([:pass, %Q{attribute :email is invalid}])
48
-
49
- should("pass when error message matches one in its list of errors") do
50
- topic.is_invalid_when(:email, "fake", /invalid/).run(Riot::Situation.new)
51
- end.equals([:pass, %Q{attribute :email is invalid}])
52
-
53
- should("fail when attribute is valid") do
54
- topic.is_invalid_when(:email, "a@b.cd", "is invalid").run(Riot::Situation.new)
55
- end.equals([:fail, %Q{expected :email to be invalid when value is "a@b.cd"}, blah, blah])
56
-
57
- should("fail when exact error message not found") do
58
- topic.is_invalid_when(:email, "fake", "can't be blank").run(Riot::Situation.new)
59
- end.equals([:fail, %Q{expected :email to be invalid with error message "can't be blank"}, blah, blah])
60
-
61
- should("fail when error message not matched to returned errors") do
62
- topic.is_invalid_when(:email, "fake", /blank/).run(Riot::Situation.new)
63
- end.equals([:fail, %Q{expected :email to be invalid with error message /blank/}, blah, blah])
64
- end # The is_invalid_when assertion macro
@@ -1,20 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The attribute_is_invalid macro" do
4
- setup_test_context
5
-
6
- should("fail when attribute is not invalid") do
7
- assertion = topic.asserts("room") { Room.new(:location => "barn burner") }
8
- assertion.attribute_is_invalid(:location, "not yet").run(Riot::Situation.new)
9
- end.equals([:fail, ":location expected to be invalid", blah, blah])
10
-
11
- should("fail when attribute is invalid, but the message could not be found") do
12
- assertion = topic.asserts("room") { Room.new }
13
- assertion.attribute_is_invalid(:location, "child please").run(Riot::Situation.new)
14
- end.equals([:fail, %Q{:location is invalid, but "child please" is not a valid error message}, blah, blah])
15
-
16
- should("pass when attribute is invalid and error message is found") do
17
- assertion = topic.asserts("room") { Room.new }
18
- assertion.attribute_is_invalid(:location, "can't be blank").run(Riot::Situation.new)
19
- end.equals([:pass, %Q{:location is invalid}])
20
- end # The attribute_is_invalid macro
@@ -1,22 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The belongs_to assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("pass when record has a belongs_to association defined for attribute") do
8
- topic.belongs_to(:house).run(Riot::Situation.new)
9
- end.equals([:pass, ":house is a belongs_to association"])
10
-
11
- should("fail when record does not have a belongs_to association defined for attribute") do
12
- topic.belongs_to(:someone_else).run(Riot::Situation.new)
13
- end.equals([:fail, ":someone_else is not a belongs_to association", blah, blah])
14
-
15
- should("fail when attribute is not a belongs_to, but is a has_one association") do
16
- topic.belongs_to(:floor).run(Riot::Situation.new)
17
- end.equals([:fail, ":floor is not a belongs_to association", blah, blah])
18
-
19
- should("fail when association options are specified, but they do not match the record") do
20
- topic.belongs_to(:owner, :class_name => "Person").run(Riot::Situation.new)
21
- end.equals([:fail, %q[expected belongs_to :owner with {:class_name=>"Person"}], blah, blah])
22
- end # The has_many assertion macro
@@ -1,18 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "ActiveRecord middleware" do
4
- setup_test_context
5
-
6
- setup do
7
- situation = Riot::Situation.new
8
- topic.context(Room) do
9
- hookup { topic.email = "i.am@chee.se" }
10
- end.local_run(Riot::SilentReporter.new, situation)
11
- situation.topic
12
- end
13
-
14
- asserts_topic.kind_of(Room)
15
- asserts(:new_record?)
16
- asserts(:email).equals("i.am@chee.se")
17
-
18
- end # ActiveRecord middleware
@@ -1,22 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The has_and_belongs_to_many assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("pass when record has a has_and_belongs_to_many association defined for attribute") do
8
- topic.has_and_belongs_to_many(:walls).run(Riot::Situation.new)
9
- end.equals([:pass, ":walls is a has_and_belongs_to_many association"])
10
-
11
- should("fail when record does not have a has_and_belongs_to_many association defined for attribute") do
12
- topic.has_and_belongs_to_many(:windows).run(Riot::Situation.new)
13
- end.equals([:fail, ":windows is not a has_and_belongs_to_many association", blah, blah])
14
-
15
- should("fail when attribute is not a has_and_belongs_to_many, but is a has_many association") do
16
- topic.has_and_belongs_to_many(:doors).run(Riot::Situation.new)
17
- end.equals([:fail, ":doors is not a has_and_belongs_to_many association", blah, blah])
18
-
19
- should("fail when association options are specified, but they do not match the record") do
20
- topic.has_and_belongs_to_many(:walls, :join_table => "blueprints").run(Riot::Situation.new)
21
- end.equals([:fail, %q[expected has_and_belongs_to_many :walls with {:join_table=>"blueprints"}], blah, blah])
22
- end # The has_and_belongs_to_many assertion macro
@@ -1,73 +0,0 @@
1
- require 'teststrap'
2
- require 'ostruct'
3
-
4
- context "The has_database_index_on macro" do
5
- setup_test_context
6
- setup { topic.asserts("room") { Room.new } }
7
-
8
- hookup do
9
- MockConnection = Class.new do
10
- def initialize(index_lookup) @index_lookup = index_lookup; end
11
- def indexes(table) @index_lookup[table]; end
12
- end
13
-
14
- def build_assertion(table, columns, unique=false)
15
- database_connection = MockConnection.new({table => [ define_index(table, columns, unique) ]})
16
- # I'll inject your dependency! ;)
17
- RiotRails::ActiveRecord::HasDatabaseIndexOnMacro.new(database_connection)
18
- end
19
-
20
- def define_index(table, columns, unique)
21
- ActiveRecord::ConnectionAdapters::IndexDefinition.new(table, columns.join(','), unique, columns)
22
- end
23
- end
24
-
25
- should("fail when no index for column") do
26
- topic.has_database_index_on(:foo).run(Riot::Situation.new)
27
- end.equals([:fail, %Q{expected index on [:foo]}, blah, blah])
28
-
29
- should("fail when no index for column set") do
30
- topic.has_database_index_on(:foo, :bar).run(Riot::Situation.new)
31
- end.equals([:fail, %Q{expected index on [:foo, :bar]}, blah, blah])
32
-
33
- should("fail when index found for column, but it's not unique") do
34
- build_assertion("rooms", ["foo"], false).
35
- evaluate(Room.new, :foo, :unique => true)
36
- end.equals([:fail, %Q{expected unique index on [:foo]}, blah, blah])
37
-
38
- should("fail when index found for column, but it's unique and should not be") do
39
- build_assertion("rooms", ["foo"], true).
40
- evaluate(Room.new, :foo, :unique => false)
41
- end.equals([:fail, %Q{expected index on [:foo]}, blah, blah])
42
-
43
- should("pass when index found for column") do
44
- build_assertion("rooms", ["foo"], false).
45
- evaluate(Room.new, :foo)
46
- end.equals([:pass, %Q{has index on [:foo]}])
47
-
48
- should("pass when index found for column set") do
49
- build_assertion("rooms", ["foo", "bar"], false).
50
- evaluate(Room.new, :foo, :bar)
51
- end.equals([:pass, %Q{has index on [:foo, :bar]}])
52
-
53
- should("pass when unique index found for column") do
54
- build_assertion("rooms", ["foo"], true).
55
- evaluate(Room.new, :foo, :unique => true)
56
- end.equals([:pass, %Q{has unique index on [:foo]}])
57
-
58
- should("pass when unique index found for column set") do
59
- build_assertion("rooms", ["foo", "bar"], true).
60
- evaluate(Room.new, :foo, :bar, :unique => true)
61
- end.equals([:pass, %Q{has unique index on [:foo, :bar]}])
62
-
63
- should("pass when non-unique index found for column") do
64
- build_assertion("rooms", ["foo"], false).
65
- evaluate(Room.new, :foo, :unique => false)
66
- end.equals([:pass, %Q{has index on [:foo]}])
67
-
68
- should("pass when non-unique index found for column set") do
69
- build_assertion("rooms", ["foo", "bar"], false).
70
- evaluate(Room.new, :foo, :bar, :unique => false)
71
- end.equals([:pass, %Q{has index on [:foo, :bar]}])
72
-
73
- end # The attribute_is_invalid macro
@@ -1,22 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The has_many assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("pass when record has a has_many association defined for attribute") do
8
- topic.has_many(:doors).run(Riot::Situation.new)
9
- end.equals([:pass, ":doors is a has_many association"])
10
-
11
- should("fail when record does not have a has_many association defined for attribute") do
12
- topic.has_many(:windows).run(Riot::Situation.new)
13
- end.equals([:fail, ":windows is not a has_many association", blah, blah])
14
-
15
- should("fail when attribute is not a has_many, but is a has_one association") do
16
- topic.has_many(:floor).run(Riot::Situation.new)
17
- end.equals([:fail, ":floor is not a has_many association", blah, blah])
18
-
19
- should("fail when association options are specified, but they do not match the record") do
20
- topic.has_many(:doors, :class_name => "Portal").run(Riot::Situation.new)
21
- end.equals([:fail, %q[expected has_many :doors with {:class_name=>"Portal"}], blah, blah])
22
- end # The has_many assertion macro
@@ -1,22 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The has_one assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("pass when record has a has_one association defined for attribute") do
8
- topic.has_one(:floor).run(Riot::Situation.new)
9
- end.equals([:pass, ":floor is a has_one association"])
10
-
11
- should("fail when record does not have a has_one association defined for attribute") do
12
- topic.has_one(:windows).run(Riot::Situation.new)
13
- end.equals([:fail, ":windows is not a has_one association", blah, blah])
14
-
15
- should("fail when attribute is not a has_one, but is a has_many association") do
16
- topic.has_one(:doors).run(Riot::Situation.new)
17
- end.equals([:fail, ":doors is not a has_one association", blah, blah])
18
-
19
- should("fail when association options are specified, but they do not match the record") do
20
- topic.has_one(:floor, :class_name => "Surface").run(Riot::Situation.new)
21
- end.equals([:fail, %q[expected has_one :floor with {:class_name=>"Surface"}], blah, blah])
22
- end # The has_one assertion macro
@@ -1,31 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The validates_length_of assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("fail when minimum length causes an error") do
8
- topic.validates_length_of(:name, (4..15)).run(Riot::Situation.new)
9
- end.equals([:fail, ":name should be able to be 4 characters", blah, blah])
10
-
11
- should("fail when value less than minimum value does not cause an error") do
12
- topic.validates_length_of(:name, (6..15)).run(Riot::Situation.new)
13
- end.equals([:fail, ":name expected to be more than 5 characters", blah, blah])
14
-
15
- should("fail when maximum length causes an error") do
16
- topic.validates_length_of(:name, (5..21)).run(Riot::Situation.new)
17
- end.equals([:fail, ":name should be able to be 21 characters", blah, blah])
18
-
19
- should("fail when value greater than maximum value does not cause an error") do
20
- topic.validates_length_of(:name, (5..19)).run(Riot::Situation.new)
21
- end.equals([:fail, ":name expected to be less than 20 characters", blah, blah])
22
-
23
- should("pass when only a value can only be within the specific range") do
24
- topic.validates_length_of(:name, (5..20)).run(Riot::Situation.new)
25
- end.equals([:pass, "validates length of :name is within 5..20"])
26
-
27
- should("pass even when minimum value is zero") do
28
- topic.validates_length_of(:contents, (0..100)).run(Riot::Situation.new)
29
- end.equals([:pass, "validates length of :contents is within 0..100"])
30
-
31
- end # The validates_length_of assertion macro
@@ -1,14 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The validates_presence_of assertion macro" do
4
- setup_test_context
5
- setup { topic.asserts("room") { Room.new } }
6
-
7
- should("pass when attribute requires presence") do
8
- topic.validates_presence_of(:location).run(Riot::Situation.new)
9
- end.equals([:pass, "validates presence of :location"])
10
-
11
- should("fail when attribute does not require presence") do
12
- topic.validates_presence_of(:contents).run(Riot::Situation.new)
13
- end.equals([:fail, "expected to validate presence of :contents", blah, blah])
14
- end # The validates_presence_of assertion macro
@@ -1,23 +0,0 @@
1
- require 'teststrap'
2
-
3
- context "The validates_uniqueness_of assertion macro" do
4
- setup_test_context
5
-
6
- should("fail without a persisted record") do
7
- topic.asserts("room") do
8
- Room.new(:email => "foo@bar.baz")
9
- end.validates_uniqueness_of(:email).run(Riot::Situation.new)
10
- end.equals([:fail, "must use a persisted record when testing uniqueness of :email", blah, blah])
11
-
12
- should("pass with a persisted record") do
13
- topic.asserts("room") do
14
- Room.create_with_good_data(:email => "foo@bar.baz")
15
- end.validates_uniqueness_of(:email).run(Riot::Situation.new)
16
- end.equals([:pass, ":email is unique"])
17
-
18
- should("fail with a persisted record but not validating uniqueness") do
19
- topic.asserts("room") do
20
- Room.create_with_good_data(:email => "goo@car.caz")
21
- end.validates_uniqueness_of(:foo).run(Riot::Situation.new)
22
- end.equals([:fail, "expected to fail because :foo is not unique", blah, blah])
23
- end # The validates_uniqueness_of assertion macro
@@ -1,21 +0,0 @@
1
- class GremlinsController < ActionController::Base
2
- def index
3
- render :text => "bar"
4
- end
5
-
6
- def show
7
- render :text => "show me the money"
8
- end
9
-
10
- def create
11
- render :text => "makin' money"
12
- end
13
-
14
- def update
15
- render :text => "savin' money"
16
- end
17
-
18
- def destroy
19
- render :text => "spendin' money"
20
- end
21
- end