Changing model_type_key one last time to 'type'. General doc refinements for 1.1.0.beta5 release

This commit is contained in:
Sam Lown 2011-04-30 13:13:38 +02:00
parent da3e524020
commit e8e1722241
7 changed files with 55 additions and 28 deletions

View file

@ -3,7 +3,15 @@
CouchRest Models adds additional functionality to the standard CouchRest Document class such as
setting properties, callbacks, typecasting, and validations.
For more documentation see [http://www.couchrest.info](http://www.couchrest.info).
## Documentation
Please visit the documentation project at [http://www.couchrest.info](http://www.couchrest.info). You're [contributions](https://github.com/couchrest/couchrest.github.com) to the documentation would be greatly appreciated!
General API: [http://rdoc.info/projects/couchrest/couchrest_model](http://rdoc.info/projects/couchrest/couchrest_model)
See the [update history](https://github.com/couchrest/couchrest_model/blob/master/history.md) for an up to date list of all the changes we've been working on recently.
## Notes
Originally called ExtendedDocument, the new Model structure uses ActiveModel, part of Rails 3,
for validations and callbacks.
@ -13,13 +21,13 @@ it is not possible to load ActiveModel into programs that do not use ActiveSuppo
CouchRest Model is only properly tested on CouchDB version 1.0 or newer.
*WARNING:* As of April 2011 and the release of version 1.1.0, the default model type key is 'model' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:
*WARNING:* As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:
CouchRest::Model::Base.configure do |config|
config.model_type_key = 'couchrest-type'
end
This is because CouchRest Model's are not couchrest specific and may be used in any other system such as a Javascript library, the model type should reflect this.
This is because CouchRest Model's are not couchrest specific and may be used in any other systems such as Javascript, the model type should reflect this. Also, we're all used to `type` being a reserved word in ActiveRecord.
## Install
@ -33,24 +41,32 @@ If you're using bundler, define a line similar to the following in your project'
gem 'couchrest_model'
You might also consider using the latest git repository. We try to make sure the current version in git is stable and at the very least all tests should pass.
### Configuration
gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git'
CouchRest Model is configured to work out the box with no configuration as long as your CouchDB instance is running on the default port (5984) on localhost. The default name of the database is either the name of your application as provided by the `Rails.application.class.to_s` call (with /application removed) or just 'couchrest' if none is available.
### Setup
The library will try to detect a configuration file at `config/couchdb.yml` from the Rails root or `Dir.pwd`. Here you can configuration your database connection in a Rails-like way:
There is currently no standard way for telling CouchRest Model how it should access your database, this is something we're still working on. For the time being, the easiest way is to set a COUCHDB_DATABASE global variable to an instance of CouchRest Database, and call `use_database COUCHDB_DATABASE` in each model.
development:
protocol: 'https'
host: sample.cloudant.com
port: 443
prefix: project
suffix: test
username: test
password: user
TODO: Add an example!
Note that the name of the database is either just the prefix and suffix combined or the prefix plus any text you specifify using `use_database` method in your models with the suffix on the end.
### Development
The example config above for example would use a database called "project_test". Heres an example using the `use_database` call:
CouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:
class Project < CouchRest::Model::Base
use_database 'sample'
end
bundle install
# The database object would be provided as:
Project.database #=> "https://test:user@sample.cloudant.com:443/project_sample_test"
That should set everything up for `rake spec` to be run correctly. Update the couchrest_model.gemspec if your alterations
use different gems.
## Generators
@ -89,21 +105,23 @@ use different gems.
@cat.new? # false
@cat.random_text # Raises error!
## Development
### Preparations
## Testing
CouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:
bundle install
That should set everything up for `rake spec` to be run correctly. Update the couchrest_model.gemspec if your alterations
use different gems.
### Testing
The most complete documentation is the spec/ directory. To validate your CouchRest install, from the project root directory run `bundle install` to ensure all the development dependencies are available and then `rspec spec` or `bundle exec rspec spec`.
We will not accept pull requests to the project without sufficient tests.
## Docs
API: [http://rdoc.info/projects/couchrest/couchrest_model](http://rdoc.info/projects/couchrest/couchrest_model)
Check the wiki for documentation and examples [http://wiki.github.com/couchrest/couchrest_model](http://wiki.github.com/couchrest/couchrest_model)
## Contact
Please post bugs, suggestions and patches to the bug tracker at [http://github.com/couchrest/couchrest_model/issues](http://github.com/couchrest/couchrest_model/issues).
@ -112,3 +130,4 @@ Follow us on Twitter: [http://twitter.com/couchrest](http://twitter.com/couchres
Also, check [http://twitter.com/#search?q=%23couchrest](http://twitter.com/#search?q=%23couchrest)

View file

@ -1,7 +1,11 @@
== 1.1.0.beta5
== 1.1.0.beta5 - 2011-04-30
* Major changes:
* Database auto configuration, with connection options!
* Changed default CouchRest Model type to 'type' to be more consistent with ActiveRecord's reserverd words we're all used to (sorry for the change again!!)
* Minor changes
* Added filter option to designs (Used with CouchDB _changes feeds)
== 1.1.0.beta4

View file

@ -16,7 +16,7 @@ module CouchRest
add_config :connection_config_file
configure do |config|
config.model_type_key = 'model' # was 'couchrest-type'
config.model_type_key = 'type' # was 'couchrest-type'
config.mass_assign_any_attribute = false
config.auto_update_design_doc = true

View file

@ -140,7 +140,7 @@ module CouchRest
module ClassMethods
def property(name, *options, &block)
raise "Invalid property definition, '#{name}' already used for CouchRest Model type field" if name.to_s == model_type_key.to_s
raise "Invalid property definition, '#{name}' already used for CouchRest Model type field" if name.to_s == model_type_key.to_s && CouchRest::Model::Base >= self
opts = { }
type = options.shift
if type.class != Hash

View file

@ -17,11 +17,11 @@ describe "Design Documents" do
end
it "should calculate a consistent checksum for model" do
WithTemplateAndUniqueID.design_doc.checksum!.should eql('ff6fa2eaf774397391942d51428c1fe2')
WithTemplateAndUniqueID.design_doc.checksum!.should eql('caa2b4c27abb82b4e37421de76d96ffc')
end
it "should calculate checksum for complex model" do
Article.design_doc.checksum!.should eql('fb65c06a76b6141529e31e894ad00b1a')
Article.design_doc.checksum!.should eql('70dff8caea143bf40fad09adf0701104')
end
it "should cache the generated checksum value" do

View file

@ -74,7 +74,7 @@ describe "Design View" do
it "should auto generate mapping from name" do
lambda { @klass.create(DesignViewModel, 'by_title') }.should_not raise_error
str = @design_doc['views']['by_title']['map']
str.should include("((doc['model'] == 'DesignViewModel') && (doc['title'] != null))")
str.should include("((doc['#{DesignViewModel.model_type_key}'] == 'DesignViewModel') && (doc['title'] != null))")
str.should include("emit(doc['title'], 1);")
str = @design_doc['views']['by_title']['reduce']
str.should include("return sum(values);")

View file

@ -56,7 +56,11 @@ describe "Model properties" do
end
it "should raise error if property name coincides with model type key" do
lambda { Person.property(Person.model_type_key) }.should raise_error(/already used/)
lambda { Cat.property(Cat.model_type_key) }.should raise_error(/already used/)
end
it "should not raise error if property name coincides with model type key on non-model" do
lambda { CatToy.property(Cat.model_type_key) }.should_not raise_error
end
it "should be auto timestamped" do