vraptor-scaffold 0.0.1.rc → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -1
- data/.gitignore +1 -0
- data/Gemfile +3 -3
- data/History.txt +10 -0
- data/README.textile +32 -0
- data/Rakefile +6 -7
- data/VERSION.yml +1 -1
- data/bin/vraptor +1 -1
- data/lib/configuration.rb +31 -0
- data/lib/generators/app_generator/app_generator.rb +75 -126
- data/lib/generators/app_generator/freemarker_template_engine.rb +50 -0
- data/lib/generators/app_generator/jsp_template_engine.rb +21 -0
- data/lib/generators/app_generator/templates/build.properties.erb +16 -0
- data/lib/generators/app_generator/templates/build.xml +109 -0
- data/lib/generators/app_generator/templates/decorators.erb +7 -0
- data/lib/generators/app_generator/templates/eclipse/classpath +23 -0
- data/lib/generators/app_generator/templates/eclipse/project.erb +36 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.jdt.core.prefs +8 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.common.component.tt +10 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +10 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
- data/lib/generators/app_generator/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
- data/lib/generators/app_generator/templates/freemarker/freemarker-ivy.xml +2 -0
- data/lib/generators/app_generator/templates/freemarker/freemarker-pom.xml +6 -0
- data/lib/generators/app_generator/templates/freemarker/freemarker-web.xml +23 -0
- data/lib/generators/app_generator/templates/freemarker/infrastructure/FreemarkerPathResolver.java.tt +21 -0
- data/lib/generators/app_generator/templates/{macros → freemarker/macros}/html.ftl +0 -0
- data/lib/generators/app_generator/templates/freemarker/main.ftl +14 -0
- data/lib/generators/app_generator/templates/ivy-2.2.0-rc1.jar +0 -0
- data/lib/generators/app_generator/templates/ivy.erb +35 -0
- data/lib/generators/app_generator/templates/jsp/main.jsp +16 -0
- data/lib/generators/app_generator/templates/pom.erb +24 -3
- data/lib/generators/app_generator/templates/{messages.properties → resources-test/.empty_directory} +0 -0
- data/lib/generators/app_generator/templates/{persistence.xml → resources/META-INF/persistence.xml} +0 -0
- data/lib/generators/app_generator/templates/{log4j.properties → resources/log4j.properties} +0 -0
- data/lib/generators/app_generator/templates/resources/messages.properties +0 -0
- data/lib/generators/app_generator/templates/src-test/controllers/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src-test/models/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src-test/repositories/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src/controllers/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/src/models/Entity.java.tt +45 -0
- data/lib/generators/app_generator/templates/src/repositories/Repository.java.tt +43 -0
- data/lib/generators/app_generator/templates/vraptor-scaffold.erb +2 -0
- data/lib/generators/app_generator/templates/webapp/WEB-INF/web.xml +38 -0
- data/lib/generators/app_generator/templates/webapp/images/.empty_directory +0 -0
- data/lib/generators/app_generator/templates/{index.jsp → webapp/index.jsp} +0 -0
- data/lib/generators/app_generator/templates/{javascripts → webapp/javascripts}/jquery-1.4.2.min.js +0 -0
- data/lib/generators/app_generator/templates/{stylesheets → webapp/stylesheets}/scaffold.css +0 -0
- data/lib/generators/scaffold_generator/attribute.rb +14 -6
- data/lib/generators/scaffold_generator/base_scaffold.rb +14 -10
- data/lib/generators/scaffold_generator/controller_generator/controller_generator.rb +6 -6
- data/lib/generators/scaffold_generator/controller_generator/templates/controller.erb +7 -7
- data/lib/generators/scaffold_generator/controller_generator/templates/controller_test.erb +1 -1
- data/lib/generators/scaffold_generator/freemarker_generator/freemarker_generator.rb +5 -5
- data/lib/generators/scaffold_generator/freemarker_generator/templates/index.erb +2 -3
- data/lib/generators/scaffold_generator/jsp_generator/jsp_generator.rb +22 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/edit.erb +3 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/form.erb +27 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/index.erb +36 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/new.erb +3 -0
- data/lib/generators/scaffold_generator/jsp_generator/templates/show.erb +14 -0
- data/lib/generators/scaffold_generator/model_generator/model_generator.rb +5 -5
- data/lib/generators/scaffold_generator/model_generator/templates/model.erb +1 -1
- data/lib/generators/scaffold_generator/model_generator/templates/model_test.erb +1 -1
- data/lib/generators/scaffold_generator/repository_generator/repository_generator.rb +6 -5
- data/lib/generators/scaffold_generator/repository_generator/templates/repository.erb +17 -9
- data/lib/generators/scaffold_generator/repository_generator/templates/repository_impl.erb +16 -0
- data/lib/generators/scaffold_generator/repository_generator/templates/repository_test.erb +2 -2
- data/lib/generators/scaffold_generator/scaffold_generator.rb +31 -38
- data/lib/load_paths.rb +6 -2
- data/lib/vraptor-scaffold.rb +29 -5
- data/spec/lib/configuration_spec.rb +60 -0
- data/spec/lib/generators/app_generator/app_generator_spec.rb +237 -116
- data/spec/lib/generators/app_generator/freemarker_template_engine_spec.rb +92 -0
- data/spec/lib/generators/app_generator/jsp_template_engine_spec.rb +44 -0
- data/{lib → spec/lib}/generators/app_generator/templates/Entity.java +5 -2
- data/{lib → spec/lib}/generators/app_generator/templates/FreemarkerPathResolver.java +1 -1
- data/{lib → spec/lib}/generators/app_generator/templates/Repository.java +6 -6
- data/spec/lib/generators/app_generator/templates/build.properties +16 -0
- data/spec/lib/generators/app_generator/templates/decorators-jsp.xml +7 -0
- data/{lib → spec/lib}/generators/app_generator/templates/decorators.xml +2 -2
- data/spec/lib/generators/app_generator/templates/ivy.xml +35 -0
- data/spec/lib/generators/app_generator/templates/pom.xml +24 -3
- data/spec/lib/generators/scaffold_generator/attribute_spec.rb +47 -27
- data/spec/lib/generators/scaffold_generator/base_scaffold_spec.rb +31 -27
- data/spec/lib/generators/scaffold_generator/controller_generator/controller_generator_spec.rb +11 -9
- data/spec/lib/generators/scaffold_generator/controller_generator/templates/ProductController.java +2 -2
- data/spec/lib/generators/scaffold_generator/freemarker_generator/freemarker_generator_spec.rb +16 -14
- data/spec/lib/generators/scaffold_generator/jsp_generator/jsp_generator_spec.rb +34 -0
- data/spec/lib/generators/scaffold_generator/model_generator/model_generator_spec.rb +11 -9
- data/spec/lib/generators/scaffold_generator/repository_generator/repository_generator_spec.rb +17 -9
- data/spec/lib/generators/scaffold_generator/repository_generator/templates/ProductRepository.java +15 -7
- data/spec/lib/generators/scaffold_generator/repository_generator/templates/ProductRepositoryImpl.java +16 -0
- data/spec/lib/generators/scaffold_generator/scaffold_generator_spec.rb +55 -57
- data/spec/lib/vraptor-scaffold_spec.rb +77 -24
- data/spec/resources/vraptor-scaffold.properties +2 -0
- data/spec/spec_helper.rb +13 -1
- data/vraptor-scaffold.gemspec +82 -34
- metadata +86 -42
- data/README.rdoc +0 -104
- data/TODO.txt +0 -17
- data/lib/generators/app_generator/templates/main.ftl +0 -14
- data/lib/generators/app_generator/templates/web.xml +0 -61
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
|
+
|
3
|
+
describe FreemarkerTemplateEngine do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@project_path = "src/vraptor-scaffold"
|
7
|
+
@webapp = "#{@project_path}/#{Configuration::WEB_APP}"
|
8
|
+
@web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
|
9
|
+
@decorators = "#{@web_inf}/decorators"
|
10
|
+
@app = "#{@project_path}/#{Configuration::MAIN_SRC}/br/com/caelum"
|
11
|
+
end
|
12
|
+
|
13
|
+
context "configuring" do
|
14
|
+
before(:all) do
|
15
|
+
AppGenerator.new(@project_path, ["--template-engine=ftl", "-p=br.com.caelum"]).invoke_all
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) do
|
19
|
+
FileUtils.remove_dir(@project_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should create decorators.xml" do
|
23
|
+
source = File.join File.dirname(__FILE__), "templates", "decorators.xml"
|
24
|
+
destination = "#{@web_inf}/decorators.xml"
|
25
|
+
exists_and_identical?(source, destination)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should append freemarker servlet in web.xml" do
|
29
|
+
source = File.join FreemarkerTemplateEngine.source_root, "freemarker-web.xml"
|
30
|
+
web_xml = "#{@web_inf}/web.xml"
|
31
|
+
File.read(web_xml).should include(File.read(source))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create views folder" do
|
35
|
+
File.exist?("#{@web_inf}/views").should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create infrastructure folder" do
|
39
|
+
File.exist?("#{@app}/infrastructure").should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create path resolver" do
|
43
|
+
source = File.join File.dirname(__FILE__), "templates", "FreemarkerPathResolver.java"
|
44
|
+
destination = "#{@app}/infrastructure/FreemarkerPathResolver.java"
|
45
|
+
exists_and_identical?(source, destination)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should create decorator file" do
|
49
|
+
source = "#{FreemarkerTemplateEngine.source_root}/main.ftl"
|
50
|
+
destination = "#{@decorators}/main.ftl"
|
51
|
+
exists_and_identical?(source, destination)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create html macro file" do
|
55
|
+
source = "#{FreemarkerTemplateEngine.source_root}/macros/html.ftl"
|
56
|
+
destination = "#{@webapp}/macros/html.ftl"
|
57
|
+
exists_and_identical?(source, destination)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with maven" do
|
62
|
+
before(:all) do
|
63
|
+
AppGenerator.new(@project_path, ["--template-engine=ftl", "-b=mvn"]).invoke_all
|
64
|
+
end
|
65
|
+
|
66
|
+
after(:all) do
|
67
|
+
FileUtils.remove_dir(@project_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should append freemarker dependency in pom.xml" do
|
71
|
+
source = File.join FreemarkerTemplateEngine.source_root, "freemarker-pom.xml"
|
72
|
+
pom = "#{@project_path}/pom.xml"
|
73
|
+
File.read(pom).should match(File.read(source))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with ant" do
|
78
|
+
before(:all) do
|
79
|
+
AppGenerator.new(@project_path, ["--template-engine=ftl", "-b=ant"]).invoke_all
|
80
|
+
end
|
81
|
+
|
82
|
+
after(:all) do
|
83
|
+
FileUtils.remove_dir(@project_path)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should append freemarker dependency in ivy.xml" do
|
87
|
+
source = File.join FreemarkerTemplateEngine.source_root, "freemarker-ivy.xml"
|
88
|
+
ivy = "#{@project_path}/ivy.xml"
|
89
|
+
File.read(ivy).should match(File.read(source))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
|
+
|
3
|
+
describe JspTemplateEngine do
|
4
|
+
|
5
|
+
context "building a jsp application" do
|
6
|
+
before(:all) do
|
7
|
+
@project_path = "src/vraptor-scaffold"
|
8
|
+
@web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
|
9
|
+
@decorators = "#{@web_inf}/decorators"
|
10
|
+
@app = "#{@project_path}/#{Configuration::MAIN_SRC}/app"
|
11
|
+
AppGenerator.new(@project_path).invoke_all
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
FileUtils.remove_dir("src")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create decorators.xml" do
|
19
|
+
source = File.join File.dirname(__FILE__), "templates", "decorators-jsp.xml"
|
20
|
+
destination = "#{@web_inf}/decorators.xml"
|
21
|
+
exists_and_identical?(source, destination)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should create views folder" do
|
25
|
+
File.exist?("#{@web_inf}/jsp").should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create decorator file" do
|
29
|
+
source = "#{JspTemplateEngine.source_root}/main.jsp"
|
30
|
+
destination = "#{@decorators}/main.jsp"
|
31
|
+
exists_and_identical?(source, destination)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not create infrastructure folder" do
|
35
|
+
File.exist?("#{@app}/infrastructure").should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not create path resolver" do
|
39
|
+
to = "#{@app}/infrastructure/FreemarkerPathResolver.java"
|
40
|
+
File.exist?(to).should be_false
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -8,7 +8,7 @@ import javax.persistence.MappedSuperclass;
|
|
8
8
|
public class Entity {
|
9
9
|
|
10
10
|
@Id @GeneratedValue
|
11
|
-
|
11
|
+
private Long id;
|
12
12
|
|
13
13
|
public void setId(Long id) {
|
14
14
|
this.id = id;
|
@@ -23,6 +23,9 @@ public class Entity {
|
|
23
23
|
if (obj == null) {
|
24
24
|
return false;
|
25
25
|
}
|
26
|
+
if (this == obj) {
|
27
|
+
return true;
|
28
|
+
}
|
26
29
|
if (getClass() != obj.getClass()) {
|
27
30
|
return false;
|
28
31
|
}
|
@@ -39,4 +42,4 @@ public class Entity {
|
|
39
42
|
hash = 17 * hash + (this.getId() != null ? this.getId().hashCode() : 0);
|
40
43
|
return hash;
|
41
44
|
}
|
42
|
-
}
|
45
|
+
}
|
@@ -6,7 +6,7 @@ import java.util.List;
|
|
6
6
|
|
7
7
|
import javax.persistence.EntityManager;
|
8
8
|
|
9
|
-
public abstract class Repository<T> {
|
9
|
+
public abstract class Repository<T, I extends Serializable> {
|
10
10
|
|
11
11
|
protected final EntityManager entityManager;
|
12
12
|
|
@@ -14,20 +14,20 @@ public abstract class Repository<T> {
|
|
14
14
|
this.entityManager = entityManager;
|
15
15
|
}
|
16
16
|
|
17
|
-
public void create(
|
17
|
+
public void create(T entity) {
|
18
18
|
entityManager.persist(entity);
|
19
19
|
}
|
20
20
|
|
21
|
-
public void update(
|
21
|
+
public void update(T entity) {
|
22
22
|
entityManager.merge(entity);
|
23
23
|
}
|
24
24
|
|
25
|
-
public void destroy(
|
25
|
+
public void destroy(T entity) {
|
26
26
|
entityManager.remove(entity);
|
27
27
|
}
|
28
28
|
|
29
|
-
public T find(
|
30
|
-
return
|
29
|
+
public T find(I id) {
|
30
|
+
return entityManager.find(getParameterizedClass(), id);
|
31
31
|
}
|
32
32
|
|
33
33
|
@SuppressWarnings("unchecked")
|
@@ -0,0 +1,16 @@
|
|
1
|
+
project.name=vraptor-scaffold
|
2
|
+
|
3
|
+
output.dir=target
|
4
|
+
test.build.dir=target/test-classes
|
5
|
+
|
6
|
+
webapp.dir=src/main/webapp
|
7
|
+
lib.dir=src/main/webapp/WEB-INF/lib
|
8
|
+
build.dir=src/main/webapp/WEB-INF/classes
|
9
|
+
|
10
|
+
src.dir=src/main/java
|
11
|
+
resources.dir=src/main/resources
|
12
|
+
|
13
|
+
test.src.dir=src/test/java
|
14
|
+
test.resources.dir=src/test/resources
|
15
|
+
|
16
|
+
ivy.jar.file=ivy-2.2.0-rc1.jar
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<ivy-module version="2.0">
|
2
|
+
<info organisation="vraptor-scaffold" module="vraptor-scaffold" />
|
3
|
+
|
4
|
+
<configurations>
|
5
|
+
<conf name="default" description="dependencies used for compile" />
|
6
|
+
<conf name="test" description="dependencies used for tests" visibility="public" />
|
7
|
+
<conf name="jetty" description="dependencies used for jetty" visibility="public" />
|
8
|
+
<conf name="provided" description="dependencies used for compile but is not packaged" visibility="public" />
|
9
|
+
</configurations>
|
10
|
+
|
11
|
+
<dependencies>
|
12
|
+
<dependency org="hsqldb" name="hsqldb" rev="1.8.0.10" conf="default" />
|
13
|
+
<dependency org="br.com.caelum" name="vraptor" rev="3.1.3" conf="default" />
|
14
|
+
<dependency org="opensymphony" name="sitemesh" rev="2.4.2" conf="default" />
|
15
|
+
<dependency org="javax.servlet" name="jstl" rev="1.2" conf="default" />
|
16
|
+
<dependency org="javax.persistence" name="persistence-api" rev="1.0" conf="default" />
|
17
|
+
<dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.4.0.GA" conf="default" />
|
18
|
+
<dependency org="org.hibernate" name="hibernate-core" rev="3.3.2.GA" conf="default" />
|
19
|
+
<dependency org="org.hibernate" name="hibernate-validator" rev="3.1.0.GA" conf="default" />
|
20
|
+
<dependency org="joda-time" name="joda-time" rev="1.6" conf="default" />
|
21
|
+
|
22
|
+
<!-- Provided dependencies -->
|
23
|
+
<dependency org="javax.servlet" name="servlet-api" rev="2.5" conf="provided->default" />
|
24
|
+
|
25
|
+
<!-- Test dependencies -->
|
26
|
+
<dependency org="junit" name="junit" rev="4.8.1" conf="test->default" />
|
27
|
+
<dependency org="org.hamcrest" name="hamcrest-all" rev="1.1" conf="test->default" />
|
28
|
+
<dependency org="org.mockito" name="mockito-all" rev="1.8.5" conf="test->default" />
|
29
|
+
|
30
|
+
<!-- Ant dependencies -->
|
31
|
+
<dependency org="org.mortbay.jetty" name="jsp-api-2.1" rev="6.1.14" conf="jetty->default"/>
|
32
|
+
<dependency org="org.mortbay.jetty" name="jsp-2.1" rev="6.1.14" conf="jetty->default"/>
|
33
|
+
<dependency org="org.mortbay.jetty" name="jetty-ant" rev="6.1.14" conf="jetty->default" />
|
34
|
+
</dependencies>
|
35
|
+
</ivy-module>
|
@@ -12,6 +12,7 @@
|
|
12
12
|
</properties>
|
13
13
|
|
14
14
|
<build>
|
15
|
+
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory>
|
15
16
|
<plugins>
|
16
17
|
<plugin>
|
17
18
|
<artifactId>maven-compiler-plugin</artifactId>
|
@@ -24,6 +25,7 @@
|
|
24
25
|
</plugin>
|
25
26
|
<plugin>
|
26
27
|
<artifactId>maven-eclipse-plugin</artifactId>
|
28
|
+
<version>2.8</version>
|
27
29
|
<configuration>
|
28
30
|
<downloadSources>true</downloadSources>
|
29
31
|
<downloadJavadocs>true</downloadJavadocs>
|
@@ -83,9 +85,9 @@
|
|
83
85
|
<version>2.4.2</version>
|
84
86
|
</dependency>
|
85
87
|
<dependency>
|
86
|
-
<groupId>
|
87
|
-
<artifactId>
|
88
|
-
<version>2
|
88
|
+
<groupId>javax.servlet</groupId>
|
89
|
+
<artifactId>jstl</artifactId>
|
90
|
+
<version>1.2</version>
|
89
91
|
</dependency>
|
90
92
|
<dependency>
|
91
93
|
<groupId>javax.persistence</groupId>
|
@@ -96,6 +98,21 @@
|
|
96
98
|
<groupId>org.hibernate</groupId>
|
97
99
|
<artifactId>hibernate-entitymanager</artifactId>
|
98
100
|
<version>3.4.0.GA</version>
|
101
|
+
<exclusions>
|
102
|
+
<exclusion>
|
103
|
+
<artifactId>slf4j-api</artifactId>
|
104
|
+
<groupId>org.slf4j</groupId>
|
105
|
+
</exclusion>
|
106
|
+
<exclusion>
|
107
|
+
<artifactId>org.hibernate</artifactId>
|
108
|
+
<groupId>hibernate-core</groupId>
|
109
|
+
</exclusion>
|
110
|
+
</exclusions>
|
111
|
+
</dependency>
|
112
|
+
<dependency>
|
113
|
+
<groupId>org.hibernate</groupId>
|
114
|
+
<artifactId>hibernate-core</artifactId>
|
115
|
+
<version>3.3.2.GA</version>
|
99
116
|
<exclusions>
|
100
117
|
<exclusion>
|
101
118
|
<artifactId>slf4j-api</artifactId>
|
@@ -112,6 +129,10 @@
|
|
112
129
|
<artifactId>slf4j-api</artifactId>
|
113
130
|
<groupId>org.slf4j</groupId>
|
114
131
|
</exclusion>
|
132
|
+
<exclusion>
|
133
|
+
<artifactId>org.hibernate</artifactId>
|
134
|
+
<groupId>hibernate-core</groupId>
|
135
|
+
</exclusion>
|
115
136
|
</exclusions>
|
116
137
|
</dependency>
|
117
138
|
<dependency>
|
@@ -1,113 +1,133 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
2
2
|
|
3
3
|
describe Attribute do
|
4
|
-
|
4
|
+
|
5
5
|
context "supported types" do
|
6
6
|
it "should support boolean" do
|
7
7
|
Attribute.valid_types.include?("boolean").should be_true
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should support double" do
|
11
11
|
Attribute.valid_types.include?("double").should be_true
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should support string" do
|
15
15
|
Attribute.valid_types.include?("string").should be_true
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should support float" do
|
19
19
|
Attribute.valid_types.include?("float").should be_true
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "should support short" do
|
23
23
|
Attribute.valid_types.include?("short").should be_true
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should support integer" do
|
27
27
|
Attribute.valid_types.include?("integer").should be_true
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should support long" do
|
31
31
|
Attribute.valid_types.include?("long").should be_true
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should support text" do
|
35
35
|
Attribute.valid_types.include?("text").should be_true
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
context "html_input" do
|
40
40
|
it "should know html input to boolean" do
|
41
41
|
Attribute.new("flag", "boolean").html_input.should eql("checkbox")
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should know html input to string" do
|
45
45
|
Attribute.new("name", "string").html_input.should eql("text")
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "should know html input to double" do
|
49
49
|
Attribute.new("name", "double").html_input.should eql("text")
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "should know html input to float" do
|
53
53
|
Attribute.new("name", "float").html_input.should eql("text")
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should know html input to short" do
|
57
57
|
Attribute.new("name", "short").html_input.should eql("text")
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "should know html input to integer" do
|
61
61
|
Attribute.new("name", "integer").html_input.should eql("text")
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it "should know html input to long" do
|
65
65
|
Attribute.new("name", "long").html_input.should eql("text")
|
66
66
|
end
|
67
|
-
|
68
|
-
|
67
|
+
|
68
|
+
it "should know html input to text" do
|
69
69
|
Attribute.new("name", "text").html_input.should eql("textarea")
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
context "java type" do
|
74
74
|
it "should know corret java type to boolean" do
|
75
75
|
Attribute.new("flag", "boolean").java_type.should eql("boolean")
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
it "should know corret java type to text" do
|
79
79
|
Attribute.new("description", "text").java_type.should eql("String")
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should know corret java type to string" do
|
83
83
|
Attribute.new("name", "string").java_type.should eql("String")
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "should know corret java type to double" do
|
87
87
|
Attribute.new("name", "double").java_type.should eql("Double")
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should know corret java type to float" do
|
91
91
|
Attribute.new("name", "float").java_type.should eql("Float")
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it "should know corret java type to short" do
|
95
95
|
Attribute.new("name", "short").java_type.should eql("Short")
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "should know corret java type to integer" do
|
99
99
|
Attribute.new("name", "integer").java_type.should eql("Integer")
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it "should know corret java type to long" do
|
103
103
|
Attribute.new("name", "long").java_type.should eql("Long")
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
|
+
context "validate" do
|
108
|
+
|
109
|
+
it "should be valid when attribute is supported" do
|
110
|
+
Kernel.should_not_receive(:exit)
|
111
|
+
Attribute.valid_types.each do |type|
|
112
|
+
Attribute.new("name", type)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "cannot be valid when attribute is not supported" do
|
117
|
+
Kernel.should_receive(:exit)
|
118
|
+
Attribute.new("name", "char")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should be valid when attribute is upper case" do
|
122
|
+
Kernel.should_not_receive(:exit)
|
123
|
+
Attribute.new("name", "String")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
107
127
|
it "should be boolean when type is boolean" do
|
108
128
|
Attribute.new("flag", "boolean").boolean?.should be_true
|
109
129
|
end
|
110
|
-
|
130
|
+
|
111
131
|
it "cannot be boolean otherwise" do
|
112
132
|
Attribute.new("flag", "short").boolean?.should be_false
|
113
133
|
end
|