ampere 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/CHANGELOG.md +15 -0
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +36 -26
  4. data/README.md +25 -11
  5. data/Rakefile +10 -0
  6. data/VERSION +1 -1
  7. data/ampere.gemspec +83 -9
  8. data/example/.gitignore +5 -0
  9. data/example/.rspec +1 -0
  10. data/example/Gemfile +21 -0
  11. data/example/Gemfile.lock +143 -0
  12. data/example/README +261 -0
  13. data/example/Rakefile +7 -0
  14. data/example/app/assets/images/rails.png +0 -0
  15. data/example/app/assets/javascripts/application.js +9 -0
  16. data/example/app/assets/javascripts/posts.js.coffee +3 -0
  17. data/example/app/assets/stylesheets/application.css +7 -0
  18. data/example/app/assets/stylesheets/posts.css.scss +3 -0
  19. data/example/app/assets/stylesheets/scaffolds.css.scss +56 -0
  20. data/example/app/controllers/application_controller.rb +3 -0
  21. data/example/app/controllers/posts_controller.rb +83 -0
  22. data/example/app/helpers/application_helper.rb +2 -0
  23. data/example/app/helpers/posts_helper.rb +2 -0
  24. data/example/app/mailers/.gitkeep +0 -0
  25. data/example/app/models/.gitkeep +0 -0
  26. data/example/app/models/post.rb +7 -0
  27. data/example/app/views/layouts/application.html.erb +14 -0
  28. data/example/app/views/posts/_form.html.erb +25 -0
  29. data/example/app/views/posts/edit.html.erb +6 -0
  30. data/example/app/views/posts/index.html.erb +25 -0
  31. data/example/app/views/posts/new.html.erb +5 -0
  32. data/example/app/views/posts/show.html.erb +15 -0
  33. data/example/config/ampere.yml +11 -0
  34. data/example/config/application.rb +54 -0
  35. data/example/config/boot.rb +6 -0
  36. data/example/config/environment.rb +5 -0
  37. data/example/config/environments/development.rb +30 -0
  38. data/example/config/environments/production.rb +60 -0
  39. data/example/config/environments/test.rb +39 -0
  40. data/example/config/initializers/backtrace_silencers.rb +7 -0
  41. data/example/config/initializers/inflections.rb +10 -0
  42. data/example/config/initializers/mime_types.rb +5 -0
  43. data/example/config/initializers/secret_token.rb +7 -0
  44. data/example/config/initializers/session_store.rb +8 -0
  45. data/example/config/initializers/wrap_parameters.rb +10 -0
  46. data/example/config/locales/en.yml +5 -0
  47. data/example/config/routes.rb +60 -0
  48. data/example/config.ru +4 -0
  49. data/example/db/seeds.rb +7 -0
  50. data/example/lib/assets/.gitkeep +0 -0
  51. data/example/lib/tasks/.gitkeep +0 -0
  52. data/example/log/.gitkeep +0 -0
  53. data/example/public/404.html +26 -0
  54. data/example/public/422.html +26 -0
  55. data/example/public/500.html +26 -0
  56. data/example/public/favicon.ico +0 -0
  57. data/example/public/index.html +241 -0
  58. data/example/public/robots.txt +5 -0
  59. data/example/script/rails +6 -0
  60. data/example/spec/controllers/posts_controller_spec.rb +164 -0
  61. data/example/spec/helpers/posts_helper_spec.rb +15 -0
  62. data/example/spec/models/post_spec.rb +5 -0
  63. data/example/spec/requests/posts_spec.rb +11 -0
  64. data/example/spec/routing/posts_routing_spec.rb +35 -0
  65. data/example/spec/spec_helper.rb +34 -0
  66. data/example/spec/views/posts/edit.html.erb_spec.rb +20 -0
  67. data/example/spec/views/posts/index.html.erb_spec.rb +23 -0
  68. data/example/spec/views/posts/new.html.erb_spec.rb +20 -0
  69. data/example/spec/views/posts/show.html.erb_spec.rb +17 -0
  70. data/example/vendor/assets/stylesheets/.gitkeep +0 -0
  71. data/example/vendor/plugins/.gitkeep +0 -0
  72. data/lib/ampere/collection.rb +6 -0
  73. data/lib/ampere/keys.rb +37 -0
  74. data/lib/ampere/model.rb +117 -58
  75. data/lib/ampere/timestamps.rb +23 -0
  76. data/lib/ampere.rb +17 -1
  77. data/lib/rails/generators/ampere/config/config_generator.rb +15 -0
  78. data/lib/rails/generators/ampere/config/templates/ampere.yml +11 -0
  79. data/lib/rails/generators/ampere/model/model_generator.rb +27 -0
  80. data/lib/rails/generators/ampere/model/templates/model.rb.tt +10 -0
  81. data/lib/rails/railtie.rb +49 -0
  82. data/lib/rails/tasks/ampere.rake +7 -0
  83. data/spec/models/model_spec.rb +12 -2
  84. data/spec/models/timestamps_spec.rb +45 -0
  85. data/spec/module/collections_spec.rb +5 -0
  86. data/spec/spec_helper.rb +1 -0
  87. metadata +153 -29
@@ -0,0 +1,164 @@
1
+ require 'spec_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ describe PostsController do
22
+
23
+ # This should return the minimal set of attributes required to create a valid
24
+ # Post. As you add validations to Post, be sure to
25
+ # update the return value of this method accordingly.
26
+ def valid_attributes
27
+ {}
28
+ end
29
+
30
+ # This should return the minimal set of values that should be in the session
31
+ # in order to pass any filters (e.g. authentication) defined in
32
+ # PostsController. Be sure to keep this updated too.
33
+ def valid_session
34
+ {}
35
+ end
36
+
37
+ describe "GET index" do
38
+ it "assigns all posts as @posts" do
39
+ post = Post.create! valid_attributes
40
+ get :index, {}, valid_session
41
+ assigns(:posts).to_a.should eq([post])
42
+ end
43
+ end
44
+
45
+ describe "GET show" do
46
+ it "assigns the requested post as @post" do
47
+ post = Post.create! valid_attributes
48
+ get :show, {:id => post.to_param}, valid_session
49
+ assigns(:post).should eq(post)
50
+ end
51
+ end
52
+
53
+ describe "GET new" do
54
+ it "assigns a new post as @post" do
55
+ get :new, {}, valid_session
56
+ assigns(:post).should be_a_new(Post)
57
+ end
58
+ end
59
+
60
+ describe "GET edit" do
61
+ it "assigns the requested post as @post" do
62
+ post = Post.create! valid_attributes
63
+ get :edit, {:id => post.to_param}, valid_session
64
+ assigns(:post).should eq(post)
65
+ end
66
+ end
67
+
68
+ describe "POST create" do
69
+ describe "with valid params" do
70
+ it "creates a new Post" do
71
+ expect {
72
+ post :create, {:post => valid_attributes}, valid_session
73
+ }.to change(Post, :count).by(1)
74
+ end
75
+
76
+ it "assigns a newly created post as @post" do
77
+ post :create, {:post => valid_attributes}, valid_session
78
+ assigns(:post).should be_a(Post)
79
+ assigns(:post).should be_persisted
80
+ end
81
+
82
+ it "redirects to the created post" do
83
+ post :create, {:post => valid_attributes}, valid_session
84
+ response.should redirect_to(Post.last)
85
+ end
86
+ end
87
+
88
+ describe "with invalid params" do
89
+ it "assigns a newly created but unsaved post as @post" do
90
+ # Trigger the behavior that occurs when invalid params are submitted
91
+ Post.any_instance.stub(:save).and_return(false)
92
+ post :create, {:post => {}}, valid_session
93
+ assigns(:post).should be_a_new(Post)
94
+ end
95
+
96
+ it "re-renders the 'new' template" do
97
+ # Trigger the behavior that occurs when invalid params are submitted
98
+ Post.any_instance.stub(:save).and_return(false)
99
+ post :create, {:post => {}}, valid_session
100
+ response.should render_template("new")
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "PUT update" do
106
+ describe "with valid params" do
107
+ it "updates the requested post" do
108
+ post = Post.create! valid_attributes
109
+ # Assuming there are no other posts in the database, this
110
+ # specifies that the Post created on the previous line
111
+ # receives the :update_attributes message with whatever params are
112
+ # submitted in the request.
113
+ Post.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
114
+ put :update, {:id => post.to_param, :post => {'these' => 'params'}}, valid_session
115
+ end
116
+
117
+ it "assigns the requested post as @post" do
118
+ post = Post.create! valid_attributes
119
+ put :update, {:id => post.to_param, :post => valid_attributes}, valid_session
120
+ assigns(:post).should eq(post)
121
+ end
122
+
123
+ it "redirects to the post" do
124
+ post = Post.create! valid_attributes
125
+ put :update, {:id => post.to_param, :post => valid_attributes}, valid_session
126
+ response.should redirect_to(post)
127
+ end
128
+ end
129
+
130
+ describe "with invalid params" do
131
+ it "assigns the post as @post" do
132
+ post = Post.create! valid_attributes
133
+ # Trigger the behavior that occurs when invalid params are submitted
134
+ Post.any_instance.stub(:save).and_return(false)
135
+ put :update, {:id => post.to_param, :post => {}}, valid_session
136
+ assigns(:post).should eq(post)
137
+ end
138
+
139
+ it "re-renders the 'edit' template" do
140
+ post = Post.create! valid_attributes
141
+ # Trigger the behavior that occurs when invalid params are submitted
142
+ Post.any_instance.stub(:save).and_return(false)
143
+ put :update, {:id => post.to_param, :post => {}}, valid_session
144
+ response.should render_template("edit")
145
+ end
146
+ end
147
+ end
148
+
149
+ describe "DELETE destroy" do
150
+ it "destroys the requested post" do
151
+ post = Post.create! valid_attributes
152
+ expect {
153
+ delete :destroy, {:id => post.to_param}, valid_session
154
+ }.to change(Post, :count).by(-1)
155
+ end
156
+
157
+ it "redirects to the posts list" do
158
+ post = Post.create! valid_attributes
159
+ delete :destroy, {:id => post.to_param}, valid_session
160
+ response.should redirect_to(posts_url)
161
+ end
162
+ end
163
+
164
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the PostsHelper. For example:
5
+ #
6
+ # describe PostsHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe PostsHelper do
14
+ pending "add some examples to (or delete) #{__FILE__}"
15
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Post do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Posts" do
4
+ describe "GET /posts" do
5
+ it "works! (now write some real specs)" do
6
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
7
+ get posts_path
8
+ response.status.should be(200)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe PostsController do
4
+ describe "routing" do
5
+
6
+ it "routes to #index" do
7
+ get("/posts").should route_to("posts#index")
8
+ end
9
+
10
+ it "routes to #new" do
11
+ get("/posts/new").should route_to("posts#new")
12
+ end
13
+
14
+ it "routes to #show" do
15
+ get("/posts/1").should route_to("posts#show", :id => "1")
16
+ end
17
+
18
+ it "routes to #edit" do
19
+ get("/posts/1/edit").should route_to("posts#edit", :id => "1")
20
+ end
21
+
22
+ it "routes to #create" do
23
+ post("/posts").should route_to("posts#create")
24
+ end
25
+
26
+ it "routes to #update" do
27
+ put("/posts/1").should route_to("posts#update", :id => "1")
28
+ end
29
+
30
+ it "routes to #destroy" do
31
+ delete("/posts/1").should route_to("posts#destroy", :id => "1")
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ # ## Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+
28
+ # If true, the base class of anonymous controllers will be inferred
29
+ # automatically. This will be the default behavior in future versions of
30
+ # rspec-rails.
31
+ config.infer_base_class_for_anonymous_controllers = false
32
+ end
33
+
34
+ Ampere.flush
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/edit" do
4
+ before(:each) do
5
+ @post = assign(:post, stub_model(Post,
6
+ :title => "MyString",
7
+ :body => "MyString"
8
+ ))
9
+ end
10
+
11
+ it "renders the edit post form" do
12
+ render
13
+
14
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
15
+ assert_select "form", :action => posts_path(@post), :method => "post" do
16
+ assert_select "input#post_title", :name => "post[title]"
17
+ assert_select "input#post_body", :name => "post[body]"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/index" do
4
+ before(:each) do
5
+ assign(:posts, [
6
+ stub_model(Post,
7
+ :title => "Title",
8
+ :body => "Body"
9
+ ),
10
+ stub_model(Post,
11
+ :title => "Title",
12
+ :body => "Body"
13
+ )
14
+ ])
15
+ end
16
+
17
+ it "renders a list of posts" do
18
+ render
19
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
20
+ assert_select "tr>td", :text => "Title".to_s, :count => 2
21
+ assert_select "tr>td", :text => "Body".to_s, :count => 2
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/new" do
4
+ before(:each) do
5
+ assign(:post, stub_model(Post,
6
+ :title => "MyString",
7
+ :body => "MyString"
8
+ ).as_new_record)
9
+ end
10
+
11
+ it "renders new post form" do
12
+ render
13
+
14
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
15
+ assert_select "form", :action => posts_path, :method => "post" do
16
+ assert_select "input#post_title", :name => "post[title]"
17
+ assert_select "input#post_body", :name => "post[body]"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/show" do
4
+ before(:each) do
5
+ @post = assign(:post, stub_model(Post,
6
+ :title => "Title",
7
+ :body => "Body"
8
+ ))
9
+ end
10
+
11
+ it "renders attributes in <p>" do
12
+ render
13
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
14
+ rendered.should match(/Title/)
15
+ rendered.should match(/Body/)
16
+ end
17
+ end
File without changes
File without changes
@@ -47,6 +47,12 @@ module Ampere
47
47
  self[-1]
48
48
  end
49
49
 
50
+ def ==(other)
51
+ if other.is_a?(Array) then
52
+ to_a == other
53
+ end
54
+ end
55
+
50
56
  # Class methods ###########################################################
51
57
 
52
58
 
@@ -0,0 +1,37 @@
1
+ # These are just utlity functions used by Ampere internally to generate Redis
2
+ # keys for various Ampere functions, for DRY excellence.
3
+ module Ampere #:nodoc:
4
+ module Keys #:nodoc:
5
+ # These methods get mixed in to class and instance
6
+ def self.included(base)
7
+ # base.extend(ClassMethods)
8
+ base.extend(self)
9
+ end
10
+
11
+ def key_for_find(parent_model, id)
12
+ unless id =~ /\./
13
+ id = "#{parent_model.to_s.downcase}.#{id}"
14
+ end
15
+ id
16
+ end
17
+
18
+ def key_for_has_many(parent_model, id, field)
19
+ [parent_model, id, 'has_many', field].flatten.join('.')
20
+ end
21
+
22
+ def key_for_index(field)
23
+ ['ampere', 'index', model_name.downcase, field].flatten.join('.')
24
+ end
25
+
26
+ private
27
+
28
+ def model_name
29
+ if self.class == Class then
30
+ to_s
31
+ else
32
+ self.class.to_s
33
+ end
34
+ end
35
+
36
+ end
37
+ end