Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Provider & rd_searchlogic GEM

  • Loading branch information...
commit d3dec91b250c80d8c5b552eef120abe54040f3fa 1 parent efab805
Easy.n xEasy authored

Showing 42 changed files with 448 additions and 9 deletions. Show diff stats Hide diff stats

  1. +2 0  Gemfile
  2. +3 0  Gemfile.lock
  3. +27 0 app/controllers/application_controller.rb
  4. +16 0 app/controllers/homes_controller.rb
  5. +1 0  app/models/classes.rb
  6. +9 0 app/models/student.rb
  7. +4 0 app/models/teacher.rb
  8. +7 2 app/views/layouts/application.html.erb
  9. +4 0 config/routes.rb
  10. BIN  public/images/Thumbs.db
  11. 0  public/images/{dock-bg.gif → dock-bg (复件).gif}
  12. 0  public/images/{dock-bg2.gif → dock-bg2 (复件).gif}
  13. BIN  public/images/opacity.png
  14. +8 5 public/javascripts/PF/pages/home_index.js
  15. +2 2 public/stylesheets/menu-style.css
  16. +20 0 vendor/plugins/provider/MIT-LICENSE
  17. +13 0 vendor/plugins/provider/README
  18. +23 0 vendor/plugins/provider/Rakefile
  19. +4 0 vendor/plugins/provider/init.rb
  20. +2 0  vendor/plugins/provider/install.rb
  21. +66 0 vendor/plugins/provider/lib/provider.rb
  22. +9 0 vendor/plugins/provider/spec/Gemfile
  23. +3 0  vendor/plugins/provider/spec/app_root/app/controllers/application_controller.rb
  24. +3 0  vendor/plugins/provider/spec/app_root/app/models/pastry.rb
  25. +33 0 vendor/plugins/provider/spec/app_root/config/application.rb
  26. +14 0 vendor/plugins/provider/spec/app_root/config/boot.rb
  27. +16 0 vendor/plugins/provider/spec/app_root/config/database.yml
  28. +6 0 vendor/plugins/provider/spec/app_root/config/environment.rb
  29. +1 0  vendor/plugins/provider/spec/app_root/config/environments/in_memory.rb
  30. +36 0 vendor/plugins/provider/spec/app_root/config/environments/test.rb
  31. +2 0  vendor/plugins/provider/spec/app_root/config/initializers/secret_token.rb
  32. +2 0  vendor/plugins/provider/spec/app_root/config/initializers/session_token.rb
  33. +2 0  vendor/plugins/provider/spec/app_root/config/locales/en.yml
  34. +4 0 vendor/plugins/provider/spec/app_root/config/routes.rb
  35. +13 0 vendor/plugins/provider/spec/app_root/db/migrate/20110306020802_create_pastries.rb
  36. +6 0 vendor/plugins/provider/spec/app_root/script/rails
  37. +11 0 vendor/plugins/provider/spec/app_root/test/fixtures/pastries.yml
  38. +9 0 vendor/plugins/provider/spec/app_root/test/unit/pastry_test.rb
  39. +39 0 vendor/plugins/provider/spec/provider_spec.rb
  40. +2 0  vendor/plugins/provider/spec/rcov.opts
  41. +24 0 vendor/plugins/provider/spec/spec_helper.rb
  42. +2 0  vendor/plugins/provider/uninstall.rb
2  Gemfile
@@ -9,6 +9,8 @@ gem "mysql2", "0.2.7"
9 9 gem "devise"
10 10 gem "mongrel", ">=1.2.0.pre2"
11 11 gem "rake", "0.8.7"
  12 +gem 'rd_searchlogic', '3.0.1', :require => 'searchlogic'
  13 +
12 14 # Use unicorn as the web server
13 15 # gem 'unicorn'
14 16
3  Gemfile.lock
@@ -71,6 +71,8 @@ GEM
71 71 rake (>= 0.8.7)
72 72 thor (~> 0.14.4)
73 73 rake (0.8.7)
  74 + rd_searchlogic (3.0.1)
  75 + activerecord (>= 3.0.0)
74 76 thor (0.14.6)
75 77 treetop (1.4.10)
76 78 polyglot
@@ -88,3 +90,4 @@ DEPENDENCIES
88 90 mysql2 (= 0.2.7)
89 91 rails (= 3.0.3)
90 92 rake (= 0.8.7)
  93 + rd_searchlogic (= 3.0.1)
27 app/controllers/application_controller.rb
@@ -6,4 +6,31 @@ class ApplicationController < ActionController::Base
6 6 def render_by_login_session
7 7 is_a?(Devise::SessionsController) ? "login" : "application"
8 8 end
  9 +
  10 + def render_error(error_msg = "",content_type = "application/json")
  11 + logger.info "==Render error : #{error_msg.inspect}=="
  12 + respond_to do |format|
  13 + format.js { render :js => "throw '#{error_msg}';" , :status => :bad_request }
  14 + format.html { render :text => error_msg, :status => :bad_request }
  15 + format.json do
  16 + is_active_record = error_msg.is_a? ActiveRecord::Base
  17 + content = {
  18 + :active_record_error => is_active_record,
  19 + :error_msg => is_active_record ? error_msg.errors.full_messages.join("<br />") : error_msg
  20 + }
  21 + render :json => { :success => false, :message => content }, :status => :bad_request, :content_type => content_type
  22 + #前台调用: Ext.decode(resp.responseText).message.error_msg
  23 + end
  24 + end
  25 + end
  26 +
  27 + def render_json(content, content_type = "application/json")
  28 + render :json => { :success => true, :root => content }, :status => :ok, :content_type => content_type
  29 + end
  30 +
  31 + def fields_provider
  32 + #生成代码块,还用到插件解析fields
  33 + Proc.new { |o| o.provide params[:fields] }
  34 + end
  35 +
9 36 end
16 app/controllers/homes_controller.rb
@@ -2,4 +2,20 @@ class HomesController < ApplicationController
2 2 def index
3 3 end
4 4
  5 + def get_classes_students
  6 + render_json Classes.find(params[:c_id]).students.order("#{params[:sort]} #{params[:dir]}").collect &fields_provider
  7 + end
  8 +
  9 + def get_classes
  10 + render_json Classes.where("name like ?", "%#{params[:query]}%").collect &fields_provider
  11 + end
  12 +
  13 + def student_detail
  14 + render_json Student.find(params[:s_id]).detail
  15 + end
  16 +
  17 + def student_score
  18 + render_json Student.find(params[:s_id]).provide params[:fields]
  19 + end
  20 +
5 21 end
1  app/models/classes.rb
... ... @@ -1,3 +1,4 @@
1 1 class Classes < ActiveRecord::Base
  2 + has_many :students
2 3 has_many :course_scores
3 4 end
9 app/models/student.rb
... ... @@ -0,0 +1,9 @@
  1 +class Student < Person
  2 + belongs_to :classes
  3 +
  4 + def detail
  5 +
  6 + end
  7 +
  8 +end
  9 +
4 app/models/teacher.rb
... ... @@ -0,0 +1,4 @@
  1 +class Teacher < Person
  2 + belongs_to :classes
  3 +
  4 +end
9 app/views/layouts/application.html.erb
@@ -60,13 +60,18 @@
60 60 var menuPanel = new Ext.Panel({
61 61 height : 50,
62 62 region : 'south',
63   - border : false
  63 + border : false,
  64 + bodyStyle : "background : none"
64 65 });
65 66
66 67 Pf.viewPage = new Ext.Viewport({
67 68 layout : 'border',
68 69 autoScroll : true,
69   - items : [ menuPanel, { region: 'center',layout : 'border', items: Pf.pages.currentInstance }]
  70 + items : [
  71 + //{ height : 30, region: 'north',border:false },
  72 + { region: 'center',layout : 'border', border: false,items: Pf.pages.currentInstance },
  73 + menuPanel
  74 + ]
70 75 });
71 76 }
72 77 })
4 config/routes.rb
@@ -2,6 +2,10 @@
2 2 resources :homes do
3 3 collection do
4 4 get "index"
  5 + get "get_classes"
  6 + get 'get_classes_students'
  7 + get 'student_detail'
  8 + get 'student_score'
5 9 end
6 10 end
7 11 resources :settings do
BIN  public/images/Thumbs.db
Binary file not shown
0  public/images/dock-bg.gif → public/images/dock-bg (复件).gif
File renamed without changes
0  public/images/dock-bg2.gif → public/images/dock-bg2 (复件).gif
File renamed without changes
BIN  public/images/opacity.png
13 public/javascripts/PF/pages/home_index.js
@@ -2,7 +2,6 @@ Ext.ns("Pf.classes.homeIndex");
2 2
3 3 Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
4 4 autoScroll : true,
5   - title : '学生信息',
6 5 layout : 'border',
7 6 region : 'center',
8 7
@@ -33,7 +32,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
33 32 createGrid : function() {
34 33 var store = new Pf.util.FieldsJsonStore({
35 34 root : 'root',
36   - url : '#',
  35 + url : '/homes/get_classes_students.json',
37 36 fields : ["id",'name','number']
38 37 });
39 38
@@ -52,23 +51,27 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
52 51 autoSelect : true,
53 52 width : 130,
54 53 forceSelection : true,
55   - lastQuery : '',
56 54 store : new Pf.util.FieldsJsonStore({
57   - url : '#',
  55 + url : '/homes/get_classes.json',
58 56 fields : ["id", "name"],
59 57 autoLoad: false
60 58 }),
61 59 listeners : {
62 60 select : function(combo, record, index) {
  61 + var store = Ext.getCmp("student-grid").getStore();
  62 + store.removeAll();
  63 + store.load({ params : { c_id : record.get("id") } });
63 64 }
64 65 }
65 66 });
66 67
67 68 var grid = new Ext.grid.EditorGridPanel({
  69 + id : 'student-grid',
68 70 store: store,
69 71 cm : cm,
70 72 border: false,
71 73 containerScroll: true,
  74 + loadMask : true,
72 75 width: 200,
73 76 region: 'west',
74 77 split: true,
@@ -117,7 +120,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
117 120 region : 'center',
118 121 frame : true,
119 122 autoScroll : true,
120   - lableWidth: 60,
  123 + lableWidth: 55,
121 124 labelAlign : 'right',
122 125 bodyStyle: 'padding:5px 5px 0',
123 126 items: [{
4 public/stylesheets/menu-style.css
@@ -17,7 +17,7 @@ img {
17 17 .dock-container {
18 18 position: absolute;
19 19 height: 50px;
20   - background: url(../images/dock-bg2.gif);
  20 + /* background: url(../images/dock-bg2.gif); */
21 21 padding-left: 20px;
22 22 }
23 23 a.dock-item {
@@ -50,7 +50,7 @@ a.dock-item {
50 50 .dock-container2 {
51 51 position: absolute;
52 52 height: 50px;
53   - background: url(../images/dock-bg.gif);
  53 + /* background: url(../images/dock-bg.gif); */
54 54 padding-left: 20px;
55 55 }
56 56 a.dock-item2 {
20 vendor/plugins/provider/MIT-LICENSE
... ... @@ -0,0 +1,20 @@
  1 +Copyright (c) 2011 [name of plugin creator]
  2 +
  3 +Permission is hereby granted, free of charge, to any person obtaining
  4 +a copy of this software and associated documentation files (the
  5 +"Software"), to deal in the Software without restriction, including
  6 +without limitation the rights to use, copy, modify, merge, publish,
  7 +distribute, sublicense, and/or sell copies of the Software, and to
  8 +permit persons to whom the Software is furnished to do so, subject to
  9 +the following conditions:
  10 +
  11 +The above copyright notice and this permission notice shall be
  12 +included in all copies or substantial portions of the Software.
  13 +
  14 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18 +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19 +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20 +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 vendor/plugins/provider/README
... ... @@ -0,0 +1,13 @@
  1 +Provider
  2 +========
  3 +
  4 +Introduction goes here.
  5 +
  6 +
  7 +Example
  8 +=======
  9 +
  10 +Example goes here.
  11 +
  12 +
  13 +Copyright (c) 2011 [name of plugin creator], released under the MIT license
23 vendor/plugins/provider/Rakefile
... ... @@ -0,0 +1,23 @@
  1 +require 'rake'
  2 +require 'rake/testtask'
  3 +require 'rake/rdoctask'
  4 +
  5 +desc 'Default: run unit tests.'
  6 +task :default => :test
  7 +
  8 +desc 'Test the provider plugin.'
  9 +Rake::TestTask.new(:test) do |t|
  10 + t.libs << 'lib'
  11 + t.libs << 'test'
  12 + t.pattern = 'test/**/*_test.rb'
  13 + t.verbose = true
  14 +end
  15 +
  16 +desc 'Generate documentation for the provider plugin.'
  17 +Rake::RDocTask.new(:rdoc) do |rdoc|
  18 + rdoc.rdoc_dir = 'rdoc'
  19 + rdoc.title = 'Provider'
  20 + rdoc.options << '--line-numbers' << '--inline-source'
  21 + rdoc.rdoc_files.include('README')
  22 + rdoc.rdoc_files.include('lib/**/*.rb')
  23 +end
4 vendor/plugins/provider/init.rb
... ... @@ -0,0 +1,4 @@
  1 +# -*- encoding : utf-8 -*-
  2 +# Include hook code here
  3 +
  4 +require 'provider'
2  vendor/plugins/provider/install.rb
... ... @@ -0,0 +1,2 @@
  1 +# -*- encoding : utf-8 -*-
  2 +# Install hook code here
66 vendor/plugins/provider/lib/provider.rb
... ... @@ -0,0 +1,66 @@
  1 +# -*- encoding : utf-8 -*-
  2 +# Provider
  3 +# access attribution and association easily
  4 +#
  5 +# Demo:
  6 +# #provide attribution
  7 +# SampleOrder.first.provide("number")
  8 +# #=> { "number" => "LSP11-0001" }
  9 +#
  10 +# #provide association:
  11 +# SampleOrder.last.provide(["number", "customer/number"])
  12 +# #=> { "number" => "LSP11-0002", "customer/number" => "LuluLemon" }
  13 +#
  14 +# Note:
  15 +# only "provide!" will raise exception when the attribution or association can't be provided.
  16 +# for example:
  17 +# SampleOrder.first.provide("abcdefghijk") #=> { "abcdefghijk" => nil }
  18 +# SampleOrder.first.provide!("abcdefghijk") #=> this case will raise exception!
  19 +#
  20 +
  21 +module Provider
  22 + def provide(params)
  23 + provide_action(params, false, false)
  24 + end
  25 +
  26 + def provide!(params)
  27 + provide_action(params, true, false)
  28 + end
  29 +
  30 + def provide_value!(params)
  31 + provide_action(params,true,true)
  32 + end
  33 +
  34 + def provide_value(params)
  35 + provide_action(params,false,true)
  36 + end
  37 +
  38 + private
  39 +
  40 + def provide_action(params,raise_exception,only_value)
  41 + only_value = only_value
  42 + attrs = (params.is_a? Array) ? params : params.to_a
  43 + r = only_value ? [] : {}
  44 + attrs.each do |attr|
  45 + begin
  46 + value = eval("self.#{ attr.gsub('/', '.') }")
  47 + if only_value
  48 + value.to_s
  49 + r.push(value)
  50 + else
  51 + r.update(attr => value )
  52 + end
  53 + rescue NoMethodError
  54 + error_msg = "\033[31m [can't provide] #{self.class.name}#ID='#{id}' can't provide '#{attr}' \033[0m"
  55 + if raise_exception
  56 + raise(error_msg)
  57 + else
  58 + only_value ? r.push(" ") : r.update(attr => nil)
  59 + end
  60 + end
  61 + end
  62 + r
  63 + end
  64 +end
  65 +
  66 +ActiveRecord::Base.send(:include, Provider)
9 vendor/plugins/provider/spec/Gemfile
... ... @@ -0,0 +1,9 @@
  1 +source 'http://rubygems.org'
  2 +
  3 +gem 'sqlite3-ruby', :require => "sqlite3"
  4 +gem 'rails', '3.0.4'
  5 +gem 'rspec'
  6 +gem 'rspec-rails'
  7 +gem 'ruby-debug'
  8 +gem 'mocha'
  9 +
3  vendor/plugins/provider/spec/app_root/app/controllers/application_controller.rb
... ... @@ -0,0 +1,3 @@
  1 +# -*- encoding : utf-8 -*-
  2 +class ApplicationController < ActionController::Base
  3 +end
3  vendor/plugins/provider/spec/app_root/app/models/pastry.rb
... ... @@ -0,0 +1,3 @@
  1 +# -*- encoding : utf-8 -*-
  2 +class Pastry < ActiveRecord::Base
  3 +end
33 vendor/plugins/provider/spec/app_root/config/application.rb
... ... @@ -0,0 +1,33 @@
  1 +# -*- encoding : utf-8 -*-
  2 +require File.expand_path('../boot', __FILE__)
  3 +
  4 +require 'rails/all'
  5 +
  6 +# If you have a Gemfile, require the gems listed there, including any gems
  7 +# you've limited to :test, :development, or :production.
  8 +Bundler.require(:default, Rails.env) if defined?(Bundler)
  9 +
  10 +
  11 +module ProviderSpecApp
  12 + class Application < Rails::Application
  13 + config.encoding = "utf-8"
  14 +
  15 + config.cache_classes = true
  16 + config.whiny_nils = true
  17 +
  18 + config.consider_all_requests_local = true
  19 + config.action_controller.perform_caching = false
  20 +
  21 + config.action_dispatch.show_exceptions = false
  22 +
  23 + config.action_controller.allow_forgery_protection = false
  24 +
  25 + config.action_mailer.delivery_method = :test
  26 +
  27 + config.active_support.deprecation = :stderr
  28 +
  29 + config.root = File.expand_path('../..', __FILE__)
  30 +
  31 + railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
  32 + end
  33 +end
14 vendor/plugins/provider/spec/app_root/config/boot.rb
... ... @@ -0,0 +1,14 @@
  1 +# -*- encoding : utf-8 -*-
  2 +require 'rubygems'
  3 +
  4 +# Set up gems listed in the Gemfile.
  5 +gemfile = File.expand_path('../../Gemfile', __FILE__)
  6 +begin
  7 + ENV['BUNDLE_GEMFILE'] = gemfile
  8 + require 'bundler'
  9 + Bundler.setup
  10 +rescue Bundler::GemNotFound => e
  11 + STDERR.puts e.message
  12 + STDERR.puts "Try running `bundle install`."
  13 + exit!
  14 +end if File.exist?(gemfile)
16 vendor/plugins/provider/spec/app_root/config/database.yml
... ... @@ -0,0 +1,16 @@
  1 +in_memory:
  2 + adapter: sqlite3
  3 + database: ":memory:"
  4 + verbosity: quiet
  5 +
  6 +
  7 +# development:
  8 +# adapter: sqlite3
  9 +# database: db/development.sqlite3
  10 +# pool: 5
  11 +# timeout: 5000
  12 +# test:
  13 +# adapter: sqlite3
  14 +# database: db/development.sqlite3
  15 +# pool: 5
  16 +# timeout: 5000
6 vendor/plugins/provider/spec/app_root/config/environment.rb
... ... @@ -0,0 +1,6 @@
  1 +# -*- encoding : utf-8 -*-
  2 +# Load the rails application
  3 +require File.expand_path('../application', __FILE__)
  4 +
  5 +# Initialize the rails application
  6 +ProviderSpecApp::Application.initialize!
1  vendor/plugins/provider/spec/app_root/config/environments/in_memory.rb
... ... @@ -0,0 +1 @@
  1 +# -*- encoding : utf-8 -*-
36 vendor/plugins/provider/spec/app_root/config/environments/test.rb
... ... @@ -0,0 +1,36 @@
  1 +# -*- encoding : utf-8 -*-
  2 +ProviderSpecApp::Application.configure do
  3 + # Settings specified here will take precedence over those in config/application.rb
  4 +
  5 + # The test environment is used exclusively to run your application's
  6 + # test suite. You never need to work with it otherwise. Remember that
  7 + # your test database is "scratch space" for the test suite and is wiped
  8 + # and recreated between test runs. Don't rely on the data there!
  9 + config.cache_classes = true
  10 +
  11 + # Log error messages when you accidentally call methods on nil.
  12 + config.whiny_nils = true
  13 +
  14 + # Show full error reports and disable caching
  15 + config.consider_all_requests_local = true
  16 + config.action_controller.perform_caching = false
  17 +
  18 + # Raise exceptions instead of rendering exception templates
  19 + config.action_dispatch.show_exceptions = false
  20 +
  21 + # Disable request forgery protection in test environment
  22 + config.action_controller.allow_forgery_protection = false
  23 +
  24 + # Tell Action Mailer not to deliver emails to the real world.
  25 + # The :test delivery method accumulates sent emails in the
  26 + # ActionMailer::Base.deliveries array.
  27 + config.action_mailer.delivery_method = :test
  28 +
  29 + # Use SQL instead of Active Record's schema dumper when creating the test database.
  30 + # This is necessary if your schema can't be completely dumped by the schema dumper,
  31 + # like if you have constraints or database-specific column types
  32 + # config.active_record.schema_format = :sql
  33 +
  34 + # Print deprecation notices to the stderr
  35 + config.active_support.deprecation = :stderr
  36 +end
2  vendor/plugins/provider/spec/app_root/config/initializers/secret_token.rb
... ... @@ -0,0 +1,2 @@
  1 +# -*- encoding : utf-8 -*-
  2 +ProviderSpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
2  vendor/plugins/provider/spec/app_root/config/initializers/session_token.rb
... ... @@ -0,0 +1,2 @@
  1 +# -*- encoding : utf-8 -*-
  2 +ProviderSpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
2  vendor/plugins/provider/spec/app_root/config/locales/en.yml
... ... @@ -0,0 +1,2 @@
  1 +en:
  2 + hello: "Hello world"
4 vendor/plugins/provider/spec/app_root/config/routes.rb
... ... @@ -0,0 +1,4 @@
  1 +# -*- encoding : utf-8 -*-
  2 +ProviderSpecApp::Application.routes.draw do
  3 + match ':controller(/:action(/:id(.:format)))'
  4 +end
13 vendor/plugins/provider/spec/app_root/db/migrate/20110306020802_create_pastries.rb
... ... @@ -0,0 +1,13 @@
  1 +# -*- encoding : utf-8 -*-
  2 +class CreatePastries < ActiveRecord::Migration
  3 + def self.up
  4 + create_table :pastries do |t|
  5 + t.string :name
  6 + t.string :email
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + drop_table :pastries
  12 + end
  13 +end
6 vendor/plugins/provider/spec/app_root/script/rails
... ... @@ -0,0 +1,6 @@
  1 +#!/usr/bin/env ruby1.8
  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'
11 vendor/plugins/provider/spec/app_root/test/fixtures/pastries.yml
... ... @@ -0,0 +1,11 @@
  1 +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2 +
  3 +# This model initially had no columns defined. If you add columns to the
  4 +# model remove the '{}' from the fixture names and add the columns immediately
  5 +# below each fixture, per the syntax in the comments below
  6 +#
  7 +one: {}
  8 +# column: value
  9 +#
  10 +two: {}
  11 +# column: value
9 vendor/plugins/provider/spec/app_root/test/unit/pastry_test.rb
... ... @@ -0,0 +1,9 @@
  1 +# -*- encoding : utf-8 -*-
  2 +require 'test_helper'
  3 +
  4 +class PastryTest < ActiveSupport::TestCase
  5 + # Replace this with your real tests.
  6 + test "the truth" do
  7 + assert true
  8 + end
  9 +end
39 vendor/plugins/provider/spec/provider_spec.rb
... ... @@ -0,0 +1,39 @@
  1 +# -*- encoding : utf-8 -*-
  2 +require File.dirname(__FILE__) + '/spec_helper'
  3 +
  4 +describe "Provider" do
  5 +
  6 + before(:each) do
  7 + @build_param = {"name" => 'zhen', "email" => "zhenWusw@gmail.com"}
  8 + @pastry = Pastry.create(@build_param)
  9 + @fields = ["name", "email"]
  10 + end
  11 +
  12 + describe "given a regual Pastry mdoel" do
  13 +
  14 + it "should invoke provide_action with params @required_fields and false" do
  15 + @pastry.expects(:provide_action).with(@fields, false)
  16 + @pastry.provide(@fields)
  17 + end
  18 +
  19 + it "should invoke provide_action with params @required_fields and true" do
  20 + @pastry.expects(:provide_action).with(@fields, true)
  21 + @pastry.provide!(@fields)
  22 + end
  23 + end
  24 +
  25 + describe "test provide_action" do
  26 +
  27 + it "should assign unkonwn attribute to nil" do
  28 + extra_fields = @fields.push("extra")
  29 + @pastry.provide_action(@fields, false).should == @build_param.update("extra" => nil)
  30 + end
  31 +
  32 + it "should raise RuntimeError when assign unkonwn attribute" do
  33 + expect {
  34 + @pastry.provide_action(@fields.push("extra"), true)
  35 + }.to raise_error(RuntimeError)
  36 + end
  37 + end
  38 +
  39 +end
2  vendor/plugins/provider/spec/rcov.opts
... ... @@ -0,0 +1,2 @@
  1 +--exclude "spec/*,gems/*"
  2 +--rails
24 vendor/plugins/provider/spec/spec_helper.rb
... ... @@ -0,0 +1,24 @@
  1 +# -*- encoding : utf-8 -*-
  2 +$: << File.join(File.dirname(__FILE__), "/../lib" )
  3 +
  4 +# Set the default environment to sqlite3's in_memory database
  5 +ENV['RAILS_ENV'] ||= 'in_memory'
  6 +ENV['RAILS_ROOT'] ||= 'app_root'
  7 +
  8 +# Load the Rails environment and testing framework
  9 +require "#{File.dirname(__FILE__)}/app_root/config/environment"
  10 +require "#{File.dirname(__FILE__)}/../init"
  11 +require 'rspec/rails'
  12 +
  13 +# Undo changes to RAILS_ENV
  14 +silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
  15 +
  16 +# Run the migrations
  17 +ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
  18 +
  19 +RSpec.configure do |config|
  20 +
  21 + config.mock_with :mocha
  22 + config.use_transactional_fixtures = true
  23 + config.use_instantiated_fixtures = false
  24 +end
2  vendor/plugins/provider/uninstall.rb
... ... @@ -0,0 +1,2 @@
  1 +# -*- encoding : utf-8 -*-
  2 +# Uninstall hook code here

0 comments on commit d3dec91

Please sign in to comment.
Something went wrong with that request. Please try again.