resourcy-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/LICENSE +25 -0
  2. data/lib/resourcy/engine.rb +4 -0
  3. data/lib/resourcy/rails.rb +4 -0
  4. data/lib/resourcy/version.rb +3 -0
  5. data/lib/resourcy-rails.rb +1 -0
  6. data/spec/dummy/Rakefile +7 -0
  7. data/spec/dummy/app/assets/javascripts/jquery-1.7.1.js +9266 -0
  8. data/spec/dummy/app/assets/javascripts/jquery-1.8.0.js +9227 -0
  9. data/spec/dummy/app/controllers/posts_controller.rb +85 -0
  10. data/spec/dummy/app/models/post.rb +3 -0
  11. data/spec/dummy/app/views/posts/_form.html.erb +25 -0
  12. data/spec/dummy/app/views/posts/edit.html.erb +6 -0
  13. data/spec/dummy/app/views/posts/index.html.erb +25 -0
  14. data/spec/dummy/app/views/posts/new.html.erb +5 -0
  15. data/spec/dummy/app/views/posts/show.html.erb +15 -0
  16. data/spec/dummy/config/application.rb +63 -0
  17. data/spec/dummy/config/boot.rb +9 -0
  18. data/spec/dummy/config/database.yml +10 -0
  19. data/spec/dummy/config/environment.rb +5 -0
  20. data/spec/dummy/config/environments/development.rb +37 -0
  21. data/spec/dummy/config/environments/test.rb +37 -0
  22. data/spec/dummy/config/evergreen.rb +47 -0
  23. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/spec/dummy/config/initializers/inflections.rb +15 -0
  25. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  26. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  27. data/spec/dummy/config/initializers/session_store.rb +8 -0
  28. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  29. data/spec/dummy/config/locales/en.yml +5 -0
  30. data/spec/dummy/config/routes.rb +64 -0
  31. data/spec/dummy/config.ru +4 -0
  32. data/spec/dummy/db/development.sqlite3 +0 -0
  33. data/spec/dummy/db/migrate/20120825050219_create_posts.rb +10 -0
  34. data/spec/dummy/db/structure.sql +4 -0
  35. data/spec/dummy/log/.gitkeep +0 -0
  36. data/spec/dummy/public/index.html +12 -0
  37. data/spec/dummy/script/rails +6 -0
  38. data/spec/javascripts/jquery.resourcy_spec.js.coffee +399 -0
  39. data/spec/javascripts/resourcy_spec.js.coffee +177 -0
  40. data/spec/javascripts/spec_helper.js +37 -0
  41. data/spec/javascripts/templates/ujs.html +3 -0
  42. data/vendor/assets/javascripts/jquery.resourcy.js.coffee +37 -0
  43. data/vendor/assets/javascripts/resourcy.js.coffee +104 -0
  44. metadata +229 -0
@@ -0,0 +1,85 @@
1
+ class PostsController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ # GET /posts
5
+ # GET /posts.json
6
+ def index
7
+ @posts = Post.all
8
+
9
+ respond_to do |format|
10
+ format.html # index.html.erb
11
+ format.json { render json: @posts }
12
+ end
13
+ end
14
+
15
+ # GET /posts/1
16
+ # GET /posts/1.json
17
+ def show
18
+ @post = Post.find(params[:id])
19
+
20
+ respond_to do |format|
21
+ format.html # show.html.erb
22
+ format.json { render json: @post }
23
+ end
24
+ end
25
+
26
+ # GET /posts/new
27
+ # GET /posts/new.json
28
+ def new
29
+ @post = Post.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.json { render json: @post }
34
+ end
35
+ end
36
+
37
+ # GET /posts/1/edit
38
+ def edit
39
+ @post = Post.find(params[:id])
40
+ end
41
+
42
+ # POST /posts
43
+ # POST /posts.json
44
+ def create
45
+ @post = Post.new(params[:post])
46
+
47
+ respond_to do |format|
48
+ if @post.save
49
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
50
+ format.json { render json: @post, status: :created, location: @post }
51
+ else
52
+ format.html { render action: "new" }
53
+ format.json { render json: @post.errors, status: :unprocessable_entity }
54
+ end
55
+ end
56
+ end
57
+
58
+ # PUT /posts/1
59
+ # PUT /posts/1.json
60
+ def update
61
+ @post = Post.find(params[:id])
62
+
63
+ respond_to do |format|
64
+ if @post.update_attributes(params[:post])
65
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
66
+ format.json { head :no_content }
67
+ else
68
+ format.html { render action: "edit" }
69
+ format.json { render json: @post.errors, status: :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /posts/1
75
+ # DELETE /posts/1.json
76
+ def destroy
77
+ @post = Post.find(params[:id])
78
+ @post.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to posts_url }
82
+ format.json { head :no_content }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ attr_accessible :content, :title
3
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@post) do |f| %>
2
+ <% if @post.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @post.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br />
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :content %><br />
20
+ <%= f.text_area :content %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @post %> |
6
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing posts</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Title</th>
6
+ <th>Content</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @posts.each do |post| %>
13
+ <tr>
14
+ <td><%= post.title %></td>
15
+ <td><%= post.content %></td>
16
+ <td><%= link_to 'Show', post %></td>
17
+ <td><%= link_to 'Edit', edit_post_path(post) %></td>
18
+ <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= link_to 'New Post', new_post_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Title:</b>
5
+ <%= @post.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Content:</b>
10
+ <%= @post.content %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_post_path(@post) %> |
15
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+ require 'evergreen/rails'
5
+
6
+ if defined?(Bundler)
7
+ # If you precompile assets before deploying to production, use this line
8
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
9
+ # If you want your assets lazily compiled in production, use this line
10
+ # Bundler.require(:default, :assets, Rails.env)
11
+ end
12
+
13
+ module Dummy
14
+ class Application < Rails::Application
15
+ # Settings in config/environments/* take precedence over those specified here.
16
+ # Application configuration should go into files in config/initializers
17
+ # -- all .rb files in that directory are automatically loaded.
18
+
19
+ # Custom directories with classes and modules you want to be autoloadable.
20
+ # config.autoload_paths += %W(#{config.root}/extras)
21
+
22
+ # Only load the plugins named here, in the order given (default is alphabetical).
23
+ # :all can be used as a placeholder for all plugins not explicitly named.
24
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25
+
26
+ # Activate observers that should always be running.
27
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28
+
29
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31
+ # config.time_zone = 'Central Time (US & Canada)'
32
+
33
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35
+ # config.i18n.default_locale = :de
36
+
37
+ # Configure the default encoding used in templates for Ruby 1.9.
38
+ config.encoding = "utf-8"
39
+
40
+ # Configure sensitive parameters which will be filtered from the log file.
41
+ config.filter_parameters += [:password]
42
+
43
+ # Enable escaping HTML in JSON.
44
+ config.active_support.escape_html_entities_in_json = true
45
+
46
+ # Use SQL instead of Active Record's schema dumper when creating the database.
47
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
48
+ # like if you have constraints or database-specific column types
49
+ config.active_record.schema_format = :sql
50
+
51
+ # Enforce whitelist mode for mass assignment.
52
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
53
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
54
+ # parameters by using an attr_accessible or attr_protected declaration.
55
+ config.active_record.whitelist_attributes = true
56
+
57
+ # Enable the asset pipeline
58
+ config.assets.enabled = true
59
+
60
+ # Version of your assets, change this if you want to expire all your assets
61
+ config.assets.version = '1.0'
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
2
+
3
+ if File.exist?(gemfile)
4
+ ENV['BUNDLE_GEMFILE'] = gemfile
5
+ require 'bundler'
6
+ Bundler.setup
7
+ end
8
+
9
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: sqlite3
9
+ database: ":memory:"
10
+ timeout: 500
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ #config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
37
+ end
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,47 @@
1
+ # The following allows us to have a nested directory structure of specs. With
2
+ # a lot of specs this is needed.
3
+ Evergreen.configure do |config|
4
+ config.root = Resourcy::Engine.root
5
+ end
6
+
7
+ module Evergreen
8
+ class Suite
9
+ def specs
10
+ Dir.glob(File.join(root, Evergreen.spec_dir, '**', '*_spec.{js,coffee,js.coffee}')).map do |path|
11
+ Spec.new(self, path.gsub(File.join(root), ''))
12
+ end
13
+ end
14
+
15
+ def templates
16
+ Dir.glob(File.join(root, Evergreen.template_dir, '**', '*')).map do |path|
17
+ Template.new(self, path.gsub(File.join(root), '')) unless File.directory?(path)
18
+ end.compact
19
+ end
20
+ end
21
+ end
22
+
23
+ module Evergreen
24
+ class Spec
25
+ def initialize(suite, name)
26
+ @suite = suite
27
+ @name = name
28
+ @name = "#{Evergreen.spec_dir}/#{name}" if !exist?
29
+ end
30
+
31
+ def name
32
+ @name.gsub("/#{Evergreen.spec_dir}/", '')
33
+ end
34
+ end
35
+ end
36
+
37
+ module Evergreen
38
+ class Template
39
+ def name
40
+ @name.gsub("/#{Evergreen.template_dir}/", '')
41
+ end
42
+
43
+ def full_path
44
+ File.join(root, @name)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '990bac5b6d4f068883259503539cad4e9ec00f137986fcbc718a1e0b645af7a3eb0340468f8fae09958a6281190396d65789b6316af61e47a8cbda3c8c071a0e'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,64 @@
1
+ Dummy::Application.routes.draw do
2
+ resources :posts
3
+
4
+ match 'blogs/:id/posts' => 'posts#index'
5
+
6
+
7
+ # The priority is based upon order of creation:
8
+ # first created -> highest priority.
9
+
10
+ # Sample of regular route:
11
+ # match 'products/:id' => 'catalog#view'
12
+ # Keep in mind you can assign values other than :controller and :action
13
+
14
+ # Sample of named route:
15
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
16
+ # This route can be invoked with purchase_url(:id => product.id)
17
+
18
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
19
+ # resources :products
20
+
21
+ # Sample resource route with options:
22
+ # resources :products do
23
+ # member do
24
+ # get 'short'
25
+ # post 'toggle'
26
+ # end
27
+ #
28
+ # collection do
29
+ # get 'sold'
30
+ # end
31
+ # end
32
+
33
+ # Sample resource route with sub-resources:
34
+ # resources :products do
35
+ # resources :comments, :sales
36
+ # resource :seller
37
+ # end
38
+
39
+ # Sample resource route with more complex sub-resources
40
+ # resources :products do
41
+ # resources :comments
42
+ # resources :sales do
43
+ # get 'recent', :on => :collection
44
+ # end
45
+ # end
46
+
47
+ # Sample resource route within a namespace:
48
+ # namespace :admin do
49
+ # # Directs /admin/products/* to Admin::ProductsController
50
+ # # (app/controllers/admin/products_controller.rb)
51
+ # resources :products
52
+ # end
53
+
54
+ # You can have the root of your site routed with "root"
55
+ # just remember to delete public/index.html.
56
+ # root :to => 'welcome#index'
57
+
58
+ # See how all your routes lay out with "rake routes"
59
+
60
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
61
+ # Note: This route will make all actions in every controller accessible via GET requests.
62
+ # match ':controller(/:action(/:id))(.:format)'
63
+
64
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
Binary file
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :content
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "content" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
2
+ CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
3
+ CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
4
+ INSERT INTO schema_migrations (version) VALUES ('20120825050219');
File without changes
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Resourcy Regression Testing</title>
6
+ <script src="/assets/jquery-1.8.0.js" type="text/javascript"></script>
7
+ <script src="/assets/resourcy.jquery.js" type="text/javascript"></script>
8
+ </head>
9
+ <body>
10
+
11
+ </body>
12
+ </html>
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'