@@ -5,6 +5,12 @@ describe("AssetFingerprint", function() {
5
5
6
6
describe ( "initialization" , function ( ) {
7
7
describe ( "needsFingerprint" , function ( ) {
8
+
9
+ beforeEach ( function ( ) {
10
+ spyOn ( fs , "existsSync" ) . and . returnValue ( false ) ;
11
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "" ) ;
12
+ } ) ;
13
+
8
14
it ( "should default needsFingerprint = true when no args" , function ( ) {
9
15
fingerprint = new AssetFingerprint ( '' ) ;
10
16
expect ( fingerprint . needsFingerprint ) . toBeTruthy ( ) ;
@@ -27,6 +33,11 @@ describe("AssetFingerprint", function() {
27
33
} ) ;
28
34
29
35
describe ( "initializer path" , function ( ) {
36
+ beforeEach ( function ( ) {
37
+ spyOn ( fs , "existsSync" ) . and . returnValue ( false ) ;
38
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "" ) ;
39
+ } ) ;
40
+
30
41
it ( "should set when supplied" , function ( ) {
31
42
var dir = 'config/initializers' ;
32
43
fingerprint = new AssetFingerprint ( dir , true ) ;
@@ -40,6 +51,11 @@ describe("AssetFingerprint", function() {
40
51
} ) ;
41
52
42
53
describe ( "fingerprint name" , function ( ) {
54
+ beforeEach ( function ( ) {
55
+ spyOn ( fs , "existsSync" ) . and . returnValue ( false ) ;
56
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "" ) ;
57
+ } ) ;
58
+
43
59
it ( "should use ASSET_FINGERPRINT when no args are passed" , function ( ) {
44
60
var dir = 'config/initializers' ;
45
61
fingerprint = new AssetFingerprint ( dir ) ;
@@ -48,15 +64,68 @@ describe("AssetFingerprint", function() {
48
64
49
65
it ( "should use value when provided" , function ( ) {
50
66
var dir = 'config/initializers' ;
51
- fingerprint = new AssetFingerprint ( dir , true , "FINGERPRINT_VALUE" ) ;
52
- expect ( fingerprint . fingerprintName ) . toEqual ( "FINGERPRINT_VALUE" ) ;
67
+ fingerprint = new AssetFingerprint ( dir , true , "TEST_FINGERPRINT" ) ;
68
+ expect ( fingerprint . fingerprintName ) . toEqual ( "TEST_FINGERPRINT" ) ;
69
+ } ) ;
70
+ } ) ;
71
+
72
+ describe ( "fingerprint name" , function ( ) {
73
+ beforeEach ( function ( ) {
74
+ spyOn ( fs , "existsSync" ) . and . returnValue ( true ) ;
75
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "TEST_FINGERPRINT" ) ;
76
+ } ) ;
77
+
78
+ it ( "should validate for duplicate name." , function ( ) {
79
+ var dir = 'config/initializers' ;
80
+ fingerprint = function ( ) { new AssetFingerprint ( dir , true , "TEST_FINGERPRINT" ) ; }
81
+ expect ( fingerprint ) . toThrowError ( 'The provided fingerprint name has already been used.' ) ;
82
+ } ) ;
83
+
84
+ it ( "should validate the file name characters." , function ( ) {
85
+ var dir = 'config/initializers' ;
86
+ fingerprint = function ( ) { new AssetFingerprint ( dir , true , "asset_FINGERPRINT" ) ; }
87
+ expect ( fingerprint ) . toThrowError ( 'Please supply a fingerprint name that is all caps separating words by underscores (i.e. CUSTOM_ASSET_FINGERPRINT).' ) ;
88
+ } ) ;
89
+
90
+ it ( "should validate the file name format." , function ( ) {
91
+ var dir = 'config/initializers' ;
92
+ fingerprint = function ( ) { new AssetFingerprint ( dir , true , "BAD_VALUE" ) ; }
93
+ expect ( fingerprint ) . toThrowError ( 'Please supply a fingerprint name that is all caps separating words by underscores (i.e. CUSTOM_ASSET_FINGERPRINT).' ) ;
94
+ } ) ;
95
+ } ) ;
96
+
97
+ describe ( "fingerprint name" , function ( ) {
98
+ beforeEach ( function ( ) {
99
+ spyOn ( fs , "existsSync" ) . and . returnValue ( true ) ;
100
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "ASSET_FINGERPRINT" ) ;
101
+ } ) ;
102
+
103
+ it ( "should not validate for duplicate name with default arguments." , function ( ) {
104
+ var dir = 'config/initializers' ;
105
+ fingerprint = new AssetFingerprint ( dir ) ;
106
+ expect ( fingerprint . fingerprintName ) . toEqual ( "ASSET_FINGERPRINT" ) ;
107
+ } ) ;
108
+ } ) ;
109
+
110
+ describe ( "fingerprint name" , function ( ) {
111
+ beforeEach ( function ( ) {
112
+ spyOn ( fs , "existsSync" ) . and . returnValue ( false ) ;
113
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "" ) ;
114
+ } ) ;
115
+
116
+ it ( "should not validate when file does not exist." , function ( ) {
117
+ var dir = 'config/initializers' ;
118
+ fingerprint = new AssetFingerprint ( dir , true , "TEST_FINGERPRINT" ) ;
119
+ expect ( fingerprint . fingerprintName ) . toEqual ( "TEST_FINGERPRINT" ) ;
53
120
} ) ;
54
121
} ) ;
55
122
56
123
describe ( "apply" , function ( ) {
57
124
beforeEach ( function ( ) {
58
125
spyOn ( fs , "writeFileSync" ) ;
59
126
spyOn ( fs , "appendFileSync" ) ;
127
+ spyOn ( fs , "existsSync" ) . and . returnValue ( false ) ;
128
+ spyOn ( fs , "readFileSync" ) . and . returnValue ( "" ) ;
60
129
spyOn ( console , "log" ) ;
61
130
} ) ;
62
131
@@ -76,16 +145,16 @@ describe("AssetFingerprint", function() {
76
145
77
146
it ( "should call appendFileSync on provided fingerprint name argument" , function ( ) {
78
147
var dir = 'config/initializers' ;
79
- fingerprint = new AssetFingerprint ( dir , true , "FINGERPRINT_VALUE " ) ;
148
+ fingerprint = new AssetFingerprint ( dir , true , "TEST_FINGERPRINT " ) ;
80
149
fingerprint . apply ( {
81
150
plugin : function ( status , callback ) { callback ( { hash : "Z1Y2X3W4" } ) }
82
151
} ) ;
83
152
84
153
expect ( fs . appendFileSync ) . toHaveBeenCalledWith (
85
- 'config/initializers/asset_fingerprint.rb' , "\r\nFINGERPRINT_VALUE = 'Z1Y2X3W4'" ) ;
154
+ 'config/initializers/asset_fingerprint.rb' , "\r\nTEST_FINGERPRINT = 'Z1Y2X3W4'" ) ;
86
155
87
156
expect ( console . log ) . toHaveBeenCalledWith (
88
- "asset-fingerprint-webpack-rails: updated file config/initializers/asset_fingerprint.rb with FINGERPRINT_VALUE = Z1Y2X3W4" ) ;
157
+ "asset-fingerprint-webpack-rails: updated file config/initializers/asset_fingerprint.rb with TEST_FINGERPRINT = Z1Y2X3W4" ) ;
89
158
} ) ;
90
159
} ) ;
91
160
} ) ;
0 commit comments