summaryrefslogtreecommitdiff
path: root/DEVELOP.md
blob: 6aeccfffbb88b8e3d2e8d90014fd6d5db6422813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Development #

## Hacking ##

Some tips on modifying the views:

* Many of the forms use [simple_form gem](https://github.com/plataformatec/simple_form)

## Engines ##

Leap Web consists of different Engines. They live in their own subdirectory and are included through bundler via their path. This way changes to the engines immediately affect the server as if they were in the main `app` directory.

Currently Leap Web consists of 5 Engines:

* [core](https://github.com/leapcode/leap_web/blob/master/core) - ships some dependencies that are used accross all engines. This might be removed at some point.
* [users](https://github.com/leapcode/leap_web/blob/master/users) - user registration and authorization
* [certs](https://github.com/leapcode/leap_web/blob/master/certs) - Cert distribution for the EIP client
* [help](https://github.com/leapcode/leap_web/blob/master/help) - Help ticket management
* [billing](https://github.com/leapcode/leap_web/blob/master/billing) - Billing System

## Creating a new engine ##

### Rails plugin new ###

Create the basic tree structure for an engine using
```
rails plugin new ENGINE_NAME -O --full
```

`-O` will skip active record and not add a dev dependency on sqlite.
`-full` will create a directory structure with config/routes and app and a basic engine file.

See http://guides.rubyonrails.org/engines.html for more general info about engines.

### Require Leap Web Core and dependencies ###

Leap Web Core provides a common set of dependencies for the engines with CouchRest Model etc.
It also comes with an optional set of UI gems like haml, sass, coffeescript, uglifier, bootstrap-sass, jquery and simple_form.

In order to use the core dependencies you need to add leap_web_core to your .gemspec:
```ruby
# make sure LeapWeb::VERSION is available
require File.expand_path('../../lib/leap_web/version.rb', __FILE__)
# ...
  Gem::Specification.new do |s|
    # ...
    s.add_dependency "rails"
    s.add_dependency "leap_web_core", LeapWeb::Version
  end
```

You also need to require it before you define your engine in lib/my_engine/engine.rb:
```ruby
require "leap_web_core"
# uncomment if you want the ui gems:
# require "leap_web_core/ui_dependencies"

module MyEngine
  class Engine < ::Rails::Engine
    # ...
  end
end
```

Some development and UI dependencies can not be loaded via leap_web_core. To make them available add the following lines to your engines Gemfile

```ruby
  eval(File.read(File.dirname(__FILE__) + '/../common_dependencies.rb'))
  # uncomment if you want the ui gems:
  # eval(File.read(File.dirname(__FILE__) + '/../ui_dependencies.rb'))
```

## Creating Models ##

You can use the normal rails generators to create models. Since you required the leap_web_core gem you will be using CouchRest::Model. So your models inherit from CouchRest::Model::Base.
http://www.couchrest.info/model/definition.html has some good first steps for setting up the model.
CouchRest Model behaved strangely when using a model without a design block. So make sure to define an initial view: http://www.couchrest.info/model/view_objects.html .

From that point on you should be able to use the standart persistance and querying methods such as create, find, destroy and so on.

## Writing Tests ##

### Locale

The ApplicationController defines a before filter #set_locale that will set
the default_url_options to include the appropriate default {:locale => x} param.

However, paths generated in tests don't use default_url_options. This can
create failures for certain nested routes unless you explicitly provide
:locale => nil to the path helper. This is not needed for actual path code in
the controllers or views, only when generating paths in tests.

For example:

    test "robot" do
      login_as @user
      visit robot_path(@robot, :locale => nil)
    end